@adminide-stack/yantra-mobile 12.0.172 → 12.0.173
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/features/apps/mobileAppCatalog.js +2 -2
- package/lib/features/apps/mobileAppCatalog.js.map +1 -1
- package/lib/features/chat/NotionPageWidgetCard.js +98 -0
- package/lib/features/chat/NotionPageWidgetCard.js.map +1 -0
- package/lib/features/chat/hostTranscriptProtocol.js +5 -1
- package/lib/features/chat/hostTranscriptProtocol.js.map +1 -1
- package/lib/features/chat/notionPageWidget.js +34 -0
- package/lib/features/chat/notionPageWidget.js.map +1 -0
- package/lib/features/games/cubeforge3D.js +11 -6
- package/lib/features/games/cubeforge3D.js.map +1 -1
- package/lib/features/games/vendored/core/cubeforge/items.js +2 -8
- package/lib/features/games/vendored/core/cubeforge/items.js.map +1 -1
- package/lib/features/games/vendored/core/cubeforge/recipes.js +1 -4
- package/lib/features/games/vendored/core/cubeforge/recipes.js.map +1 -1
- package/lib/features/games/vendored/core/cubeforge/skin.js +83 -0
- package/lib/features/games/vendored/core/cubeforge/skin.js.map +1 -0
- package/lib/features/games/vendored/core/cubeforge/worldgen.js +2 -38
- package/lib/features/games/vendored/core/cubeforge/worldgen.js.map +1 -1
- package/lib/features/games/vendored/core/engine/palette.js +2 -9
- package/lib/features/games/vendored/core/engine/palette.js.map +1 -1
- package/lib/features/games/vendored/core/lessons/lessons.js +2 -96
- package/lib/features/games/vendored/core/lessons/lessons.js.map +1 -1
- package/lib/features/games/vendored/ui/GamesRoot.js +87 -144
- package/lib/features/games/vendored/ui/GamesRoot.js.map +1 -1
- package/lib/features/games/vendored/ui/components/primitives.js +2 -50
- package/lib/features/games/vendored/ui/components/primitives.js.map +1 -1
- package/lib/features/games/vendored/ui/screens/Cubeforge3DHomeScreen.js +20 -3
- package/lib/features/games/vendored/ui/screens/Cubeforge3DHomeScreen.js.map +1 -1
- package/lib/features/games/vendored/ui/screens/SkinEditorScreen.js +169 -0
- package/lib/features/games/vendored/ui/screens/SkinEditorScreen.js.map +1 -0
- package/lib/features/games/vendored/ui/theme.js +1 -3
- package/lib/features/games/vendored/ui/theme.js.map +1 -1
- package/lib/features/notion/notionEditorModel.js +3 -1
- package/lib/features/notion/notionEditorModel.js.map +1 -1
- package/lib/screens/GamesNative/index.js +1 -1
- package/lib/screens/Home/components/homeCatalog.js +2 -2
- package/lib/screens/Home/components/homeCatalog.js.map +1 -1
- package/package.json +2 -2
- package/lib/features/games/vendored/core/classroom/permissions.js +0 -76
- package/lib/features/games/vendored/core/classroom/permissions.js.map +0 -1
- package/lib/features/games/vendored/core/classroom/resourceLink.js +0 -101
- package/lib/features/games/vendored/core/classroom/resourceLink.js.map +0 -1
- package/lib/features/games/vendored/core/classroom/rules.js +0 -83
- package/lib/features/games/vendored/core/classroom/rules.js.map +0 -1
- package/lib/features/games/vendored/core/classroom/worldSettings.js +0 -49
- package/lib/features/games/vendored/core/classroom/worldSettings.js.map +0 -1
- package/lib/features/games/vendored/core/cubeforge/cycle.js +0 -15
- package/lib/features/games/vendored/core/cubeforge/cycle.js.map +0 -1
- package/lib/features/games/vendored/core/cubeforge/inventory.js +0 -75
- package/lib/features/games/vendored/core/cubeforge/inventory.js.map +0 -1
- package/lib/features/games/vendored/core/cubeforge/save.js +0 -92
- package/lib/features/games/vendored/core/cubeforge/save.js.map +0 -1
- package/lib/features/games/vendored/core/cubeforge/session.js +0 -154
- package/lib/features/games/vendored/core/cubeforge/session.js.map +0 -1
- package/lib/features/games/vendored/core/engine/iso.js +0 -41
- package/lib/features/games/vendored/core/engine/iso.js.map +0 -1
- package/lib/features/games/vendored/core/engine/world.js +0 -148
- package/lib/features/games/vendored/core/engine/world.js.map +0 -1
- package/lib/features/games/vendored/core/games/catalog.js +0 -34
- package/lib/features/games/vendored/core/games/catalog.js.map +0 -1
- package/lib/features/games/vendored/core/logging/events.js +0 -24
- package/lib/features/games/vendored/core/logging/events.js.map +0 -1
- package/lib/features/games/vendored/core/logging/logger.js +0 -54
- package/lib/features/games/vendored/core/logging/logger.js.map +0 -1
- package/lib/features/games/vendored/core/session/gameSession.js +0 -317
- package/lib/features/games/vendored/core/session/gameSession.js.map +0 -1
- package/lib/features/games/vendored/core/storage/worldRepository.js +0 -192
- package/lib/features/games/vendored/core/storage/worldRepository.js.map +0 -1
- package/lib/features/games/vendored/core/store/reactive.js +0 -78
- package/lib/features/games/vendored/core/store/reactive.js.map +0 -1
- package/lib/features/games/vendored/ui/components/BlockPalette.js +0 -64
- package/lib/features/games/vendored/ui/components/BlockPalette.js.map +0 -1
- package/lib/features/games/vendored/ui/components/IsoCanvas.js +0 -124
- package/lib/features/games/vendored/ui/components/IsoCanvas.js.map +0 -1
- package/lib/features/games/vendored/ui/hooks/useReactiveQuery.js +0 -3
- package/lib/features/games/vendored/ui/hooks/useReactiveQuery.js.map +0 -1
- package/lib/features/games/vendored/ui/screens/ActivityScreen.js +0 -68
- package/lib/features/games/vendored/ui/screens/ActivityScreen.js.map +0 -1
- package/lib/features/games/vendored/ui/screens/BuilderScreen.js +0 -227
- package/lib/features/games/vendored/ui/screens/BuilderScreen.js.map +0 -1
- package/lib/features/games/vendored/ui/screens/ClassroomScreen.js +0 -95
- package/lib/features/games/vendored/ui/screens/ClassroomScreen.js.map +0 -1
- package/lib/features/games/vendored/ui/screens/CubeforgeScreen.js +0 -342
- package/lib/features/games/vendored/ui/screens/CubeforgeScreen.js.map +0 -1
- package/lib/features/games/vendored/ui/screens/HubScreen.js +0 -131
- package/lib/features/games/vendored/ui/screens/HubScreen.js.map +0 -1
- package/lib/features/games/vendored/ui/screens/WorldListScreen.js +0 -134
- package/lib/features/games/vendored/ui/screens/WorldListScreen.js.map +0 -1
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {emptyResourceLink}from'./resourceLink.js';const BOOLEAN_SETTING_KEYS = ["destructiveItems", "playerDamage", "immutableWorld", "mobsRestricted", "perfectWeather", "showBorderEffects", "tntExplodes", "respawnBlocksExplode", "fireSpreads", "pvp", "friendlyFire", "mobSpawning", "weatherCycle"];
|
|
2
|
-
function defaultWorldSettings() {
|
|
3
|
-
return {
|
|
4
|
-
destructiveItems: true,
|
|
5
|
-
playerDamage: true,
|
|
6
|
-
immutableWorld: false,
|
|
7
|
-
mobsRestricted: false,
|
|
8
|
-
perfectWeather: false,
|
|
9
|
-
showBorderEffects: false,
|
|
10
|
-
tntExplodes: true,
|
|
11
|
-
respawnBlocksExplode: true,
|
|
12
|
-
fireSpreads: true,
|
|
13
|
-
pvp: true,
|
|
14
|
-
friendlyFire: false,
|
|
15
|
-
mobSpawning: true,
|
|
16
|
-
weatherCycle: true,
|
|
17
|
-
resourceLink: emptyResourceLink()
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
const SETTING_LABELS = {
|
|
21
|
-
destructiveItems: "Destructive items",
|
|
22
|
-
playerDamage: "Player damage",
|
|
23
|
-
immutableWorld: "Immutable world",
|
|
24
|
-
mobsRestricted: "Mobs restricted",
|
|
25
|
-
perfectWeather: "Perfect weather",
|
|
26
|
-
showBorderEffects: "Show border effects",
|
|
27
|
-
tntExplodes: "Explosives detonate",
|
|
28
|
-
respawnBlocksExplode: "Respawn blocks explode",
|
|
29
|
-
fireSpreads: "Fire spreads",
|
|
30
|
-
pvp: "Player vs player",
|
|
31
|
-
friendlyFire: "Friendly fire",
|
|
32
|
-
mobSpawning: "Creature spawning",
|
|
33
|
-
weatherCycle: "Weather cycle"
|
|
34
|
-
};
|
|
35
|
-
const SETTING_DESCRIPTIONS = {
|
|
36
|
-
destructiveItems: "Allow explosives and harmful items. Off also disables explosions and fire spread.",
|
|
37
|
-
playerDamage: "Players can take damage. Off makes everyone invulnerable and disables combat.",
|
|
38
|
-
immutableWorld: "Players can interact but cannot break or place blocks. Great for demos and assessments.",
|
|
39
|
-
mobsRestricted: "No creatures spawn anywhere in the world.",
|
|
40
|
-
perfectWeather: "Keep the sky clear. Stops the weather from changing.",
|
|
41
|
-
showBorderEffects: "Show a visible effect on the edges of the build area.",
|
|
42
|
-
tntExplodes: "Explosives can detonate and damage the world.",
|
|
43
|
-
respawnBlocksExplode: "Respawn blocks can explode when used in the wrong place.",
|
|
44
|
-
fireSpreads: "Fire can spread from block to block.",
|
|
45
|
-
pvp: "Players can damage one another.",
|
|
46
|
-
friendlyFire: "Players on the same team can damage one another.",
|
|
47
|
-
mobSpawning: "Creatures spawn naturally over time.",
|
|
48
|
-
weatherCycle: "Weather changes on its own over time."
|
|
49
|
-
};export{BOOLEAN_SETTING_KEYS,SETTING_DESCRIPTIONS,SETTING_LABELS,defaultWorldSettings};//# sourceMappingURL=worldSettings.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worldSettings.js","sources":["../../../../../../src/features/games/vendored/core/classroom/worldSettings.ts"],"sourcesContent":["/**\n * World settings for a block-building world, including Classroom-mode rules.\n *\n * This is Yantra Games' own model of the configurable world options a teacher\n * can set. It is informed by a generic feature study of classroom-style world\n * rules (lockable worlds, coupled toggles, a teacher resource link, player\n * permissions) and implemented from scratch - no third-party code or assets.\n *\n * The rule *coupling* and *lock* behaviour lives in ./rules; the single source\n * of truth normalises settings there so a view can never show a toggle as\n * editable while the enforced state disagrees.\n */\n\nimport type { ResourceLink } from './resourceLink';\nimport { emptyResourceLink } from './resourceLink';\n\n/** Every boolean world rule, by key. Used by the rule-coupling engine. */\nexport type BooleanSettingKey =\n // Master classroom rules\n | 'destructiveItems'\n | 'playerDamage'\n | 'immutableWorld'\n | 'mobsRestricted'\n | 'perfectWeather'\n | 'showBorderEffects'\n // Dependent world rules (can be force-locked by a master rule above)\n | 'tntExplodes'\n | 'respawnBlocksExplode'\n | 'fireSpreads'\n | 'pvp'\n | 'friendlyFire'\n | 'mobSpawning'\n | 'weatherCycle';\n\nexport const BOOLEAN_SETTING_KEYS: readonly BooleanSettingKey[] = [\n 'destructiveItems',\n 'playerDamage',\n 'immutableWorld',\n 'mobsRestricted',\n 'perfectWeather',\n 'showBorderEffects',\n 'tntExplodes',\n 'respawnBlocksExplode',\n 'fireSpreads',\n 'pvp',\n 'friendlyFire',\n 'mobSpawning',\n 'weatherCycle',\n];\n\nexport interface WorldSettings {\n // --- Master classroom rules ---\n /** When off: no destructive items, and explosion/fire rules are force-locked off. */\n destructiveItems: boolean;\n /** When off: players are invulnerable, and PvP + friendly fire are locked off. */\n playerDamage: boolean;\n /** When on: players may interact with blocks but cannot break or place them. */\n immutableWorld: boolean;\n /** When on: no creatures spawn, and mob spawning is locked off. */\n mobsRestricted: boolean;\n /** When on: weather is held clear, and the weather cycle is locked off. */\n perfectWeather: boolean;\n /** When on: world-border blocks emit a visible effect. */\n showBorderEffects: boolean;\n\n // --- Dependent world rules ---\n tntExplodes: boolean;\n respawnBlocksExplode: boolean;\n fireSpreads: boolean;\n pvp: boolean;\n friendlyFire: boolean;\n mobSpawning: boolean;\n weatherCycle: boolean;\n\n // --- Teacher resource link ---\n resourceLink: ResourceLink;\n}\n\nexport function defaultWorldSettings(): WorldSettings {\n return {\n destructiveItems: true,\n playerDamage: true,\n immutableWorld: false,\n mobsRestricted: false,\n perfectWeather: false,\n showBorderEffects: false,\n tntExplodes: true,\n respawnBlocksExplode: true,\n fireSpreads: true,\n pvp: true,\n friendlyFire: false,\n mobSpawning: true,\n weatherCycle: true,\n resourceLink: emptyResourceLink(),\n };\n}\n\n/** Human-readable label for each setting, for the settings UI. */\nexport const SETTING_LABELS: Record<BooleanSettingKey, string> = {\n destructiveItems: 'Destructive items',\n playerDamage: 'Player damage',\n immutableWorld: 'Immutable world',\n mobsRestricted: 'Mobs restricted',\n perfectWeather: 'Perfect weather',\n showBorderEffects: 'Show border effects',\n tntExplodes: 'Explosives detonate',\n respawnBlocksExplode: 'Respawn blocks explode',\n fireSpreads: 'Fire spreads',\n pvp: 'Player vs player',\n friendlyFire: 'Friendly fire',\n mobSpawning: 'Creature spawning',\n weatherCycle: 'Weather cycle',\n};\n\n/** One-line description for each setting, for the settings UI. */\nexport const SETTING_DESCRIPTIONS: Record<BooleanSettingKey, string> = {\n destructiveItems: 'Allow explosives and harmful items. Off also disables explosions and fire spread.',\n playerDamage: 'Players can take damage. Off makes everyone invulnerable and disables combat.',\n immutableWorld: 'Players can interact but cannot break or place blocks. Great for demos and assessments.',\n mobsRestricted: 'No creatures spawn anywhere in the world.',\n perfectWeather: 'Keep the sky clear. Stops the weather from changing.',\n showBorderEffects: 'Show a visible effect on the edges of the build area.',\n tntExplodes: 'Explosives can detonate and damage the world.',\n respawnBlocksExplode: 'Respawn blocks can explode when used in the wrong place.',\n fireSpreads: 'Fire can spread from block to block.',\n pvp: 'Players can damage one another.',\n friendlyFire: 'Players on the same team can damage one another.',\n mobSpawning: 'Creatures spawn naturally over time.',\n weatherCycle: 'Weather changes on its own over time.',\n};\n"],"names":[],"mappings":"kDAsBO,MAAM,oBAAqD,GAAA,CAAC,kBAAoB,EAAA,cAAA,EAAgB,kBAAkB,gBAAkB,EAAA,gBAAA,EAAkB,mBAAqB,EAAA,aAAA,EAAe,sBAAwB,EAAA,aAAA,EAAe,KAAO,EAAA,cAAA,EAAgB,eAAe,cAAc;AA4BrR,SAAS,oBAAsC,GAAA;AACpD,EAAO,OAAA;AAAA,IACL,gBAAkB,EAAA,IAAA;AAAA,IAClB,YAAc,EAAA,IAAA;AAAA,IACd,cAAgB,EAAA,KAAA;AAAA,IAChB,cAAgB,EAAA,KAAA;AAAA,IAChB,cAAgB,EAAA,KAAA;AAAA,IAChB,iBAAmB,EAAA,KAAA;AAAA,IACnB,WAAa,EAAA,IAAA;AAAA,IACb,oBAAsB,EAAA,IAAA;AAAA,IACtB,WAAa,EAAA,IAAA;AAAA,IACb,GAAK,EAAA,IAAA;AAAA,IACL,YAAc,EAAA,KAAA;AAAA,IACd,WAAa,EAAA,IAAA;AAAA,IACb,YAAc,EAAA,IAAA;AAAA,IACd,cAAc,iBAAkB;AAAA,GAClC;AACF;AAGO,MAAM,cAAoD,GAAA;AAAA,EAC/D,gBAAkB,EAAA,mBAAA;AAAA,EAClB,YAAc,EAAA,eAAA;AAAA,EACd,cAAgB,EAAA,iBAAA;AAAA,EAChB,cAAgB,EAAA,iBAAA;AAAA,EAChB,cAAgB,EAAA,iBAAA;AAAA,EAChB,iBAAmB,EAAA,qBAAA;AAAA,EACnB,WAAa,EAAA,qBAAA;AAAA,EACb,oBAAsB,EAAA,wBAAA;AAAA,EACtB,WAAa,EAAA,cAAA;AAAA,EACb,GAAK,EAAA,kBAAA;AAAA,EACL,YAAc,EAAA,eAAA;AAAA,EACd,WAAa,EAAA,mBAAA;AAAA,EACb,YAAc,EAAA;AAChB;AAGO,MAAM,oBAA0D,GAAA;AAAA,EACrE,gBAAkB,EAAA,mFAAA;AAAA,EAClB,YAAc,EAAA,+EAAA;AAAA,EACd,cAAgB,EAAA,yFAAA;AAAA,EAChB,cAAgB,EAAA,2CAAA;AAAA,EAChB,cAAgB,EAAA,sDAAA;AAAA,EAChB,iBAAmB,EAAA,uDAAA;AAAA,EACnB,WAAa,EAAA,+CAAA;AAAA,EACb,oBAAsB,EAAA,0DAAA;AAAA,EACtB,WAAa,EAAA,sCAAA;AAAA,EACb,GAAK,EAAA,iCAAA;AAAA,EACL,YAAc,EAAA,kDAAA;AAAA,EACd,WAAa,EAAA,sCAAA;AAAA,EACb,YAAc,EAAA;AAChB"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const ENERGY_MAX = 12;
|
|
2
|
-
const DAY_STEPS = 10;
|
|
3
|
-
const NIGHT_STEPS = 6;
|
|
4
|
-
const CYCLE_STEPS = DAY_STEPS + NIGHT_STEPS;
|
|
5
|
-
function phaseAt(step) {
|
|
6
|
-
const s = (Math.floor(step) % CYCLE_STEPS + CYCLE_STEPS) % CYCLE_STEPS;
|
|
7
|
-
return s < DAY_STEPS ? "day" : "night";
|
|
8
|
-
}
|
|
9
|
-
function dayNumber(step) {
|
|
10
|
-
return Math.floor(Math.max(0, step) / CYCLE_STEPS) + 1;
|
|
11
|
-
}
|
|
12
|
-
function clampEnergy(value) {
|
|
13
|
-
if (!Number.isFinite(value)) return ENERGY_MAX;
|
|
14
|
-
return Math.max(0, Math.min(ENERGY_MAX, Math.floor(value)));
|
|
15
|
-
}export{CYCLE_STEPS,DAY_STEPS,ENERGY_MAX,NIGHT_STEPS,clampEnergy,dayNumber,phaseAt};//# sourceMappingURL=cycle.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cycle.js","sources":["../../../../../../src/features/games/vendored/core/cubeforge/cycle.ts"],"sourcesContent":["/**\n * Cubeforge day/night cycle and energy model.\n *\n * Time is a monotonically increasing integer `step`; gathering and placing each\n * advance it by one. The cycle alternates day and night. Energy gates how much\n * the player can gather before resting; resting advances to the next dawn and\n * refills energy. Deliberately gentle - this is a learning sandbox, not a\n * punishing survival game.\n */\n\nexport const ENERGY_MAX = 12;\n\n/** Steps of daylight, then steps of night, per full cycle. */\nexport const DAY_STEPS = 10;\nexport const NIGHT_STEPS = 6;\nexport const CYCLE_STEPS = DAY_STEPS + NIGHT_STEPS;\n\nexport type Phase = 'day' | 'night';\n\nexport function phaseAt(step: number): Phase {\n const s = ((Math.floor(step) % CYCLE_STEPS) + CYCLE_STEPS) % CYCLE_STEPS;\n return s < DAY_STEPS ? 'day' : 'night';\n}\n\n/** 1-based day number for display (first dawn is Day 1). */\nexport function dayNumber(step: number): number {\n return Math.floor(Math.max(0, step) / CYCLE_STEPS) + 1;\n}\n\n/** The step index of the next dawn strictly after the current cycle. */\nexport function nextDawnStep(step: number): number {\n return (Math.floor(Math.max(0, step) / CYCLE_STEPS) + 1) * CYCLE_STEPS;\n}\n\nexport function clampEnergy(value: number): number {\n if (!Number.isFinite(value)) return ENERGY_MAX;\n return Math.max(0, Math.min(ENERGY_MAX, Math.floor(value)));\n}\n"],"names":[],"mappings":"AAUO,MAAM,UAAa,GAAA;AAGnB,MAAM,SAAY,GAAA;AAClB,MAAM,WAAc,GAAA;AACpB,MAAM,cAAc,SAAY,GAAA;AAEhC,SAAS,QAAQ,IAAqB,EAAA;AAC3C,EAAA,MAAM,KAAK,IAAK,CAAA,KAAA,CAAM,IAAI,CAAA,GAAI,cAAc,WAAe,IAAA,WAAA;AAC3D,EAAO,OAAA,CAAA,GAAI,YAAY,KAAQ,GAAA,OAAA;AACjC;AAGO,SAAS,UAAU,IAAsB,EAAA;AAC9C,EAAO,OAAA,IAAA,CAAK,MAAM,IAAK,CAAA,GAAA,CAAI,GAAG,IAAI,CAAA,GAAI,WAAW,CAAI,GAAA,CAAA;AACvD;AAMO,SAAS,YAAY,KAAuB,EAAA;AACjD,EAAA,IAAI,CAAC,MAAA,CAAO,QAAS,CAAA,KAAK,GAAU,OAAA,UAAA;AACpC,EAAO,OAAA,IAAA,CAAK,GAAI,CAAA,CAAA,EAAG,IAAK,CAAA,GAAA,CAAI,YAAY,IAAK,CAAA,KAAA,CAAM,KAAK,CAAC,CAAC,CAAA;AAC5D"}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
4
|
-
class Inventory {
|
|
5
|
-
constructor(counts) {
|
|
6
|
-
__publicField(this, "counts");
|
|
7
|
-
this.counts = counts != null ? counts : /* @__PURE__ */ new Map();
|
|
8
|
-
}
|
|
9
|
-
/** Build from a persisted record, dropping invalid or non-positive entries. */
|
|
10
|
-
static from(record) {
|
|
11
|
-
const map = /* @__PURE__ */ new Map();
|
|
12
|
-
if (record && typeof record === "object") {
|
|
13
|
-
for (const [key, value] of Object.entries(record)) {
|
|
14
|
-
if (typeof value === "number" && Number.isFinite(value) && value > 0) {
|
|
15
|
-
map.set(key, Math.floor(value));
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return new Inventory(map);
|
|
20
|
-
}
|
|
21
|
-
count(key) {
|
|
22
|
-
var _a;
|
|
23
|
-
return (_a = this.counts.get(key)) != null ? _a : 0;
|
|
24
|
-
}
|
|
25
|
-
has(key, qty = 1) {
|
|
26
|
-
return this.count(key) >= qty;
|
|
27
|
-
}
|
|
28
|
-
/** Total number of items held (sum of all counts). */
|
|
29
|
-
total() {
|
|
30
|
-
let n = 0;
|
|
31
|
-
for (const v of this.counts.values()) n += v;
|
|
32
|
-
return n;
|
|
33
|
-
}
|
|
34
|
-
add(key, qty = 1) {
|
|
35
|
-
if (qty <= 0) return;
|
|
36
|
-
this.counts.set(key, this.count(key) + qty);
|
|
37
|
-
}
|
|
38
|
-
/** Remove `qty` of an item; returns false (and changes nothing) if short. */
|
|
39
|
-
take(key, qty = 1) {
|
|
40
|
-
if (qty <= 0) return false;
|
|
41
|
-
const have = this.count(key);
|
|
42
|
-
if (have < qty) return false;
|
|
43
|
-
const next = have - qty;
|
|
44
|
-
if (next === 0) this.counts.delete(key);
|
|
45
|
-
else this.counts.set(key, next);
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
canAfford(cost) {
|
|
49
|
-
var _a;
|
|
50
|
-
const need = /* @__PURE__ */ new Map();
|
|
51
|
-
for (const c of cost) need.set(c.item, ((_a = need.get(c.item)) != null ? _a : 0) + c.qty);
|
|
52
|
-
for (const [key, qty] of need) if (this.count(key) < qty) return false;
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
/** Pay a cost atomically; returns false and changes nothing if unaffordable. */
|
|
56
|
-
pay(cost) {
|
|
57
|
-
if (!this.canAfford(cost)) return false;
|
|
58
|
-
for (const c of cost) this.take(c.item, c.qty);
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
entries() {
|
|
62
|
-
return [...this.counts.entries()].map(([key, count]) => ({
|
|
63
|
-
key,
|
|
64
|
-
count
|
|
65
|
-
}));
|
|
66
|
-
}
|
|
67
|
-
serialize() {
|
|
68
|
-
const out = {};
|
|
69
|
-
for (const [key, value] of this.counts) out[key] = value;
|
|
70
|
-
return out;
|
|
71
|
-
}
|
|
72
|
-
clone() {
|
|
73
|
-
return new Inventory(new Map(this.counts));
|
|
74
|
-
}
|
|
75
|
-
}export{Inventory};//# sourceMappingURL=inventory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inventory.js","sources":["../../../../../../src/features/games/vendored/core/cubeforge/inventory.ts"],"sourcesContent":["/**\n * Cubeforge inventory: counts of items, keyed by item key.\n *\n * Backed by a Map for O(1) add/take/count, and serialises to a flat record for\n * persistence. Zero-count entries are dropped so the model and saves stay small.\n */\n\nimport type { RecipeCost } from './recipes';\n\nexport type SerializedInventory = Record<string, number>;\n\nexport class Inventory {\n private readonly counts: Map<string, number>;\n\n constructor(counts?: Map<string, number>) {\n this.counts = counts ?? new Map();\n }\n\n /** Build from a persisted record, dropping invalid or non-positive entries. */\n static from(record: SerializedInventory | undefined | null): Inventory {\n const map = new Map<string, number>();\n if (record && typeof record === 'object') {\n for (const [key, value] of Object.entries(record)) {\n if (typeof value === 'number' && Number.isFinite(value) && value > 0) {\n map.set(key, Math.floor(value));\n }\n }\n }\n return new Inventory(map);\n }\n\n count(key: string): number {\n return this.counts.get(key) ?? 0;\n }\n\n has(key: string, qty = 1): boolean {\n return this.count(key) >= qty;\n }\n\n /** Total number of items held (sum of all counts). */\n total(): number {\n let n = 0;\n for (const v of this.counts.values()) n += v;\n return n;\n }\n\n add(key: string, qty = 1): void {\n if (qty <= 0) return;\n this.counts.set(key, this.count(key) + qty);\n }\n\n /** Remove `qty` of an item; returns false (and changes nothing) if short. */\n take(key: string, qty = 1): boolean {\n if (qty <= 0) return false;\n const have = this.count(key);\n if (have < qty) return false;\n const next = have - qty;\n if (next === 0) this.counts.delete(key);\n else this.counts.set(key, next);\n return true;\n }\n\n canAfford(cost: readonly RecipeCost[]): boolean {\n const need = new Map<string, number>();\n for (const c of cost) need.set(c.item, (need.get(c.item) ?? 0) + c.qty);\n for (const [key, qty] of need) if (this.count(key) < qty) return false;\n return true;\n }\n\n /** Pay a cost atomically; returns false and changes nothing if unaffordable. */\n pay(cost: readonly RecipeCost[]): boolean {\n if (!this.canAfford(cost)) return false;\n for (const c of cost) this.take(c.item, c.qty);\n return true;\n }\n\n entries(): Array<{ key: string; count: number }> {\n return [...this.counts.entries()].map(([key, count]) => ({ key, count }));\n }\n\n serialize(): SerializedInventory {\n const out: SerializedInventory = {};\n for (const [key, value] of this.counts) out[key] = value;\n return out;\n }\n\n clone(): Inventory {\n return new Inventory(new Map(this.counts));\n }\n}\n"],"names":[],"mappings":";;;AASO,MAAM,SAAU,CAAA;AAAA,EAErB,YAAY,MAA8B,EAAA;AAD1C,IAAiB,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA;AAEf,IAAK,IAAA,CAAA,MAAA,GAAS,MAAU,IAAA,IAAA,GAAA,MAAA,mBAAA,IAAI,GAAI,EAAA;AAAA;AAClC;AAAA,EAGA,OAAO,KAAK,MAA2D,EAAA;AACrE,IAAM,MAAA,GAAA,uBAAU,GAAoB,EAAA;AACpC,IAAI,IAAA,MAAA,IAAU,OAAO,MAAA,KAAW,QAAU,EAAA;AACxC,MAAA,KAAA,MAAW,CAAC,GAAK,EAAA,KAAK,KAAK,MAAO,CAAA,OAAA,CAAQ,MAAM,CAAG,EAAA;AACjD,QAAI,IAAA,OAAO,UAAU,QAAY,IAAA,MAAA,CAAO,SAAS,KAAK,CAAA,IAAK,QAAQ,CAAG,EAAA;AACpE,UAAA,GAAA,CAAI,GAAI,CAAA,GAAA,EAAK,IAAK,CAAA,KAAA,CAAM,KAAK,CAAC,CAAA;AAAA;AAChC;AACF;AAEF,IAAO,OAAA,IAAI,UAAU,GAAG,CAAA;AAAA;AAC1B,EACA,MAAM,GAAqB,EAAA;AA3B7B,IAAA,IAAA,EAAA;AA4BI,IAAA,OAAA,CAAO,EAAK,GAAA,IAAA,CAAA,MAAA,CAAO,GAAI,CAAA,GAAG,MAAnB,IAAwB,GAAA,EAAA,G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CAAA,CAAE,IAAI,CAAA,KAAf,IAAoB,GAAA,EAAA,GAAA,CAAA,IAAK,EAAE,GAAG,CAAA;AACtE,IAAW,KAAA,MAAA,CAAC,GAAK,EAAA,GAAG,CAAK,IAAA,IAAA,EAAU,IAAA,IAAA,CAAK,KAAM,CAAA,GAAG,CAAI,GAAA,GAAA,EAAY,OAAA,KAAA;AACjE,IAAO,OAAA,IAAA;AAAA;AACT;AAAA,EAGA,IAAI,IAAsC,EAAA;AACxC,IAAA,IAAI,CAAC,IAAA,CAAK,SAAU,CAAA,IAAI,GAAU,OAAA,KAAA;AAClC,IAAA,KAAA,MAAW,KAAK,IAAM,EAAA,IAAA,CAAK,KAAK,CAAE,CAAA,IAAA,EAAM,EAAE,GAAG,CAAA;AAC7C,IAAO,OAAA,IAAA;AAAA;AACT,EACA,OAGG,GAAA;AACD,IAAA,OAAO,CAAC,GAAG,IAAK,CAAA,MAAA,CAAO,OAAQ,EAAC,CAAE,CAAA,GAAA,CAAI,CAAC,CAAC,GAAK,EAAA,KAAK,CAAO,MAAA;AAAA,MACvD,GAAA;AAAA,MACA;AAAA,KACA,CAAA,CAAA;AAAA;AACJ,EACA,SAAiC,GAAA;AAC/B,IAAA,MAAM,MAA2B,EAAC;AAClC,IAAW,KAAA,MAAA,CAAC,KAAK,KAAK,CAAA,IAAK,KAAK,MAAQ,EAAA,GAAA,CAAI,GAAG,CAAI,GAAA,KAAA;AACnD,IAAO,OAAA,GAAA;AAAA;AACT,EACA,KAAmB,GAAA;AACjB,IAAA,OAAO,IAAI,SAAU,CAAA,IAAI,GAAI,CAAA,IAAA,CAAK,MAAM,CAAC,CAAA;AAAA;AAE7C"}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
const CUBEFORGE_VERSION = "v1";
|
|
21
|
-
const CUBEFORGE_PREFIX = `yantra.games.cubeforge.${CUBEFORGE_VERSION}`;
|
|
22
|
-
class CubeforgeRepository {
|
|
23
|
-
constructor(storage, namespace, now = () => Date.now()) {
|
|
24
|
-
this.storage = storage;
|
|
25
|
-
this.namespace = namespace;
|
|
26
|
-
this.now = now;
|
|
27
|
-
}
|
|
28
|
-
async load() {
|
|
29
|
-
const raw = await this.storage.getItem(this.key());
|
|
30
|
-
if (raw === null) return null;
|
|
31
|
-
let parsed;
|
|
32
|
-
try {
|
|
33
|
-
parsed = JSON.parse(raw);
|
|
34
|
-
} catch (e) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
return coerce(parsed);
|
|
38
|
-
}
|
|
39
|
-
async save(snapshot) {
|
|
40
|
-
const record = __spreadProps(__spreadValues({}, snapshot), {
|
|
41
|
-
updatedAt: this.now()
|
|
42
|
-
});
|
|
43
|
-
await this.storage.setItem(this.key(), JSON.stringify(record));
|
|
44
|
-
}
|
|
45
|
-
async clear() {
|
|
46
|
-
await this.storage.removeItem(this.key());
|
|
47
|
-
}
|
|
48
|
-
key() {
|
|
49
|
-
return `${CUBEFORGE_PREFIX}:${this.namespace}`;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
function coerce(value) {
|
|
53
|
-
if (!value || typeof value !== "object") return null;
|
|
54
|
-
const v = value;
|
|
55
|
-
if (typeof v.seed !== "number") return null;
|
|
56
|
-
const init = {
|
|
57
|
-
seed: v.seed >>> 0
|
|
58
|
-
};
|
|
59
|
-
const world = coerceWorld(v.world);
|
|
60
|
-
if (world) init.world = world;
|
|
61
|
-
if (v.inventory && typeof v.inventory === "object") {
|
|
62
|
-
const inv = {};
|
|
63
|
-
for (const [key, n] of Object.entries(v.inventory)) {
|
|
64
|
-
if (typeof n === "number" && Number.isFinite(n) && n > 0) inv[key] = Math.floor(n);
|
|
65
|
-
}
|
|
66
|
-
init.inventory = inv;
|
|
67
|
-
}
|
|
68
|
-
if (typeof v.energy === "number") init.energy = v.energy;
|
|
69
|
-
if (typeof v.step === "number") init.step = v.step;
|
|
70
|
-
if (typeof v.selectedItem === "string") init.selectedItem = v.selectedItem;
|
|
71
|
-
return init;
|
|
72
|
-
}
|
|
73
|
-
function coerceWorld(value) {
|
|
74
|
-
if (!value || typeof value !== "object") return void 0;
|
|
75
|
-
const v = value;
|
|
76
|
-
const bounds = v.bounds;
|
|
77
|
-
if (!bounds || typeof bounds.x !== "number" || typeof bounds.y !== "number" || typeof bounds.z !== "number" || !v.blocks || typeof v.blocks !== "object") {
|
|
78
|
-
return void 0;
|
|
79
|
-
}
|
|
80
|
-
const blocks = {};
|
|
81
|
-
for (const [key, id] of Object.entries(v.blocks)) {
|
|
82
|
-
if (typeof id === "number") blocks[key] = id;
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
bounds: {
|
|
86
|
-
x: bounds.x,
|
|
87
|
-
y: bounds.y,
|
|
88
|
-
z: bounds.z
|
|
89
|
-
},
|
|
90
|
-
blocks
|
|
91
|
-
};
|
|
92
|
-
}export{CUBEFORGE_PREFIX,CUBEFORGE_VERSION,CubeforgeRepository};//# sourceMappingURL=save.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"save.js","sources":["../../../../../../src/features/games/vendored/core/cubeforge/save.ts"],"sourcesContent":["/**\n * Cubeforge persistence.\n *\n * Cubeforge is one continuous world per organisation, so it needs only a single\n * namespaced key (not the multi-world index Blockwright uses). Reads are\n * defensive: a corrupt or partial save returns `null` or a best-effort partial,\n * and the session regenerates anything missing from the seed.\n *\n * yantra.games.cubeforge.v1:<org> -> CubeforgeSave\n */\n\nimport type { KeyValueStorage } from '../storage/storage';\nimport type { CubeforgeInit, CubeforgeSnapshot } from './session';\nimport type { SerializedWorld } from '../engine/world';\n\nexport const CUBEFORGE_VERSION = 'v1';\nexport const CUBEFORGE_PREFIX = `yantra.games.cubeforge.${CUBEFORGE_VERSION}`;\n\nexport interface CubeforgeSave extends CubeforgeSnapshot {\n updatedAt: number;\n}\n\nexport class CubeforgeRepository {\n constructor(\n private readonly storage: KeyValueStorage,\n private readonly namespace: string,\n private readonly now: () => number = () => Date.now(),\n ) {}\n\n async load(): Promise<CubeforgeInit | null> {\n const raw = await this.storage.getItem(this.key());\n if (raw === null) return null;\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n return null;\n }\n return coerce(parsed);\n }\n\n async save(snapshot: CubeforgeSnapshot): Promise<void> {\n const record: CubeforgeSave = { ...snapshot, updatedAt: this.now() };\n await this.storage.setItem(this.key(), JSON.stringify(record));\n }\n\n async clear(): Promise<void> {\n await this.storage.removeItem(this.key());\n }\n\n private key(): string {\n return `${CUBEFORGE_PREFIX}:${this.namespace}`;\n }\n}\n\nfunction coerce(value: unknown): CubeforgeInit | null {\n if (!value || typeof value !== 'object') return null;\n const v = value as Record<string, unknown>;\n if (typeof v.seed !== 'number') return null;\n\n const init: CubeforgeInit = { seed: v.seed >>> 0 };\n\n const world = coerceWorld(v.world);\n if (world) init.world = world;\n\n if (v.inventory && typeof v.inventory === 'object') {\n const inv: Record<string, number> = {};\n for (const [key, n] of Object.entries(v.inventory as Record<string, unknown>)) {\n if (typeof n === 'number' && Number.isFinite(n) && n > 0) inv[key] = Math.floor(n);\n }\n init.inventory = inv;\n }\n\n if (typeof v.energy === 'number') init.energy = v.energy;\n if (typeof v.step === 'number') init.step = v.step;\n if (typeof v.selectedItem === 'string') init.selectedItem = v.selectedItem;\n\n return init;\n}\n\n/** Accept a world only if it has the right shape; the session sanitises cells. */\nfunction coerceWorld(value: unknown): SerializedWorld | undefined {\n if (!value || typeof value !== 'object') return undefined;\n const v = value as Record<string, unknown>;\n const bounds = v.bounds as Record<string, unknown> | undefined;\n if (\n !bounds ||\n typeof bounds.x !== 'number' ||\n typeof bounds.y !== 'number' ||\n typeof bounds.z !== 'number' ||\n !v.blocks ||\n typeof v.blocks !== 'object'\n ) {\n return undefined;\n }\n const blocks: Record<string, number> = {};\n for (const [key, id] of Object.entries(v.blocks as Record<string, unknown>)) {\n if (typeof id === 'number') blocks[key] = id;\n }\n return { bounds: { x: bounds.x, y: bounds.y, z: bounds.z }, blocks };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAcO,MAAM,iBAAoB,GAAA;AACpB,MAAA,gBAAA,GAAmB,0BAA0B,iBAAiB,CAAA;AAIpE,MAAM,mBAAoB,CAAA;AAAA,EAC/B,YAA6B,OAA2C,EAAA,SAAA,EAAoC,MAAoB,MAAM,IAAA,CAAK,KAAO,EAAA;AAArH,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAA2C,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AAAoC,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AAAA;AAAuC,EACnJ,MAAM,IAAsC,GAAA;AAC1C,IAAA,MAAM,MAAM,MAAM,IAAA,CAAK,QAAQ,OAAQ,CAAA,IAAA,CAAK,KAAK,CAAA;AACjD,IAAI,IAAA,GAAA,KAAQ,MAAa,OAAA,IAAA;AAC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KAAO,QAAU,EAAA,MAAA,CAAO,GAAG,CAAI,GAAA,EAAA;AAAA;AAE5C,EAAO,OAAA;AAAA,IACL,MAAQ,EAAA;AAAA,MACN,GAAG,MAAO,CAAA,CAAA;AAAA,MACV,GAAG,MAAO,CAAA,CAAA;AAAA,MACV,GAAG,MAAO,CAAA;AAAA,KACZ;AAAA,IACA;AAAA,GACF;AACF"}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import {ReactiveValue}from'../store/reactive.js';import {VoxelWorld,DEFAULT_BOUNDS}from'../engine/world.js';import {itemByKey,itemForBlock,ITEMS}from'./items.js';import {recipeById,RECIPES}from'./recipes.js';import {Inventory}from'./inventory.js';import {clampEnergy,ENERGY_MAX,CYCLE_STEPS,phaseAt,dayNumber}from'./cycle.js';import {generateWorld}from'./worldgen.js';var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
class CubeforgeSession {
|
|
5
|
-
constructor(init = {}) {
|
|
6
|
-
__publicField(this, "world");
|
|
7
|
-
__publicField(this, "inventory");
|
|
8
|
-
__publicField(this, "energy");
|
|
9
|
-
__publicField(this, "step");
|
|
10
|
-
__publicField(this, "selectedItem");
|
|
11
|
-
__publicField(this, "seed");
|
|
12
|
-
__publicField(this, "state");
|
|
13
|
-
var _a, _b;
|
|
14
|
-
this.seed = typeof init.seed === "number" && Number.isFinite(init.seed) ? init.seed >>> 0 : 1;
|
|
15
|
-
this.world = init.world ? VoxelWorld.deserialize(init.world) : generateWorld(this.seed, DEFAULT_BOUNDS);
|
|
16
|
-
this.inventory = Inventory.from(init.inventory);
|
|
17
|
-
this.energy = clampEnergy((_a = init.energy) != null ? _a : ENERGY_MAX);
|
|
18
|
-
this.step = Number.isInteger(init.step) && init.step >= 0 ? init.step : 0;
|
|
19
|
-
this.selectedItem = this.resolveSelected((_b = init.selectedItem) != null ? _b : void 0);
|
|
20
|
-
this.state = new ReactiveValue(this.snapshot());
|
|
21
|
-
}
|
|
22
|
-
get query() {
|
|
23
|
-
return this.state;
|
|
24
|
-
}
|
|
25
|
-
getState() {
|
|
26
|
-
return this.state.get();
|
|
27
|
-
}
|
|
28
|
-
// --- commands ---
|
|
29
|
-
/** Choose which placeable item a tap will place. */
|
|
30
|
-
selectItem(key) {
|
|
31
|
-
const item = itemByKey(key);
|
|
32
|
-
if (!item || item.placesBlock == null || this.selectedItem === key) return;
|
|
33
|
-
this.selectedItem = key;
|
|
34
|
-
this.publish();
|
|
35
|
-
}
|
|
36
|
-
/** Harvest the top block of a column into the inventory. Costs 1 energy. */
|
|
37
|
-
gather(x, y) {
|
|
38
|
-
if (this.energy <= 0) return false;
|
|
39
|
-
const z = this.columnTop(x, y);
|
|
40
|
-
if (z < 0) return false;
|
|
41
|
-
const blockId = this.world.get(x, y, z);
|
|
42
|
-
const result = this.world.break(x, y, z);
|
|
43
|
-
if (!result.ok) return false;
|
|
44
|
-
const item = itemForBlock(blockId);
|
|
45
|
-
if (item) {
|
|
46
|
-
this.inventory.add(item.key, 1);
|
|
47
|
-
if (this.selectedItem == null && item.placesBlock != null) this.selectedItem = item.key;
|
|
48
|
-
}
|
|
49
|
-
this.energy -= 1;
|
|
50
|
-
this.step += 1;
|
|
51
|
-
this.publish();
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
/** Place the selected item on the first empty cell of a column; consumes one. */
|
|
55
|
-
place(x, y) {
|
|
56
|
-
const key = this.selectedItem;
|
|
57
|
-
if (!key) return false;
|
|
58
|
-
const item = itemByKey(key);
|
|
59
|
-
if (!item || item.placesBlock == null) return false;
|
|
60
|
-
if (!this.inventory.has(key, 1)) return false;
|
|
61
|
-
const z = this.firstEmpty(x, y);
|
|
62
|
-
if (z < 0) return false;
|
|
63
|
-
const result = this.world.place(x, y, z, item.placesBlock);
|
|
64
|
-
if (!result.ok) return false;
|
|
65
|
-
this.inventory.take(key, 1);
|
|
66
|
-
this.step += 1;
|
|
67
|
-
this.publish();
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
/** Craft a recipe if its inputs are in stock. */
|
|
71
|
-
craft(recipeId) {
|
|
72
|
-
const recipe = recipeById(recipeId);
|
|
73
|
-
if (!recipe) return false;
|
|
74
|
-
if (!this.inventory.pay(recipe.inputs)) return false;
|
|
75
|
-
this.inventory.add(recipe.output.item, recipe.output.qty);
|
|
76
|
-
const out = itemByKey(recipe.output.item);
|
|
77
|
-
if (this.selectedItem == null && (out == null ? void 0 : out.placesBlock) != null) this.selectedItem = out.key;
|
|
78
|
-
this.publish();
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
/** Rest through the night: advance to the next dawn and refill energy. */
|
|
82
|
-
rest() {
|
|
83
|
-
this.step = (Math.floor(this.step / CYCLE_STEPS) + 1) * CYCLE_STEPS;
|
|
84
|
-
this.energy = ENERGY_MAX;
|
|
85
|
-
this.publish();
|
|
86
|
-
}
|
|
87
|
-
// --- persistence ---
|
|
88
|
-
serialize() {
|
|
89
|
-
return {
|
|
90
|
-
seed: this.seed,
|
|
91
|
-
world: this.world.serialize(),
|
|
92
|
-
inventory: this.inventory.serialize(),
|
|
93
|
-
energy: this.energy,
|
|
94
|
-
step: this.step,
|
|
95
|
-
selectedItem: this.selectedItem
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
// --- internals ---
|
|
99
|
-
resolveSelected(key) {
|
|
100
|
-
if (key) {
|
|
101
|
-
const item = itemByKey(key);
|
|
102
|
-
if ((item == null ? void 0 : item.placesBlock) != null) return key;
|
|
103
|
-
}
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
/** Highest occupied z in a column, or -1 if the column is empty. */
|
|
107
|
-
columnTop(x, y) {
|
|
108
|
-
if (!this.world.inBounds(x, y, 0)) return -1;
|
|
109
|
-
for (let z = this.world.bounds.z - 1; z >= 0; z -= 1) {
|
|
110
|
-
if (this.world.has(x, y, z)) return z;
|
|
111
|
-
}
|
|
112
|
-
return -1;
|
|
113
|
-
}
|
|
114
|
-
/** Lowest empty z in a column, or -1 if the column is full. */
|
|
115
|
-
firstEmpty(x, y) {
|
|
116
|
-
if (!this.world.inBounds(x, y, 0)) return -1;
|
|
117
|
-
for (let z = 0; z < this.world.bounds.z; z += 1) {
|
|
118
|
-
if (!this.world.has(x, y, z)) return z;
|
|
119
|
-
}
|
|
120
|
-
return -1;
|
|
121
|
-
}
|
|
122
|
-
publish() {
|
|
123
|
-
this.state.set(this.snapshot());
|
|
124
|
-
}
|
|
125
|
-
snapshot() {
|
|
126
|
-
const slots = [];
|
|
127
|
-
for (const item of ITEMS) {
|
|
128
|
-
const count = this.inventory.count(item.key);
|
|
129
|
-
if (count > 0) slots.push({
|
|
130
|
-
item,
|
|
131
|
-
count
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
const selected = this.selectedItem;
|
|
135
|
-
return {
|
|
136
|
-
bounds: this.world.bounds,
|
|
137
|
-
blocks: this.world.drawOrder(),
|
|
138
|
-
blockCount: this.world.count(),
|
|
139
|
-
inventory: slots,
|
|
140
|
-
selectedItem: selected,
|
|
141
|
-
energy: this.energy,
|
|
142
|
-
energyMax: ENERGY_MAX,
|
|
143
|
-
step: this.step,
|
|
144
|
-
day: dayNumber(this.step),
|
|
145
|
-
phase: phaseAt(this.step),
|
|
146
|
-
canGather: this.energy > 0,
|
|
147
|
-
canPlace: selected != null && this.inventory.has(selected, 1),
|
|
148
|
-
recipes: RECIPES.map((recipe) => ({
|
|
149
|
-
recipe,
|
|
150
|
-
canCraft: this.inventory.canAfford(recipe.inputs)
|
|
151
|
-
}))
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
}export{CubeforgeSession};//# sourceMappingURL=session.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sources":["../../../../../../src/features/games/vendored/core/cubeforge/session.ts"],"sourcesContent":["/**\n * The Cubeforge session: the single source of truth for one survival world.\n *\n * It owns the voxel terrain, the inventory, the day/night clock, and energy, and\n * exposes a reactive read model plus gated commands. The UI reads the same state\n * the commands enforce, so a view can never place an item the player doesn't have\n * or gather with no energy. Pure TypeScript - fully unit-tested, no React.\n */\n\nimport { ReactiveValue, type Query } from '../store/reactive';\nimport { VoxelWorld, DEFAULT_BOUNDS, type PlacedBlock, type SerializedWorld, type WorldBounds } from '../engine/world';\nimport { ITEMS, itemByKey, itemForBlock, type CubeItem } from './items';\nimport { RECIPES, recipeById, type Recipe } from './recipes';\nimport { Inventory, type SerializedInventory } from './inventory';\nimport { ENERGY_MAX, CYCLE_STEPS, clampEnergy, phaseAt, dayNumber, type Phase } from './cycle';\nimport { generateWorld } from './worldgen';\n\nexport interface InventorySlot {\n readonly item: CubeItem;\n readonly count: number;\n}\n\nexport interface RecipeView {\n readonly recipe: Recipe;\n readonly canCraft: boolean;\n}\n\nexport interface CubeforgeState {\n readonly bounds: WorldBounds;\n /** Blocks ordered back-to-front for rendering. */\n readonly blocks: readonly PlacedBlock[];\n readonly blockCount: number;\n /** Non-empty inventory slots, in catalogue order. */\n readonly inventory: readonly InventorySlot[];\n /** Key of the placeable item currently selected, or null. */\n readonly selectedItem: string | null;\n readonly energy: number;\n readonly energyMax: number;\n readonly step: number;\n readonly day: number;\n readonly phase: Phase;\n /** Whether the player can gather right now (has energy). */\n readonly canGather: boolean;\n /** Whether the selected item is in stock to place. */\n readonly canPlace: boolean;\n readonly recipes: readonly RecipeView[];\n}\n\n/** Everything needed to restore a session. Also the persisted save shape. */\nexport interface CubeforgeSnapshot {\n seed: number;\n world: SerializedWorld;\n inventory: SerializedInventory;\n energy: number;\n step: number;\n selectedItem: string | null;\n}\n\nexport type CubeforgeInit = Partial<CubeforgeSnapshot>;\n\nexport class CubeforgeSession {\n private world: VoxelWorld;\n private readonly inventory: Inventory;\n private energy: number;\n private step: number;\n private selectedItem: string | null;\n private readonly seed: number;\n private readonly state: ReactiveValue<CubeforgeState>;\n\n constructor(init: CubeforgeInit = {}) {\n this.seed = typeof init.seed === 'number' && Number.isFinite(init.seed) ? init.seed >>> 0 : 1;\n this.world = init.world ? VoxelWorld.deserialize(init.world) : generateWorld(this.seed, DEFAULT_BOUNDS);\n this.inventory = Inventory.from(init.inventory);\n this.energy = clampEnergy(init.energy ?? ENERGY_MAX);\n this.step = Number.isInteger(init.step) && (init.step as number) >= 0 ? (init.step as number) : 0;\n this.selectedItem = this.resolveSelected(init.selectedItem ?? undefined);\n this.state = new ReactiveValue<CubeforgeState>(this.snapshot());\n }\n\n get query(): Query<CubeforgeState> {\n return this.state;\n }\n\n getState(): CubeforgeState {\n return this.state.get();\n }\n\n // --- commands ---\n\n /** Choose which placeable item a tap will place. */\n selectItem(key: string): void {\n const item = itemByKey(key);\n if (!item || item.placesBlock == null || this.selectedItem === key) return;\n this.selectedItem = key;\n this.publish();\n }\n\n /** Harvest the top block of a column into the inventory. Costs 1 energy. */\n gather(x: number, y: number): boolean {\n if (this.energy <= 0) return false;\n const z = this.columnTop(x, y);\n if (z < 0) return false;\n const blockId = this.world.get(x, y, z);\n const result = this.world.break(x, y, z);\n if (!result.ok) return false;\n const item = itemForBlock(blockId);\n if (item) {\n this.inventory.add(item.key, 1);\n if (this.selectedItem == null && item.placesBlock != null) this.selectedItem = item.key;\n }\n this.energy -= 1;\n this.step += 1;\n this.publish();\n return true;\n }\n\n /** Place the selected item on the first empty cell of a column; consumes one. */\n place(x: number, y: number): boolean {\n const key = this.selectedItem;\n if (!key) return false;\n const item = itemByKey(key);\n if (!item || item.placesBlock == null) return false;\n if (!this.inventory.has(key, 1)) return false;\n const z = this.firstEmpty(x, y);\n if (z < 0) return false;\n const result = this.world.place(x, y, z, item.placesBlock);\n if (!result.ok) return false;\n this.inventory.take(key, 1);\n this.step += 1;\n this.publish();\n return true;\n }\n\n /** Craft a recipe if its inputs are in stock. */\n craft(recipeId: string): boolean {\n const recipe = recipeById(recipeId);\n if (!recipe) return false;\n if (!this.inventory.pay(recipe.inputs)) return false;\n this.inventory.add(recipe.output.item, recipe.output.qty);\n const out = itemByKey(recipe.output.item);\n if (this.selectedItem == null && out?.placesBlock != null) this.selectedItem = out.key;\n this.publish();\n return true;\n }\n\n /** Rest through the night: advance to the next dawn and refill energy. */\n rest(): void {\n this.step = (Math.floor(this.step / CYCLE_STEPS) + 1) * CYCLE_STEPS;\n this.energy = ENERGY_MAX;\n this.publish();\n }\n\n // --- persistence ---\n\n serialize(): CubeforgeSnapshot {\n return {\n seed: this.seed,\n world: this.world.serialize(),\n inventory: this.inventory.serialize(),\n energy: this.energy,\n step: this.step,\n selectedItem: this.selectedItem,\n };\n }\n\n // --- internals ---\n\n private resolveSelected(key?: string): string | null {\n if (key) {\n const item = itemByKey(key);\n if (item?.placesBlock != null) return key;\n }\n return null;\n }\n\n /** Highest occupied z in a column, or -1 if the column is empty. */\n private columnTop(x: number, y: number): number {\n if (!this.world.inBounds(x, y, 0)) return -1;\n for (let z = this.world.bounds.z - 1; z >= 0; z -= 1) {\n if (this.world.has(x, y, z)) return z;\n }\n return -1;\n }\n\n /** Lowest empty z in a column, or -1 if the column is full. */\n private firstEmpty(x: number, y: number): number {\n if (!this.world.inBounds(x, y, 0)) return -1;\n for (let z = 0; z < this.world.bounds.z; z += 1) {\n if (!this.world.has(x, y, z)) return z;\n }\n return -1;\n }\n\n private publish(): void {\n this.state.set(this.snapshot());\n }\n\n private snapshot(): CubeforgeState {\n const slots: InventorySlot[] = [];\n for (const item of ITEMS) {\n const count = this.inventory.count(item.key);\n if (count > 0) slots.push({ item, count });\n }\n const selected = this.selectedItem;\n return {\n bounds: this.world.bounds,\n blocks: this.world.drawOrder(),\n blockCount: this.world.count(),\n inventory: slots,\n selectedItem: selected,\n energy: this.energy,\n energyMax: ENERGY_MAX,\n step: this.step,\n day: dayNumber(this.step),\n phase: phaseAt(this.step),\n canGather: this.energy > 0,\n canPlace: selected !=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|
-
}
|
|
9
|
-
function unprojectToCell(sx, sy, z, cfg) {
|
|
10
|
-
const u = (sx - cfg.originX) / (cfg.tileWidth / 2);
|
|
11
|
-
const v = (sy - cfg.originY + z * cfg.blockHeight) / (cfg.tileHeight / 2);
|
|
12
|
-
return {
|
|
13
|
-
x: Math.round((u + v) / 2),
|
|
14
|
-
y: Math.round((v - u) / 2)
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function depthKey(x, y, z) {
|
|
18
|
-
return x + y + z;
|
|
19
|
-
}
|
|
20
|
-
function blockFaces(x, y, z, cfg) {
|
|
21
|
-
const top0 = project(x, y, z + 1, cfg);
|
|
22
|
-
const top1 = project(x + 1, y, z + 1, cfg);
|
|
23
|
-
const top2 = project(x + 1, y + 1, z + 1, cfg);
|
|
24
|
-
const top3 = project(x, y + 1, z + 1, cfg);
|
|
25
|
-
const botL0 = project(x, y + 1, z, cfg);
|
|
26
|
-
const botL1 = project(x + 1, y + 1, z, cfg);
|
|
27
|
-
const botR1 = project(x + 1, y, z, cfg);
|
|
28
|
-
return {
|
|
29
|
-
top: [top0, top1, top2, top3],
|
|
30
|
-
// Left face faces toward +y (down-left on screen).
|
|
31
|
-
left: [top3, top2, botL1, botL0],
|
|
32
|
-
// Right face faces toward +x (down-right on screen).
|
|
33
|
-
right: [top2, top1, botR1, botL1]
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function toSvgPoints(points) {
|
|
37
|
-
return points.map((p) => `${round(p.sx)},${round(p.sy)}`).join(" ");
|
|
38
|
-
}
|
|
39
|
-
function round(n) {
|
|
40
|
-
return Math.round(n * 100) / 100;
|
|
41
|
-
}export{blockFaces,depthKey,project,toSvgPoints,unprojectToCell};//# sourceMappingURL=iso.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"iso.js","sources":["../../../../../../src/features/games/vendored/core/engine/iso.ts"],"sourcesContent":["/**\n * Isometric projection math for the block-building game.\n *\n * Original implementation. A block lives on an integer grid (x, y, z); this maps\n * grid coordinates to 2D screen points for a 2:1 isometric view and builds the\n * three visible faces of a cube so a renderer can paint them back-to-front.\n */\n\nexport interface Point {\n readonly sx: number;\n readonly sy: number;\n}\n\nexport interface IsoConfig {\n /** Full width of a tile diamond, in px. */\n readonly tileWidth: number;\n /** Full height of a tile diamond, in px (classically tileWidth / 2). */\n readonly tileHeight: number;\n /** Vertical screen offset per +1 in z (block height), in px. */\n readonly blockHeight: number;\n /** Screen-space origin the grid is drawn around. */\n readonly originX: number;\n readonly originY: number;\n}\n\nexport const defaultIsoConfig = (originX = 0, originY = 0): IsoConfig => ({\n tileWidth: 48,\n tileHeight: 24,\n blockHeight: 28,\n originX,\n originY,\n});\n\n/** Project a grid coordinate to a 2D screen point. */\nexport function project(x: number, y: number, z: number, cfg: IsoConfig): Point {\n const sx = cfg.originX + (x - y) * (cfg.tileWidth / 2);\n const sy = cfg.originY + (x + y) * (cfg.tileHeight / 2) - z * cfg.blockHeight;\n return { sx, sy };\n}\n\n/**\n * Inverse of `project` for a known z-plane: map a screen point back to the grid\n * cell on that plane, rounded to the nearest integer cell. Used for tap-to-build\n * hit testing when editing a single height layer.\n */\nexport function unprojectToCell(sx: number, sy: number, z: number, cfg: IsoConfig): { x: number; y: number } {\n const u = (sx - cfg.originX) / (cfg.tileWidth / 2); // = x - y\n const v = (sy - cfg.originY + z * cfg.blockHeight) / (cfg.tileHeight / 2); // = x + y\n return { x: Math.round((u + v) / 2), y: Math.round((v - u) / 2) };\n}\n\n/**\n * Painter's-algorithm depth key. Blocks with a smaller key are farther from the\n * camera and must be drawn first. For this projection, draw order along\n * (x + y + z) ascending yields correct occlusion for axis-aligned stacked cubes.\n */\nexport function depthKey(x: number, y: number, z: number): number {\n return x + y + z;\n}\n\nexport interface BlockFaces {\n /** Top rhombus (brightest). */\n readonly top: readonly Point[];\n /** Left face (medium shade). */\n readonly left: readonly Point[];\n /** Right face (darkest). */\n readonly right: readonly Point[];\n}\n\n/**\n * The three visible faces of the unit cube occupying cell (x, y, z), as screen\n * polygons. Corners are named by grid offset; z+1 is the top of the cube.\n */\nexport function blockFaces(x: number, y: number, z: number, cfg: IsoConfig): BlockFaces {\n const top0 = project(x, y, z + 1, cfg);\n const top1 = project(x + 1, y, z + 1, cfg);\n const top2 = project(x + 1, y + 1, z + 1, cfg);\n const top3 = project(x, y + 1, z + 1, cfg);\n\n const botL0 = project(x, y + 1, z, cfg);\n const botL1 = project(x + 1, y + 1, z, cfg);\n const botR1 = project(x + 1, y, z, cfg);\n\n return {\n top: [top0, top1, top2, top3],\n // Left face faces toward +y (down-left on screen).\n left: [top3, top2, botL1, botL0],\n // Right face faces toward +x (down-right on screen).\n right: [top2, top1, botR1, botL1],\n };\n}\n\n/** Serialize a polygon to an SVG `points` string. */\nexport function toSvgPoints(points: readonly Point[]): string {\n return points.map((p) => `${round(p.sx)},${round(p.sy)}`).join(' ');\n}\n\nfunction round(n: number): number {\n return Math.round(n * 100) / 100;\n}\n"],"names":[],"mappings":"AAgCO,SAAS,OAAQ,CAAA,CAAA,EAAW,CAAW,EAAA,CAAA,EAAW,GAAuB,EAAA;AAC9E,EAAA,MAAM,KAAK,GAAI,CAAA,OAAA,GAAA,CAAW,CAAI,GAAA,CAAA,KAAM,IAAI,SAAY,GAAA,CAAA,CAAA;AACpD,EAAM,MAAA,EAAA,GAAK,IAAI,OAAW,GAAA,CAAA,CAAA,GAAI,MAAM,GAAI,CAAA,UAAA,GAAa,CAAK,CAAA,GAAA,CAAA,GAAI,GAAI,CAAA,WAAA;AAClE,EAAO,OAAA;AAAA,IACL,EAAA;AAAA,IACA;AAAA,GACF;AACF;AAOO,SAAS,eAAgB,CAAA,EAAA,EAAY,EAAY,EAAA,CAAA,EAAW,GAGjE,EAAA;AACA,EAAA,MAAM,CAAK,GAAA,CAAA,EAAA,GAAK,GAAI,CAAA,OAAA,KAAY,IAAI,SAAY,GAAA,CAAA,CAAA;AAChD,EAAM,MAAA,CAAA,GAAA,CAAK,KAAK,GAAI,C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