@crowdedkingdoms/crowdyjs 8.2.0 → 8.3.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 (102) hide show
  1. package/README.md +21 -3
  2. package/dist/crowdy-client.d.ts.map +1 -1
  3. package/dist/crowdy-client.js +5 -1
  4. package/dist/index.d.ts +2 -2
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +2 -2
  7. package/dist/kit/blueprints/combat.d.ts +75 -0
  8. package/dist/kit/blueprints/combat.d.ts.map +1 -0
  9. package/dist/kit/blueprints/combat.js +351 -0
  10. package/dist/kit/blueprints/core.d.ts +222 -0
  11. package/dist/kit/blueprints/core.d.ts.map +1 -0
  12. package/dist/kit/blueprints/core.js +185 -0
  13. package/dist/kit/blueprints/decks.d.ts +50 -0
  14. package/dist/kit/blueprints/decks.d.ts.map +1 -0
  15. package/dist/kit/blueprints/decks.js +163 -0
  16. package/dist/kit/blueprints/economy.d.ts +88 -0
  17. package/dist/kit/blueprints/economy.d.ts.map +1 -0
  18. package/dist/kit/blueprints/economy.js +533 -0
  19. package/dist/kit/blueprints/guild.d.ts +51 -0
  20. package/dist/kit/blueprints/guild.d.ts.map +1 -0
  21. package/dist/kit/blueprints/guild.js +50 -0
  22. package/dist/kit/blueprints/index.d.ts +21 -0
  23. package/dist/kit/blueprints/index.d.ts.map +1 -0
  24. package/dist/kit/blueprints/index.js +20 -0
  25. package/dist/kit/blueprints/inventory.d.ts +38 -0
  26. package/dist/kit/blueprints/inventory.d.ts.map +1 -0
  27. package/dist/kit/blueprints/inventory.js +157 -0
  28. package/dist/kit/blueprints/leaderboards.d.ts +49 -0
  29. package/dist/kit/blueprints/leaderboards.d.ts.map +1 -0
  30. package/dist/kit/blueprints/leaderboards.js +126 -0
  31. package/dist/kit/blueprints/locks.d.ts +82 -0
  32. package/dist/kit/blueprints/locks.d.ts.map +1 -0
  33. package/dist/kit/blueprints/locks.js +155 -0
  34. package/dist/kit/blueprints/loot.d.ts +84 -0
  35. package/dist/kit/blueprints/loot.d.ts.map +1 -0
  36. package/dist/kit/blueprints/loot.js +228 -0
  37. package/dist/kit/blueprints/matches.d.ts +59 -0
  38. package/dist/kit/blueprints/matches.d.ts.map +1 -0
  39. package/dist/kit/blueprints/matches.js +246 -0
  40. package/dist/kit/blueprints/npcs.d.ts +71 -0
  41. package/dist/kit/blueprints/npcs.d.ts.map +1 -0
  42. package/dist/kit/blueprints/npcs.js +122 -0
  43. package/dist/kit/blueprints/plots.d.ts +54 -0
  44. package/dist/kit/blueprints/plots.d.ts.map +1 -0
  45. package/dist/kit/blueprints/plots.js +146 -0
  46. package/dist/kit/blueprints/progression.d.ts +68 -0
  47. package/dist/kit/blueprints/progression.d.ts.map +1 -0
  48. package/dist/kit/blueprints/progression.js +324 -0
  49. package/dist/kit/blueprints/quests.d.ts +65 -0
  50. package/dist/kit/blueprints/quests.d.ts.map +1 -0
  51. package/dist/kit/blueprints/quests.js +284 -0
  52. package/dist/kit/blueprints/worldsim.d.ts +84 -0
  53. package/dist/kit/blueprints/worldsim.d.ts.map +1 -0
  54. package/dist/kit/blueprints/worldsim.js +461 -0
  55. package/dist/kit/combat.d.ts +103 -0
  56. package/dist/kit/combat.d.ts.map +1 -0
  57. package/dist/kit/combat.js +151 -0
  58. package/dist/kit/decks.d.ts +123 -0
  59. package/dist/kit/decks.d.ts.map +1 -0
  60. package/dist/kit/decks.js +138 -0
  61. package/dist/kit/economy.d.ts +244 -0
  62. package/dist/kit/economy.d.ts.map +1 -0
  63. package/dist/kit/economy.js +365 -0
  64. package/dist/kit/features.d.ts +60 -0
  65. package/dist/kit/features.d.ts.map +1 -0
  66. package/dist/kit/features.js +65 -0
  67. package/dist/kit/index.d.ts +13 -2
  68. package/dist/kit/index.d.ts.map +1 -1
  69. package/dist/kit/index.js +12 -1
  70. package/dist/kit/inventory.d.ts +5 -0
  71. package/dist/kit/inventory.d.ts.map +1 -1
  72. package/dist/kit/inventory.js +14 -1
  73. package/dist/kit/kit.d.ts +58 -2
  74. package/dist/kit/kit.d.ts.map +1 -1
  75. package/dist/kit/kit.js +24 -2
  76. package/dist/kit/leaderboards.d.ts +66 -0
  77. package/dist/kit/leaderboards.d.ts.map +1 -0
  78. package/dist/kit/leaderboards.js +94 -0
  79. package/dist/kit/loot.d.ts +106 -0
  80. package/dist/kit/loot.d.ts.map +1 -0
  81. package/dist/kit/loot.js +120 -0
  82. package/dist/kit/matches.d.ts +140 -0
  83. package/dist/kit/matches.d.ts.map +1 -0
  84. package/dist/kit/matches.js +253 -0
  85. package/dist/kit/objects.js +1 -1
  86. package/dist/kit/plots.js +1 -1
  87. package/dist/kit/progression.d.ts +181 -0
  88. package/dist/kit/progression.d.ts.map +1 -0
  89. package/dist/kit/progression.js +265 -0
  90. package/dist/kit/quests.d.ts +110 -0
  91. package/dist/kit/quests.d.ts.map +1 -0
  92. package/dist/kit/quests.js +158 -0
  93. package/dist/kit/social.d.ts +267 -0
  94. package/dist/kit/social.d.ts.map +1 -0
  95. package/dist/kit/social.js +230 -0
  96. package/dist/kit/worldsim.d.ts +225 -0
  97. package/dist/kit/worldsim.d.ts.map +1 -0
  98. package/dist/kit/worldsim.js +231 -0
  99. package/package.json +1 -1
  100. package/dist/kit/blueprints.d.ts +0 -370
  101. package/dist/kit/blueprints.d.ts.map +0 -1
  102. package/dist/kit/blueprints.js +0 -643
@@ -0,0 +1,50 @@
1
+ import { composeBlueprints } from './core.js';
2
+ import { inventoryBlueprint, inventoryNames } from './inventory.js';
3
+ import { lockBlueprint, lockNames } from './locks.js';
4
+ /** Compute the type/function names a guild blueprint (and kit.social.guild) uses. */
5
+ export function guildNames(typePrefix = 'Guild') {
6
+ const locks = lockNames(`${typePrefix}Hall`);
7
+ const bank = inventoryNames(`${typePrefix}Bank`);
8
+ return {
9
+ hallType: locks.objectType,
10
+ openHallFn: locks.openFn,
11
+ closeHallFn: locks.closeFn,
12
+ bankTypePrefix: `${typePrefix}Bank`,
13
+ bankInventoryType: bank.inventoryType,
14
+ bankStackType: bank.stackType,
15
+ };
16
+ }
17
+ /**
18
+ * Composite blueprint for a **guild's shared assets** — a demonstration of
19
+ * blueprint composition: a `GuildHall` lockable whose open/close is gated on
20
+ * membership of the guild team (`group_permission`), plus a prefixed
21
+ * guild-bank inventory (`GuildBankInventory` / `GuildBankItemStack`) for
22
+ * shared storage. The guild itself is a **team** (`kit.social.guild`), its
23
+ * chat a **channel**, and its territory a grid group-grant
24
+ * (`kit.social.guild.claimTerritory`) — no new model surface needed for
25
+ * those.
26
+ *
27
+ * Runtime counterparts: `client.kit(appId).social.guild` (team/chat/territory),
28
+ * `kit.objectsFor(guildNames().hallType)` (the hall), and
29
+ * `client.kit(appId, { inventory: { typePrefix: guildNames().bankTypePrefix } })
30
+ * .inventory` (the bank).
31
+ */
32
+ export function guildBlueprint(options) {
33
+ const { typePrefix = 'Guild', guildGroupId, hallPermission, bank = true } = options;
34
+ if (!guildGroupId) {
35
+ throw new Error('guildBlueprint requires guildGroupId — create the guild team first, then deploy');
36
+ }
37
+ const hall = lockBlueprint({
38
+ objectTypeName: `${typePrefix}Hall`,
39
+ authority: {
40
+ kind: 'groupPermission',
41
+ groupId: guildGroupId,
42
+ ...(hallPermission !== undefined ? { permission: hallPermission } : {}),
43
+ },
44
+ });
45
+ const blueprints = [hall];
46
+ if (bank) {
47
+ blueprints.push(inventoryBlueprint({ typePrefix: `${typePrefix}Bank` }));
48
+ }
49
+ return composeBlueprints(typePrefix.toLowerCase(), blueprints);
50
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Blueprint builders for the Game Kit, one module per game concept, re-exported
3
+ * here as a stable barrel (import paths from `kit/index.js` and the package
4
+ * root are unchanged as builders are added).
5
+ */
6
+ export { andPolicies, composeBlueprints, featureGate, kitPolicyJson, mergeBlueprints, ownerEquals, ownerEqualsCaller, ownerMirrorProperty, toSnakeCase, trustedAuthorityFields, type KitAutomationSpec, type KitAutomationTriggerSpec, type KitBlueprint, type KitInvokePolicy, type KitOwnerIdKind, type KitSelectorSpec, type KitTrustedAuthority, type MergedBlueprints, type SelectorPermissionPredicate, } from './core.js';
7
+ export { combatBlueprint, combatNames, type CombatBlueprintOptions, type CombatNames, } from './combat.js';
8
+ export { decksBlueprint, decksNames, type DecksBlueprintOptions, type DecksNames, } from './decks.js';
9
+ export { economyBlueprint, economyCurrencyFn, economyNames, type EconomyBlueprintOptions, type EconomyNames, } from './economy.js';
10
+ export { guildBlueprint, guildNames, type GuildBlueprintOptions, type GuildNames, } from './guild.js';
11
+ export { inventoryBlueprint, inventoryNames, type InventoryBlueprintOptions, type InventoryNames, } from './inventory.js';
12
+ export { leaderboardsBlueprint, leaderboardsNames, type LeaderboardsBlueprintOptions, type LeaderboardsNames, } from './leaderboards.js';
13
+ export { lootBlueprint, lootNames, lootRollFn, type LootBlueprintOptions, type LootDropSpec, type LootEntrySpec, type LootNames, type LootTableSpec, } from './loot.js';
14
+ export { lockBlueprint, lockNames, type LockAuthority, type LockBlueprintOptions, type LockNames, } from './locks.js';
15
+ export { questsBlueprint, questsNames, type QuestAdvanceSpec, type QuestsBlueprintOptions, type QuestsNames, } from './quests.js';
16
+ export { progressionBlueprint, progressionNames, type ProgressionBlueprintOptions, type ProgressionNames, } from './progression.js';
17
+ export { plotBlueprint, plotNames, type PlotBlueprintOptions, type PlotNames, } from './plots.js';
18
+ export { matchesBlueprint, matchesNames, type MatchesBlueprintOptions, type MatchesNames, } from './matches.js';
19
+ export { npcBehaviorFunctionName, npcBlueprint, type NpcBehaviorSpec, type NpcBehaviorTrigger, type NpcBlueprintOptions, } from './npcs.js';
20
+ export { worldsimBlueprint, worldsimNames, type WorldsimBlueprintOptions, type WorldsimNames, } from './worldsim.js';
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/kit/blueprints/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,sBAAsB,EACtB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,2BAA2B,GACjC,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,eAAe,EACf,WAAW,EACX,KAAK,sBAAsB,EAC3B,KAAK,WAAW,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,cAAc,EACd,UAAU,EACV,KAAK,qBAAqB,EAC1B,KAAK,UAAU,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,KAAK,uBAAuB,EAC5B,KAAK,YAAY,GAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,cAAc,EACd,UAAU,EACV,KAAK,qBAAqB,EAC1B,KAAK,UAAU,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,KAAK,yBAAyB,EAC9B,KAAK,cAAc,GACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,KAAK,4BAA4B,EACjC,KAAK,iBAAiB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,aAAa,EACb,SAAS,EACT,UAAU,EACV,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,aAAa,GACnB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,aAAa,EACb,SAAS,EACT,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,SAAS,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,eAAe,EACf,WAAW,EACX,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,WAAW,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,KAAK,2BAA2B,EAChC,KAAK,gBAAgB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,aAAa,EACb,SAAS,EACT,KAAK,oBAAoB,EACzB,KAAK,SAAS,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,KAAK,uBAAuB,EAC5B,KAAK,YAAY,GAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,uBAAuB,EACvB,YAAY,EACZ,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,GACzB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,KAAK,wBAAwB,EAC7B,KAAK,aAAa,GACnB,MAAM,eAAe,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Blueprint builders for the Game Kit, one module per game concept, re-exported
3
+ * here as a stable barrel (import paths from `kit/index.js` and the package
4
+ * root are unchanged as builders are added).
5
+ */
6
+ export { andPolicies, composeBlueprints, featureGate, kitPolicyJson, mergeBlueprints, ownerEquals, ownerEqualsCaller, ownerMirrorProperty, toSnakeCase, trustedAuthorityFields, } from './core.js';
7
+ export { combatBlueprint, combatNames, } from './combat.js';
8
+ export { decksBlueprint, decksNames, } from './decks.js';
9
+ export { economyBlueprint, economyCurrencyFn, economyNames, } from './economy.js';
10
+ export { guildBlueprint, guildNames, } from './guild.js';
11
+ export { inventoryBlueprint, inventoryNames, } from './inventory.js';
12
+ export { leaderboardsBlueprint, leaderboardsNames, } from './leaderboards.js';
13
+ export { lootBlueprint, lootNames, lootRollFn, } from './loot.js';
14
+ export { lockBlueprint, lockNames, } from './locks.js';
15
+ export { questsBlueprint, questsNames, } from './quests.js';
16
+ export { progressionBlueprint, progressionNames, } from './progression.js';
17
+ export { plotBlueprint, plotNames, } from './plots.js';
18
+ export { matchesBlueprint, matchesNames, } from './matches.js';
19
+ export { npcBehaviorFunctionName, npcBlueprint, } from './npcs.js';
20
+ export { worldsimBlueprint, worldsimNames, } from './worldsim.js';
@@ -0,0 +1,38 @@
1
+ import { type KitBlueprint } from './core.js';
2
+ /** Options for {@link inventoryBlueprint}. */
3
+ export interface InventoryBlueprintOptions {
4
+ /**
5
+ * Prefix applied to the container type names (e.g. `'Bank'` →
6
+ * `BankInventory` / `BankItemStack`) and, snake-cased, to the function
7
+ * names (`bank_grant_stack`, …). Lets several independent inventory systems
8
+ * coexist in one app. Defaults to none.
9
+ */
10
+ typePrefix?: string;
11
+ /** Default `max_slots` on new inventories. Defaults to 24. */
12
+ maxSlots?: number;
13
+ /** Exclusive upper bound for stack `slot` indexes. Defaults to 64. */
14
+ slotCount?: number;
15
+ }
16
+ /** Names derived by {@link inventoryBlueprint} for a given prefix. */
17
+ export interface InventoryNames {
18
+ inventoryType: string;
19
+ stackType: string;
20
+ grantFn: string;
21
+ consumeFn: string;
22
+ moveFn: string;
23
+ transferFn: string;
24
+ containsEdge: string;
25
+ }
26
+ /** Compute the type/function names an inventory blueprint (and its runtime helper) uses. */
27
+ export declare function inventoryNames(typePrefix?: string): InventoryNames;
28
+ /**
29
+ * Blueprint for a server-authoritative **inventory**: a per-player
30
+ * `Inventory` container plus `ItemStack` containers (`item_id`, `quantity`,
31
+ * `slot`), and owner-gated functions to grant, consume, move, and transfer
32
+ * stacks. Quantity guards live in the invoke policies, so an untrusted client
33
+ * can never overdraw or touch another player's items.
34
+ *
35
+ * Runtime counterpart: `client.kit(appId).inventory`.
36
+ */
37
+ export declare function inventoryBlueprint(options?: InventoryBlueprintOptions): KitBlueprint;
38
+ //# sourceMappingURL=inventory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inventory.d.ts","sourceRoot":"","sources":["../../../src/kit/blueprints/inventory.ts"],"names":[],"mappings":"AACA,OAAO,EAA8B,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAE1E,8CAA8C;AAC9C,MAAM,WAAW,yBAAyB;IACxC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,sEAAsE;AACtE,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,4FAA4F;AAC5F,wBAAgB,cAAc,CAAC,UAAU,SAAK,GAAG,cAAc,CAW9D;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,yBAA8B,GACtC,YAAY,CAyId"}
@@ -0,0 +1,157 @@
1
+ import { kitPolicyJson, toSnakeCase } from './core.js';
2
+ /** Compute the type/function names an inventory blueprint (and its runtime helper) uses. */
3
+ export function inventoryNames(typePrefix = '') {
4
+ const fnPrefix = typePrefix ? `${toSnakeCase(typePrefix)}_` : '';
5
+ return {
6
+ inventoryType: `${typePrefix}Inventory`,
7
+ stackType: `${typePrefix}ItemStack`,
8
+ grantFn: `${fnPrefix}grant_stack`,
9
+ consumeFn: `${fnPrefix}consume_stack`,
10
+ moveFn: `${fnPrefix}move_stack`,
11
+ transferFn: `${fnPrefix}transfer_stack`,
12
+ containsEdge: 'inventory_contains',
13
+ };
14
+ }
15
+ /**
16
+ * Blueprint for a server-authoritative **inventory**: a per-player
17
+ * `Inventory` container plus `ItemStack` containers (`item_id`, `quantity`,
18
+ * `slot`), and owner-gated functions to grant, consume, move, and transfer
19
+ * stacks. Quantity guards live in the invoke policies, so an untrusted client
20
+ * can never overdraw or touch another player's items.
21
+ *
22
+ * Runtime counterpart: `client.kit(appId).inventory`.
23
+ */
24
+ export function inventoryBlueprint(options = {}) {
25
+ const { typePrefix = '', maxSlots = 24, slotCount = 64 } = options;
26
+ const names = inventoryNames(typePrefix);
27
+ const ownerOnly = kitPolicyJson({ type: 'owner_of_self' });
28
+ return {
29
+ name: names.inventoryType,
30
+ containerTypes: [
31
+ {
32
+ typeName: names.inventoryType,
33
+ displayName: names.inventoryType,
34
+ instantiableBy: 'member',
35
+ description: 'A bag of item stacks owned by one player.',
36
+ },
37
+ {
38
+ typeName: names.stackType,
39
+ displayName: names.stackType,
40
+ instantiableBy: 'member',
41
+ description: 'One stack of a single item type in an inventory slot.',
42
+ },
43
+ ],
44
+ propertyDefinitions: [
45
+ {
46
+ containerTypeName: names.inventoryType,
47
+ key: 'max_slots',
48
+ valueType: 'int',
49
+ defaultValueJson: String(maxSlots),
50
+ },
51
+ { containerTypeName: names.stackType, key: 'item_id', valueType: 'string' },
52
+ {
53
+ containerTypeName: names.stackType,
54
+ key: 'owner_user_id',
55
+ valueType: 'int',
56
+ defaultValueJson: '0',
57
+ description: "Mirror of the stack owner's user id (kit convention), read by cross-container guards such as the economy trade/market functions.",
58
+ },
59
+ {
60
+ containerTypeName: names.stackType,
61
+ key: 'quantity',
62
+ valueType: 'int',
63
+ defaultValueJson: '0',
64
+ },
65
+ {
66
+ containerTypeName: names.stackType,
67
+ key: 'slot',
68
+ valueType: 'int',
69
+ defaultValueJson: '0',
70
+ },
71
+ ],
72
+ functions: [
73
+ {
74
+ name: names.grantFn,
75
+ containerTypeName: names.stackType,
76
+ returnType: 'int',
77
+ parameters: [{ name: 'amount', valueType: 'int', required: true }],
78
+ mutations: [
79
+ {
80
+ target: 'self',
81
+ property: 'quantity',
82
+ expression: 'self.quantity + max(0, $amount)',
83
+ },
84
+ ],
85
+ returnExpression: 'self.quantity',
86
+ invokePolicyJson: ownerOnly,
87
+ description: 'Add items to a stack the caller owns.',
88
+ },
89
+ {
90
+ name: names.consumeFn,
91
+ containerTypeName: names.stackType,
92
+ returnType: 'int',
93
+ parameters: [{ name: 'amount', valueType: 'int', required: true }],
94
+ mutations: [
95
+ { target: 'self', property: 'quantity', expression: 'self.quantity - $amount' },
96
+ ],
97
+ returnExpression: 'self.quantity',
98
+ invokePolicyJson: kitPolicyJson({
99
+ type: 'and',
100
+ rules: [
101
+ { type: 'owner_of_self' },
102
+ {
103
+ type: 'condition',
104
+ expression: '$amount > 0 && self.quantity >= $amount',
105
+ },
106
+ ],
107
+ }),
108
+ description: 'Spend items from a stack; refuses to overdraw.',
109
+ },
110
+ {
111
+ name: names.moveFn,
112
+ containerTypeName: names.stackType,
113
+ returnType: 'int',
114
+ parameters: [{ name: 'to_slot', valueType: 'int', required: true }],
115
+ mutations: [
116
+ {
117
+ target: 'self',
118
+ property: 'slot',
119
+ expression: `clamp($to_slot, 0, ${slotCount - 1})`,
120
+ },
121
+ ],
122
+ returnExpression: 'self.slot',
123
+ invokePolicyJson: ownerOnly,
124
+ description: 'Move a stack to another slot.',
125
+ },
126
+ {
127
+ name: names.transferFn,
128
+ containerTypeName: names.stackType,
129
+ returnType: 'int',
130
+ parameters: [
131
+ { name: 'to_id', valueType: 'container_ref', required: true },
132
+ { name: 'amount', valueType: 'int', required: true },
133
+ ],
134
+ mutations: [
135
+ { target: 'self', property: 'quantity', expression: 'self.quantity - $amount' },
136
+ {
137
+ target: 'ref($to_id)',
138
+ property: 'quantity',
139
+ expression: 'ref($to_id).quantity + $amount',
140
+ },
141
+ ],
142
+ returnExpression: 'self.quantity',
143
+ invokePolicyJson: kitPolicyJson({
144
+ type: 'and',
145
+ rules: [
146
+ { type: 'owner_of_self' },
147
+ {
148
+ type: 'condition',
149
+ expression: '$amount > 0 && self.quantity >= $amount && ref($to_id).item_id == self.item_id',
150
+ },
151
+ ],
152
+ }),
153
+ description: 'Atomically move items between two stacks of the same item type.',
154
+ },
155
+ ],
156
+ };
157
+ }
@@ -0,0 +1,49 @@
1
+ import { type KitBlueprint, type KitOwnerIdKind, type KitTrustedAuthority } from './core.js';
2
+ /** Options for {@link leaderboardsBlueprint}. */
3
+ export interface LeaderboardsBlueprintOptions {
4
+ /** Prefix for the type/function names. Defaults to none. */
5
+ typePrefix?: string;
6
+ /**
7
+ * Who may submit scores: `'host'` (the elected host referees; default),
8
+ * `'server'` (app admins / studio backend), or `'automation'` (e.g. an
9
+ * event automation on the match layer's `end_match`).
10
+ */
11
+ submitAuthority?: KitTrustedAuthority;
12
+ /**
13
+ * When true (default), submitting keeps the best score
14
+ * (`max(self.score, $points)`); when false, submissions overwrite.
15
+ */
16
+ keepBest?: boolean;
17
+ /**
18
+ * When set, adds a cron automation that rolls the season: bumps `season`
19
+ * and resets `score`/`rank` on EVERY entry (e.g. `'0 0 1 * *'` for
20
+ * monthly seasons).
21
+ */
22
+ seasonCron?: string;
23
+ /** Owner-mirror typing (see the kit convention). Defaults to `'int'`. */
24
+ ownerIdKind?: KitOwnerIdKind;
25
+ }
26
+ /** Names derived by {@link leaderboardsBlueprint} for a given prefix. */
27
+ export interface LeaderboardsNames {
28
+ entryType: string;
29
+ submitFn: string;
30
+ rollSeasonFn: string;
31
+ seasonAutomation: string;
32
+ }
33
+ /** Compute the type/function names a leaderboards blueprint (and its runtime helper) uses. */
34
+ export declare function leaderboardsNames(typePrefix?: string): LeaderboardsNames;
35
+ /**
36
+ * Blueprint for **leaderboards**: per-player `LeaderboardEntry` rows keyed
37
+ * by a `board_id`, written only through the trusted `submit_score`
38
+ * (host-refereed by default — configure `submitAuthority`), with optional
39
+ * cron **season rolls**.
40
+ *
41
+ * Ranking is honest about the platform: container lists have no server-side
42
+ * ORDER BY, so `kit.leaderboards.top()` fetches a board's entries and sorts
43
+ * client-side — fine for the few hundred entries a per-app board holds.
44
+ * Automation selectors' `pick: highest` covers server-side top-1 needs.
45
+ *
46
+ * Runtime counterpart: `client.kit(appId).leaderboards`.
47
+ */
48
+ export declare function leaderboardsBlueprint(options?: LeaderboardsBlueprintOptions): KitBlueprint;
49
+ //# sourceMappingURL=leaderboards.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leaderboards.d.ts","sourceRoot":"","sources":["../../../src/kit/blueprints/leaderboards.ts"],"names":[],"mappings":"AAIA,OAAO,EAML,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACzB,MAAM,WAAW,CAAC;AAEnB,iDAAiD;AACjD,MAAM,WAAW,4BAA4B;IAC3C,4DAA4D;IAC5D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,eAAe,CAAC,EAAE,mBAAmB,CAAC;IACtC;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yEAAyE;IACzE,WAAW,CAAC,EAAE,cAAc,CAAC;CAC9B;AAED,yEAAyE;AACzE,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,8FAA8F;AAC9F,wBAAgB,iBAAiB,CAAC,UAAU,SAAK,GAAG,iBAAiB,CAQpE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,GAAE,4BAAiC,GACzC,YAAY,CAiHd"}
@@ -0,0 +1,126 @@
1
+ import { kitPolicyJson, ownerMirrorProperty, toSnakeCase, trustedAuthorityFields, } from './core.js';
2
+ /** Compute the type/function names a leaderboards blueprint (and its runtime helper) uses. */
3
+ export function leaderboardsNames(typePrefix = '') {
4
+ const fnPrefix = typePrefix ? `${toSnakeCase(typePrefix)}_` : '';
5
+ return {
6
+ entryType: `${typePrefix}LeaderboardEntry`,
7
+ submitFn: `${fnPrefix}submit_score`,
8
+ rollSeasonFn: `${fnPrefix}roll_season`,
9
+ seasonAutomation: `${fnPrefix.replace(/_/g, '-')}season-roll`,
10
+ };
11
+ }
12
+ /**
13
+ * Blueprint for **leaderboards**: per-player `LeaderboardEntry` rows keyed
14
+ * by a `board_id`, written only through the trusted `submit_score`
15
+ * (host-refereed by default — configure `submitAuthority`), with optional
16
+ * cron **season rolls**.
17
+ *
18
+ * Ranking is honest about the platform: container lists have no server-side
19
+ * ORDER BY, so `kit.leaderboards.top()` fetches a board's entries and sorts
20
+ * client-side — fine for the few hundred entries a per-app board holds.
21
+ * Automation selectors' `pick: highest` covers server-side top-1 needs.
22
+ *
23
+ * Runtime counterpart: `client.kit(appId).leaderboards`.
24
+ */
25
+ export function leaderboardsBlueprint(options = {}) {
26
+ const { typePrefix = '', submitAuthority = 'host', keepBest = true, seasonCron, ownerIdKind: kind = 'int', } = options;
27
+ const names = leaderboardsNames(typePrefix);
28
+ const propertyDefinitions = [
29
+ ownerMirrorProperty(names.entryType, kind),
30
+ {
31
+ containerTypeName: names.entryType,
32
+ key: 'board_id',
33
+ valueType: 'string',
34
+ defaultValueJson: '""',
35
+ description: "Which leaderboard this entry belongs to (e.g. 'weekly_kills').",
36
+ },
37
+ {
38
+ containerTypeName: names.entryType,
39
+ key: 'score',
40
+ valueType: 'int',
41
+ defaultValueJson: '0',
42
+ description: 'The ranked score, written only through submit_score.',
43
+ },
44
+ {
45
+ containerTypeName: names.entryType,
46
+ key: 'season',
47
+ valueType: 'int',
48
+ defaultValueJson: '1',
49
+ description: 'Season counter, bumped by the season-roll automation.',
50
+ },
51
+ {
52
+ containerTypeName: names.entryType,
53
+ key: 'rank',
54
+ valueType: 'int',
55
+ defaultValueJson: '0',
56
+ description: 'Optional stamped rank (0 = unstamped; ranking is client-side by default).',
57
+ },
58
+ ];
59
+ const functions = [
60
+ {
61
+ name: names.submitFn,
62
+ containerTypeName: names.entryType,
63
+ returnType: 'int',
64
+ parameters: [
65
+ {
66
+ name: 'points',
67
+ valueType: 'int',
68
+ required: true,
69
+ description: 'The score to submit.',
70
+ },
71
+ ],
72
+ mutations: [
73
+ {
74
+ target: 'self',
75
+ property: 'score',
76
+ expression: keepBest ? 'max(self.score, $points)' : '$points',
77
+ },
78
+ ],
79
+ returnExpression: 'self.score',
80
+ ...trustedAuthorityFields(submitAuthority),
81
+ description: `Trusted score submission (${keepBest ? 'keeps the best score' : 'overwrites'}); never a plain player call.`,
82
+ },
83
+ ];
84
+ const automations = [];
85
+ if (seasonCron !== undefined) {
86
+ functions.push({
87
+ name: names.rollSeasonFn,
88
+ containerTypeName: names.entryType,
89
+ returnType: 'int',
90
+ mutations: [
91
+ { target: 'self', property: 'season', expression: 'self.season + 1' },
92
+ { target: 'self', property: 'score', expression: '0' },
93
+ { target: 'self', property: 'rank', expression: '0' },
94
+ ],
95
+ returnExpression: 'self.season',
96
+ invokePolicyJson: kitPolicyJson({ type: 'is_automation' }),
97
+ autonomousInvocable: true,
98
+ description: 'Season roll (automation-only): bumps the season and resets scores.',
99
+ });
100
+ automations.push({
101
+ name: names.seasonAutomation,
102
+ functionName: names.rollSeasonFn,
103
+ targetMode: 'type',
104
+ targetTypeName: names.entryType,
105
+ triggerType: 'schedule',
106
+ scheduleKind: 'cron',
107
+ cronExpr: seasonCron,
108
+ maxTargets: 500,
109
+ description: 'Rolls every leaderboard entry into the next season on the cron.',
110
+ });
111
+ }
112
+ return {
113
+ name: names.entryType,
114
+ containerTypes: [
115
+ {
116
+ typeName: names.entryType,
117
+ displayName: names.entryType,
118
+ instantiableBy: 'member',
119
+ description: "One player's entry on one leaderboard (score writable only via submit_score).",
120
+ },
121
+ ],
122
+ propertyDefinitions,
123
+ functions,
124
+ ...(automations.length ? { automations } : {}),
125
+ };
126
+ }
@@ -0,0 +1,82 @@
1
+ import { type KitBlueprint, type KitInvokePolicy } from './core.js';
2
+ /**
3
+ * The authority source that may operate a lockable object. Several may be
4
+ * combined (any one grants access — they are OR'd):
5
+ *
6
+ * - `owner` — only the container's owner (`owner_of_self`); "only the owner
7
+ * of this chest can open it".
8
+ * - `key` — the caller must own a matching key item; "if a player has key 1
9
+ * they can open door 1". Adds a required `key_id` (`container_ref`) param.
10
+ * - `gridPermission` — the caller must hold a runtime grid permission; ties
11
+ * the object to a world region ("movement permission on chunk X opens the
12
+ * doors in it").
13
+ * - `groupPermission` — the caller must be in a team/group (optionally with a
14
+ * specific group permission).
15
+ * - `custom` — any hand-written {@link KitInvokePolicy} rule.
16
+ */
17
+ export type LockAuthority = {
18
+ kind: 'owner';
19
+ } | {
20
+ kind: 'key';
21
+ } | {
22
+ kind: 'gridPermission';
23
+ key: string;
24
+ gridId?: string;
25
+ } | {
26
+ /**
27
+ * The caller must hold the runtime permission on the grid covering the
28
+ * chunk the OBJECT stands in (`cx`/`cy`/`cz` int properties, seeded via
29
+ * `ObjectsKit.create({ chunk })`). No hand-pinned grid id — one function
30
+ * serves every such object in the world. `mode` picks the covering grid
31
+ * when several overlap: 'first' (enforcement parity, default) |
32
+ * 'smallest' (innermost plot) | 'largest'. Requires game-api v0.13.12+.
33
+ */
34
+ kind: 'chunkPermission';
35
+ key: string;
36
+ mode?: 'first' | 'smallest' | 'largest';
37
+ } | {
38
+ kind: 'groupPermission';
39
+ groupId: string;
40
+ permission?: string;
41
+ } | {
42
+ kind: 'custom';
43
+ rule: KitInvokePolicy;
44
+ };
45
+ /** Options for {@link lockBlueprint}. */
46
+ export interface LockBlueprintOptions {
47
+ /**
48
+ * Container type name for the lockable object (`Door`, `Chest`, `Gate`, …).
49
+ * Also drives the function names (`open_door` / `close_door`). Defaults to
50
+ * `'Lockable'`.
51
+ */
52
+ objectTypeName?: string;
53
+ /** Key item type name (only used with a `key` authority). Defaults to `<objectTypeName>Key`. */
54
+ keyTypeName?: string;
55
+ /** One or more authority sources; any one grants access. */
56
+ authority: LockAuthority | LockAuthority[];
57
+ /**
58
+ * Extra policy rule AND'ed on top of the OR'd authorities — e.g.
59
+ * `featureGate('vip')` for members-only doors regardless of keys.
60
+ */
61
+ policyExtra?: KitInvokePolicy;
62
+ }
63
+ /** Names derived by {@link lockBlueprint} for a given object type. */
64
+ export interface LockNames {
65
+ objectType: string;
66
+ keyType: string;
67
+ openFn: string;
68
+ closeFn: string;
69
+ }
70
+ /** Compute the type/function names a lock blueprint (and its runtime helper) uses. */
71
+ export declare function lockNames(objectTypeName?: string, keyTypeName?: string): LockNames;
72
+ /**
73
+ * Blueprint for a **lockable game object** (door, chest, gate, switch) whose
74
+ * `open`/`close` functions are gated by a configurable authority source:
75
+ * ownership, a key item the caller must hold, a runtime grid permission, a
76
+ * team/group permission, or any custom policy rule. Multiple authorities are
77
+ * OR'd, so "the owner, or anyone with the right key" is one blueprint.
78
+ *
79
+ * Runtime counterpart: `client.kit(appId).objects`.
80
+ */
81
+ export declare function lockBlueprint(options: LockBlueprintOptions): KitBlueprint;
82
+ //# sourceMappingURL=locks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locks.d.ts","sourceRoot":"","sources":["../../../src/kit/blueprints/locks.ts"],"names":[],"mappings":"AAMA,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,eAAe,EACrB,MAAM,WAAW,CAAC;AAEnB;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,GACf;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACxD;IACE;;;;;;;OAOG;IACH,IAAI,EAAE,iBAAiB,CAAC;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAAC;CACzC,GACD;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GACjE;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,eAAe,CAAA;CAAE,CAAC;AAE9C,yCAAyC;AACzC,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gGAAgG;IAChG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,SAAS,EAAE,aAAa,GAAG,aAAa,EAAE,CAAC;IAC3C;;;OAGG;IACH,WAAW,CAAC,EAAE,eAAe,CAAC;CAC/B;AAED,sEAAsE;AACtE,MAAM,WAAW,SAAS;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,sFAAsF;AACtF,wBAAgB,SAAS,CACvB,cAAc,SAAa,EAC3B,WAAW,CAAC,EAAE,MAAM,GACnB,SAAS,CAQX;AAwCD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,YAAY,CA6GzE"}