@adminide-stack/yantra-mobile 12.0.171-alpha.0 → 12.0.172-alpha.0

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.
Files changed (90) hide show
  1. package/lib/compute.js +51 -1
  2. package/lib/compute.js.map +1 -1
  3. package/lib/features/apps/AppsCatalog.js +10 -0
  4. package/lib/features/apps/AppsCatalog.js.map +1 -1
  5. package/lib/features/apps/mobileAppCatalog.js +9 -0
  6. package/lib/features/apps/mobileAppCatalog.js.map +1 -1
  7. package/lib/features/apps/nativeSurfaceTwin.js +2 -1
  8. package/lib/features/apps/nativeSurfaceTwin.js.map +1 -1
  9. package/lib/features/canvas/set/agent/prompt.js +4 -5
  10. package/lib/features/canvas/set/agent/prompt.js.map +1 -1
  11. package/lib/features/canvas/set/supplyLibrary.js +1294 -2
  12. package/lib/features/canvas/set/supplyLibrary.js.map +1 -1
  13. package/lib/features/games/cubeforge3D.js +26 -0
  14. package/lib/features/games/cubeforge3D.js.map +1 -0
  15. package/lib/features/games/vendored/core/classroom/permissions.js +76 -0
  16. package/lib/features/games/vendored/core/classroom/permissions.js.map +1 -0
  17. package/lib/features/games/vendored/core/classroom/resourceLink.js +101 -0
  18. package/lib/features/games/vendored/core/classroom/resourceLink.js.map +1 -0
  19. package/lib/features/games/vendored/core/classroom/rules.js +83 -0
  20. package/lib/features/games/vendored/core/classroom/rules.js.map +1 -0
  21. package/lib/features/games/vendored/core/classroom/worldSettings.js +49 -0
  22. package/lib/features/games/vendored/core/classroom/worldSettings.js.map +1 -0
  23. package/lib/features/games/vendored/core/cubeforge/cycle.js +15 -0
  24. package/lib/features/games/vendored/core/cubeforge/cycle.js.map +1 -0
  25. package/lib/features/games/vendored/core/cubeforge/inventory.js +75 -0
  26. package/lib/features/games/vendored/core/cubeforge/inventory.js.map +1 -0
  27. package/lib/features/games/vendored/core/cubeforge/items.js +62 -0
  28. package/lib/features/games/vendored/core/cubeforge/items.js.map +1 -0
  29. package/lib/features/games/vendored/core/cubeforge/nativeWorld.js +4 -0
  30. package/lib/features/games/vendored/core/cubeforge/nativeWorld.js.map +1 -0
  31. package/lib/features/games/vendored/core/cubeforge/recipes.js +52 -0
  32. package/lib/features/games/vendored/core/cubeforge/recipes.js.map +1 -0
  33. package/lib/features/games/vendored/core/cubeforge/save.js +92 -0
  34. package/lib/features/games/vendored/core/cubeforge/save.js.map +1 -0
  35. package/lib/features/games/vendored/core/cubeforge/session.js +154 -0
  36. package/lib/features/games/vendored/core/cubeforge/session.js.map +1 -0
  37. package/lib/features/games/vendored/core/cubeforge/worldgen.js +44 -0
  38. package/lib/features/games/vendored/core/cubeforge/worldgen.js.map +1 -0
  39. package/lib/features/games/vendored/core/engine/iso.js +41 -0
  40. package/lib/features/games/vendored/core/engine/iso.js.map +1 -0
  41. package/lib/features/games/vendored/core/engine/palette.js +53 -0
  42. package/lib/features/games/vendored/core/engine/palette.js.map +1 -0
  43. package/lib/features/games/vendored/core/engine/world.js +148 -0
  44. package/lib/features/games/vendored/core/engine/world.js.map +1 -0
  45. package/lib/features/games/vendored/core/games/catalog.js +34 -0
  46. package/lib/features/games/vendored/core/games/catalog.js.map +1 -0
  47. package/lib/features/games/vendored/core/lessons/lessons.js +97 -0
  48. package/lib/features/games/vendored/core/lessons/lessons.js.map +1 -0
  49. package/lib/features/games/vendored/core/logging/events.js +24 -0
  50. package/lib/features/games/vendored/core/logging/events.js.map +1 -0
  51. package/lib/features/games/vendored/core/logging/logger.js +54 -0
  52. package/lib/features/games/vendored/core/logging/logger.js.map +1 -0
  53. package/lib/features/games/vendored/core/session/gameSession.js +317 -0
  54. package/lib/features/games/vendored/core/session/gameSession.js.map +1 -0
  55. package/lib/features/games/vendored/core/storage/worldRepository.js +192 -0
  56. package/lib/features/games/vendored/core/storage/worldRepository.js.map +1 -0
  57. package/lib/features/games/vendored/core/store/reactive.js +78 -0
  58. package/lib/features/games/vendored/core/store/reactive.js.map +1 -0
  59. package/lib/features/games/vendored/ui/GamesRoot.js +159 -0
  60. package/lib/features/games/vendored/ui/GamesRoot.js.map +1 -0
  61. package/lib/features/games/vendored/ui/components/BlockPalette.js +64 -0
  62. package/lib/features/games/vendored/ui/components/BlockPalette.js.map +1 -0
  63. package/lib/features/games/vendored/ui/components/IsoCanvas.js +124 -0
  64. package/lib/features/games/vendored/ui/components/IsoCanvas.js.map +1 -0
  65. package/lib/features/games/vendored/ui/components/primitives.js +257 -0
  66. package/lib/features/games/vendored/ui/components/primitives.js.map +1 -0
  67. package/lib/features/games/vendored/ui/hooks/useReactiveQuery.js +3 -0
  68. package/lib/features/games/vendored/ui/hooks/useReactiveQuery.js.map +1 -0
  69. package/lib/features/games/vendored/ui/screens/ActivityScreen.js +68 -0
  70. package/lib/features/games/vendored/ui/screens/ActivityScreen.js.map +1 -0
  71. package/lib/features/games/vendored/ui/screens/BuilderScreen.js +227 -0
  72. package/lib/features/games/vendored/ui/screens/BuilderScreen.js.map +1 -0
  73. package/lib/features/games/vendored/ui/screens/ClassroomScreen.js +95 -0
  74. package/lib/features/games/vendored/ui/screens/ClassroomScreen.js.map +1 -0
  75. package/lib/features/games/vendored/ui/screens/CubeforgeScreen.js +342 -0
  76. package/lib/features/games/vendored/ui/screens/CubeforgeScreen.js.map +1 -0
  77. package/lib/features/games/vendored/ui/screens/HubScreen.js +131 -0
  78. package/lib/features/games/vendored/ui/screens/HubScreen.js.map +1 -0
  79. package/lib/features/games/vendored/ui/screens/ScreenHeader.js +51 -0
  80. package/lib/features/games/vendored/ui/screens/ScreenHeader.js.map +1 -0
  81. package/lib/features/games/vendored/ui/screens/WorldListScreen.js +134 -0
  82. package/lib/features/games/vendored/ui/screens/WorldListScreen.js.map +1 -0
  83. package/lib/features/games/vendored/ui/storage/asyncStorageAdapter.js +23 -0
  84. package/lib/features/games/vendored/ui/storage/asyncStorageAdapter.js.map +1 -0
  85. package/lib/features/games/vendored/ui/theme.js +53 -0
  86. package/lib/features/games/vendored/ui/theme.js.map +1 -0
  87. package/lib/routes.json +50 -0
  88. package/lib/screens/GamesNative/index.js +30 -0
  89. package/lib/screens/GamesNative/index.js.map +1 -0
  90. package/package.json +2 -2
@@ -0,0 +1,49 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,15 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,75 @@
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
@@ -0,0 +1 @@
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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AAK,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"}
@@ -0,0 +1,62 @@
1
+ const ITEMS = [{
2
+ key: "grass",
3
+ name: "Grass",
4
+ color: "#7cc86b",
5
+ kind: "resource",
6
+ placesBlock: 1
7
+ }, {
8
+ key: "soil",
9
+ name: "Soil",
10
+ color: "#b07a4e",
11
+ kind: "resource",
12
+ placesBlock: 2
13
+ }, {
14
+ key: "stone",
15
+ name: "Stone",
16
+ color: "#b9bdc6",
17
+ kind: "resource",
18
+ placesBlock: 3
19
+ }, {
20
+ key: "wood",
21
+ name: "Wood",
22
+ color: "#d6a86a",
23
+ kind: "resource",
24
+ placesBlock: 4
25
+ }, {
26
+ key: "sand",
27
+ name: "Sand",
28
+ color: "#ead9a0",
29
+ kind: "resource",
30
+ placesBlock: 6
31
+ }, {
32
+ key: "brick",
33
+ name: "Bricks",
34
+ color: "#d1684f",
35
+ kind: "crafted",
36
+ placesBlock: 7
37
+ }, {
38
+ key: "glass",
39
+ name: "Glass",
40
+ color: "#bfe9ef",
41
+ kind: "crafted",
42
+ placesBlock: 8
43
+ }, {
44
+ key: "torch",
45
+ name: "Torch",
46
+ color: "#f2c14e",
47
+ kind: "tool"
48
+ }, {
49
+ key: "workbench",
50
+ name: "Workbench",
51
+ color: "#8a6d3b",
52
+ kind: "tool"
53
+ }];
54
+ const BY_KEY = new Map(ITEMS.map((i) => [i.key, i]));
55
+ const BY_BLOCK = /* @__PURE__ */ new Map();
56
+ for (const i of ITEMS) if (i.placesBlock != null) BY_BLOCK.set(i.placesBlock, i);
57
+ function itemByKey(key) {
58
+ return BY_KEY.get(key);
59
+ }
60
+ function itemForBlock(block) {
61
+ return BY_BLOCK.get(block);
62
+ }export{ITEMS,itemByKey,itemForBlock};//# sourceMappingURL=items.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"items.js","sources":["../../../../../../src/features/games/vendored/core/cubeforge/items.ts"],"sourcesContent":["/**\n * Cubeforge item registry.\n *\n * Cubeforge is an original survival/crafting sandbox. Items are what the player\n * gathers, crafts, and places. Placeable items carry a `placesBlock` id from the\n * shared voxel palette so the existing isometric renderer draws them with no new\n * art. Tools have no block - they are crafted goods the player keeps.\n *\n * Original work. Nothing here is ported or copied from any third-party game.\n */\n\nimport type { BlockId } from '../engine/palette';\n\nexport type ItemKind = 'resource' | 'crafted' | 'tool';\n\nexport interface CubeItem {\n /** Stable key used in saves and inventory. */\n readonly key: string;\n readonly name: string;\n /** Chip colour in the UI (taken from the matching block's top face). */\n readonly color: string;\n readonly kind: ItemKind;\n /** When present, the item can be placed into the world as this block. */\n readonly placesBlock?: BlockId;\n}\n\n/**\n * The item catalogue. Resources are gathered from the generated world; crafted\n * items come from recipes; tools are crafted goods with no placed block.\n */\nexport const ITEMS: readonly CubeItem[] = [\n { key: 'grass', name: 'Grass', color: '#7cc86b', kind: 'resource', placesBlock: 1 },\n { key: 'soil', name: 'Soil', color: '#b07a4e', kind: 'resource', placesBlock: 2 },\n { key: 'stone', name: 'Stone', color: '#b9bdc6', kind: 'resource', placesBlock: 3 },\n { key: 'wood', name: 'Wood', color: '#d6a86a', kind: 'resource', placesBlock: 4 },\n { key: 'sand', name: 'Sand', color: '#ead9a0', kind: 'resource', placesBlock: 6 },\n { key: 'brick', name: 'Bricks', color: '#d1684f', kind: 'crafted', placesBlock: 7 },\n { key: 'glass', name: 'Glass', color: '#bfe9ef', kind: 'crafted', placesBlock: 8 },\n { key: 'torch', name: 'Torch', color: '#f2c14e', kind: 'tool' },\n { key: 'workbench', name: 'Workbench', color: '#8a6d3b', kind: 'tool' },\n];\n\nconst BY_KEY = new Map<string, CubeItem>(ITEMS.map((i) => [i.key, i]));\nconst BY_BLOCK = new Map<BlockId, CubeItem>();\nfor (const i of ITEMS) if (i.placesBlock != null) BY_BLOCK.set(i.placesBlock, i);\n\nexport function itemByKey(key: string): CubeItem | undefined {\n return BY_KEY.get(key);\n}\n\n/** The item a placed block yields when gathered, if any. */\nexport function itemForBlock(block: BlockId): CubeItem | undefined {\n return BY_BLOCK.get(block);\n}\n\nexport function isPlaceable(item: CubeItem): boolean {\n return item.placesBlock != null;\n}\n\n/** Items that can be placed into the world, in catalogue order. */\nexport function placeableItems(): CubeItem[] {\n return ITEMS.filter(isPlaceable);\n}\n"],"names":[],"mappings":"AA4BO,MAAM,QAA6B,CAAC;AAAA,EACzC,GAAK,EAAA,OAAA;AAAA,EACL,IAAM,EAAA,OAAA;AAAA,EACN,KAAO,EAAA,SAAA;AAAA,EACP,IAAM,EAAA,UAAA;AAAA,EACN,WAAa,EAAA;AACf,CAAG,EAAA;AAAA,EACD,GAAK,EAAA,MAAA;AAAA,EACL,IAAM,EAAA,MAAA;AAAA,EACN,KAAO,EAAA,SAAA;AAAA,EACP,IAAM,EAAA,UAAA;AAAA,EACN,WAAa,EAAA;AACf,CAAG,EAAA;AAAA,EACD,GAAK,EAAA,OAAA;AAAA,EACL,IAAM,EAAA,OAAA;AAAA,EACN,KAAO,EAAA,SAAA;AAAA,EACP,IAAM,EAAA,UAAA;AAAA,EACN,WAAa,EAAA;AACf,CAAG,EAAA;AAAA,EACD,GAAK,EAAA,MAAA;AAAA,EACL,IAAM,EAAA,MAAA;AAAA,EACN,KAAO,EAAA,SAAA;AAAA,EACP,IAAM,EAAA,UAAA;AAAA,EACN,WAAa,EAAA;AACf,CAAG,EAAA;AAAA,EACD,GAAK,EAAA,MAAA;AAAA,EACL,IAAM,EAAA,MAAA;AAAA,EACN,KAAO,EAAA,SAAA;AAAA,EACP,IAAM,EAAA,UAAA;AAAA,EACN,WAAa,EAAA;AACf,CAAG,EAAA;AAAA,EACD,GAAK,EAAA,OAAA;AAAA,EACL,IAAM,EAAA,QAAA;AAAA,EACN,KAAO,EAAA,SAAA;AAAA,EACP,IAAM,EAAA,SAAA;AAAA,EACN,WAAa,EAAA;AACf,CAAG,EAAA;AAAA,EACD,GAAK,EAAA,OAAA;AAAA,EACL,IAAM,EAAA,OAAA;AAAA,EACN,KAAO,EAAA,SAAA;AAAA,EACP,IAAM,EAAA,SAAA;AAAA,EACN,WAAa,EAAA;AACf,CAAG,EAAA;AAAA,EACD,GAAK,EAAA,OAAA;AAAA,EACL,IAAM,EAAA,OAAA;AAAA,EACN,KAAO,EAAA,SAAA;AAAA,EACP,IAAM,EAAA;AACR,CAAG,EAAA;AAAA,EACD,GAAK,EAAA,WAAA;AAAA,EACL,IAAM,EAAA,WAAA;AAAA,EACN,KAAO,EAAA,SAAA;AAAA,EACP,IAAM,EAAA;AACR,CAAC;AACD,MAAM,MAAA,GAAS,IAAI,GAAA,CAAsB,KAAM,CAAA,GAAA,CAAI,CAAK,CAAA,KAAA,CAAC,CAAE,CAAA,GAAA,EAAK,CAAC,CAAC,CAAC,CAAA;AACnE,MAAM,QAAA,uBAAe,GAAuB,EAAA;AAC5C,KAAW,MAAA,CAAA,IAAK,KAAO,EAAA,IAAI,CAAE,CAAA,WAAA,IAAe,MAAe,QAAA,CAAA,GAAA,CAAI,CAAE,CAAA,WAAA,EAAa,CAAC,CAAA;AACxE,SAAS,UAAU,GAAmC,EAAA;AAC3D,EAAO,OAAA,MAAA,CAAO,IAAI,GAAG,CAAA;AACvB;AAGO,SAAS,aAAa,KAAsC,EAAA;AACjE,EAAO,OAAA,QAAA,CAAS,IAAI,KAAK,CAAA;AAC3B"}
@@ -0,0 +1,4 @@
1
+ function nativeWorldKey(orgName) {
2
+ const key = (orgName || "default").toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "");
3
+ return key || "default";
4
+ }export{nativeWorldKey};//# sourceMappingURL=nativeWorld.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nativeWorld.js","sources":["../../../../../../src/features/games/vendored/core/cubeforge/nativeWorld.ts"],"sourcesContent":["/**\n * Helpers for hosts that run Cubeforge in a native 3D engine (see\n * `native/cubeforge`). The 3D world keeps its own save; these keep its identity\n * stable and safe to use in a file name.\n */\n\n/** A file-name-safe key for an org's native 3D world (`[a-z0-9_-]+`). */\nexport function nativeWorldKey(orgName: string): string {\n const key = (orgName || 'default')\n .toLowerCase()\n .replace(/[^a-z0-9_-]+/g, '-')\n .replace(/^-+|-+$/g, '');\n return key || 'default';\n}\n"],"names":[],"mappings":"AAOO,SAAS,eAAe,OAAyB,EAAA;AACtD,EAAM,MAAA,GAAA,GAAA,CAAO,OAAW,IAAA,SAAA,EAAW,WAAY,EAAA,CAAE,OAAQ,CAAA,eAAA,EAAiB,GAAG,CAAA,CAAE,OAAQ,CAAA,UAAA,EAAY,EAAE,CAAA;AACrG,EAAA,OAAO,GAAO,IAAA,SAAA;AAChB"}
@@ -0,0 +1,52 @@
1
+ const RECIPES = [{
2
+ id: "bricks",
3
+ name: "Bricks",
4
+ inputs: [{
5
+ item: "soil",
6
+ qty: 2
7
+ }],
8
+ output: {
9
+ item: "brick",
10
+ qty: 1
11
+ }
12
+ }, {
13
+ id: "glass",
14
+ name: "Glass",
15
+ inputs: [{
16
+ item: "sand",
17
+ qty: 2
18
+ }],
19
+ output: {
20
+ item: "glass",
21
+ qty: 1
22
+ }
23
+ }, {
24
+ id: "torch",
25
+ name: "Torch",
26
+ inputs: [{
27
+ item: "wood",
28
+ qty: 1
29
+ }, {
30
+ item: "stone",
31
+ qty: 1
32
+ }],
33
+ output: {
34
+ item: "torch",
35
+ qty: 1
36
+ }
37
+ }, {
38
+ id: "workbench",
39
+ name: "Workbench",
40
+ inputs: [{
41
+ item: "wood",
42
+ qty: 3
43
+ }],
44
+ output: {
45
+ item: "workbench",
46
+ qty: 1
47
+ }
48
+ }];
49
+ const BY_ID = new Map(RECIPES.map((r) => [r.id, r]));
50
+ function recipeById(id) {
51
+ return BY_ID.get(id);
52
+ }export{RECIPES,recipeById};//# sourceMappingURL=recipes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recipes.js","sources":["../../../../../../src/features/games/vendored/core/cubeforge/recipes.ts"],"sourcesContent":["/**\n * Cubeforge crafting recipes.\n *\n * A recipe turns a set of input items into one output item. Recipes are pure\n * data; the session checks affordability against the inventory and applies them.\n * Original design - small, readable, and classroom-friendly.\n */\n\nexport interface RecipeCost {\n readonly item: string;\n readonly qty: number;\n}\n\nexport interface Recipe {\n readonly id: string;\n readonly name: string;\n readonly inputs: readonly RecipeCost[];\n readonly output: RecipeCost;\n}\n\nexport const RECIPES: readonly Recipe[] = [\n { id: 'bricks', name: 'Bricks', inputs: [{ item: 'soil', qty: 2 }], output: { item: 'brick', qty: 1 } },\n { id: 'glass', name: 'Glass', inputs: [{ item: 'sand', qty: 2 }], output: { item: 'glass', qty: 1 } },\n {\n id: 'torch',\n name: 'Torch',\n inputs: [\n { item: 'wood', qty: 1 },\n { item: 'stone', qty: 1 },\n ],\n output: { item: 'torch', qty: 1 },\n },\n { id: 'workbench', name: 'Workbench', inputs: [{ item: 'wood', qty: 3 }], output: { item: 'workbench', qty: 1 } },\n];\n\nconst BY_ID = new Map<string, Recipe>(RECIPES.map((r) => [r.id, r]));\n\nexport function recipeById(id: string): Recipe | undefined {\n return BY_ID.get(id);\n}\n\n/** Sum a recipe's inputs by item key (handles repeated items defensively). */\nexport function totalCost(recipe: Recipe): Map<string, number> {\n const need = new Map<string, number>();\n for (const c of recipe.inputs) need.set(c.item, (need.get(c.item) ?? 0) + c.qty);\n return need;\n}\n"],"names":[],"mappings":"AAkBO,MAAM,UAA6B,CAAC;AAAA,EACzC,EAAI,EAAA,QAAA;AAAA,EACJ,IAAM,EAAA,QAAA;AAAA,EACN,QAAQ,CAAC;AAAA,IACP,IAAM,EAAA,MAAA;AAAA,IACN,GAAK,EAAA;AAAA,GACN,CAAA;AAAA,EACD,MAAQ,EAAA;AAAA,IACN,IAAM,EAAA,OAAA;AAAA,IACN,GAAK,EAAA;AAAA;AAET,CAAG,EAAA;AAAA,EACD,EAAI,EAAA,OAAA;AAAA,EACJ,IAAM,EAAA,OAAA;AAAA,EACN,QAAQ,CAAC;AAAA,IACP,IAAM,EAAA,MAAA;AAAA,IACN,GAAK,EAAA;AAAA,GACN,CAAA;AAAA,EACD,MAAQ,EAAA;AAAA,IACN,IAAM,EAAA,OAAA;AAAA,IACN,GAAK,EAAA;AAAA;AAET,CAAG,EAAA;AAAA,EACD,EAAI,EAAA,OAAA;AAAA,EACJ,IAAM,EAAA,OAAA;AAAA,EACN,QAAQ,CAAC;AAAA,IACP,IAAM,EAAA,MAAA;AAAA,IACN,GAAK,EAAA;AAAA,GACJ,EAAA;AAAA,IACD,IAAM,EAAA,OAAA;AAAA,IACN,GAAK,EAAA;AAAA,GACN,CAAA;AAAA,EACD,MAAQ,EAAA;AAAA,IACN,IAAM,EAAA,OAAA;AAAA,IACN,GAAK,EAAA;AAAA;AAET,CAAG,EAAA;AAAA,EACD,EAAI,EAAA,WAAA;AAAA,EACJ,IAAM,EAAA,WAAA;AAAA,EACN,QAAQ,CAAC;AAAA,IACP,IAAM,EAAA,MAAA;AAAA,IACN,GAAK,EAAA;AAAA,GACN,CAAA;AAAA,EACD,MAAQ,EAAA;AAAA,IACN,IAAM,EAAA,WAAA;AAAA,IACN,GAAK,EAAA;AAAA;AAET,CAAC;AACD,MAAM,KAAA,GAAQ,IAAI,GAAA,CAAoB,OAAQ,CAAA,GAAA,CAAI,CAAK,CAAA,KAAA,CAAC,CAAE,CAAA,EAAA,EAAI,CAAC,CAAC,CAAC,CAAA;AAC1D,SAAS,WAAW,EAAgC,EAAA;AACzD,EAAO,OAAA,KAAA,CAAM,IAAI,EAAE,CAAA;AACrB"}
@@ -0,0 +1,92 @@
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
@@ -0,0 +1 @@
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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AACT;AAGA,SAAS,YAAY,KAA6C,EAAA;AAChE,EAAA,IAAI,CAAC,KAAA,IAAS,OAAO,KAAA,KAAU,UAAiB,OAAA,MAAA;AAChD,EAAA,MAAM,CAAI,GAAA,KAAA;AACV,EAAA,MAAM,SAAS,CAAE,CAAA,MAAA;AACjB,EAAI,IAAA,CAAC,UAAU,OAAO,MAAA,CAAO,MAAM,QAAY,IAAA,OAAO,OAAO,CAAM,KAAA,QAAA,IAAY,OAAO,MAAO,CAAA,CAAA,KAAM,YAAY,CAAC,CAAA,CAAE,UAAU,OAAO,CAAA,CAAE,WAAW,QAAU,EAAA;AACxJ,IAAO,OAAA,MAAA;AAAA;AAET,EAAA,MAAM,SAAiC,EAAC;AACxC,EAAW,KAAA,MAAA,CAAC,KAAK,EAAE,CAAA,IAAK,OAAO,OAAQ,CAAA,CAAA,CAAE,MAAiC,CAAG,EAAA;AAC3E,IAAA,IAAI,OAAO,EAAA,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"}
@@ -0,0 +1,154 @@
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
@@ -0,0 +1 @@
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 != null && this.inventory.has(selected, 1),\n recipes: RECIPES.map((recipe) => ({ recipe, canCraft: this.inventory.canAfford(recipe.inputs) })),\n };\n }\n}\n"],"names":[],"mappings":";;;AAuDO,MAAM,gBAAiB,CAAA;AAAA,EAQ5B,WAAA,CAAY,IAAsB,GAAA,EAAI,EAAA;AAPtC,IAAQ,aAAA,CAAA,IAAA,EAAA,OAAA,CAAA;AACR,IAAiB,aAAA,CAAA,IAAA,EAAA,WAAA,CAAA;AACjB,IAAQ,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA;AACR,IAAQ,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AACR,IAAQ,aAAA,CAAA,IAAA,EAAA,cAAA,CAAA;AACR,IAAiB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AACjB,IAAiB,aAAA,CAAA,IAAA,EAAA,OAAA,CAAA;AA9DnB,IAAA,IA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