@v12-engine/engine 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/dist/abilities/buffs.d.ts +83 -0
- package/dist/abilities/castTold.d.ts +12 -0
- package/dist/abilities/charges.d.ts +28 -0
- package/dist/abilities/dispel.d.ts +9 -0
- package/dist/abilities/effectFields.d.ts +10 -0
- package/dist/abilities/effects/buff.d.ts +8 -0
- package/dist/abilities/effects/core.d.ts +1 -0
- package/dist/abilities/effects/damage.d.ts +1 -0
- package/dist/abilities/effects/heal.d.ts +2 -0
- package/dist/abilities/effects/missile.d.ts +1 -0
- package/dist/abilities/effects/moves.d.ts +11 -0
- package/dist/abilities/effects/passives.d.ts +15 -0
- package/dist/abilities/effects/sight.d.ts +4 -0
- package/dist/abilities/effects/spawn.d.ts +2 -0
- package/dist/abilities/effects/timed.d.ts +4 -0
- package/dist/abilities/effects/trade.d.ts +1 -0
- package/dist/abilities/effects.d.ts +122 -0
- package/dist/abilities/land.d.ts +21 -0
- package/dist/abilities/scaled.d.ts +21 -0
- package/dist/abilities/text.d.ts +113 -0
- package/dist/ai/area.d.ts +53 -0
- package/dist/ai/brain.d.ts +528 -0
- package/dist/ai/budget.d.ts +67 -0
- package/dist/ai/checks.d.ts +115 -0
- package/dist/ai/computer.d.ts +166 -0
- package/dist/ai/defence.d.ts +108 -0
- package/dist/ai/define.d.ts +21 -0
- package/dist/ai/economy.d.ts +129 -0
- package/dist/ai/geometry.d.ts +35 -0
- package/dist/ai/goals.d.ts +360 -0
- package/dist/ai/index.d.ts +38 -0
- package/dist/ai/knowledge.d.ts +418 -0
- package/dist/ai/lanes.d.ts +232 -0
- package/dist/ai/melee/build.d.ts +61 -0
- package/dist/ai/melee/goals.d.ts +299 -0
- package/dist/ai/melee/heroes.d.ts +27 -0
- package/dist/ai/melee/index.d.ts +14 -0
- package/dist/ai/melee/production.d.ts +8 -0
- package/dist/ai/melee/surrender.d.ts +24 -0
- package/dist/ai/micro.d.ts +278 -0
- package/dist/ai/mission.d.ts +195 -0
- package/dist/ai/missionRules.d.ts +18 -0
- package/dist/ai/module.d.ts +116 -0
- package/dist/ai/options.d.ts +61 -0
- package/dist/ai/plans/build.d.ts +280 -0
- package/dist/ai/plans/placement.d.ts +82 -0
- package/dist/ai/plans/plans.d.ts +105 -0
- package/dist/ai/plans/production.d.ts +210 -0
- package/dist/ai/plans/purse.d.ts +73 -0
- package/dist/ai/plans/tech.d.ts +37 -0
- package/dist/ai/profiles.d.ts +204 -0
- package/dist/ai/reach.d.ts +4 -0
- package/dist/ai/report.d.ts +203 -0
- package/dist/ai/roles.d.ts +133 -0
- package/dist/ai/rules.d.ts +288 -0
- package/dist/ai/scouting.d.ts +98 -0
- package/dist/ai/settings.d.ts +73 -0
- package/dist/ai/squads.d.ts +429 -0
- package/dist/ai/strength.d.ts +167 -0
- package/dist/ai/task.d.ts +118 -0
- package/dist/ai/tasks/attack.d.ts +7 -0
- package/dist/ai/tasks/capture.d.ts +21 -0
- package/dist/ai/tasks/creep.d.ts +16 -0
- package/dist/ai/tasks/defend.d.ts +29 -0
- package/dist/ai/tasks/drop.d.ts +34 -0
- package/dist/ai/tasks/escort.d.ts +16 -0
- package/dist/ai/tasks/gather.d.ts +23 -0
- package/dist/ai/tasks/harass.d.ts +7 -0
- package/dist/ai/tasks/hold.d.ts +20 -0
- package/dist/ai/tasks/index.d.ts +32 -0
- package/dist/ai/tasks/move.d.ts +19 -0
- package/dist/ai/tasks/patrol.d.ts +8 -0
- package/dist/ai/tasks/retreat.d.ts +20 -0
- package/dist/ai/tasks/scout.d.ts +29 -0
- package/dist/ai/tasks/shared.d.ts +74 -0
- package/dist/ai/team.d.ts +155 -0
- package/dist/ai/threat.d.ts +91 -0
- package/dist/ai/view.d.ts +366 -0
- package/dist/ai/waves.d.ts +126 -0
- package/dist/ai.js +6239 -0
- package/dist/ai.js.map +1 -0
- package/dist/aiTesting.d.ts +179 -0
- package/dist/areas.d.ts +149 -0
- package/dist/attacks.d.ts +66 -0
- package/dist/attributes.d.ts +66 -0
- package/dist/brain-BvVdUhX8.js +7659 -0
- package/dist/brain-BvVdUhX8.js.map +1 -0
- package/dist/builds-C6LfgvEU.js +460 -0
- package/dist/builds-C6LfgvEU.js.map +1 -0
- package/dist/bytes.d.ts +6 -0
- package/dist/camps.d.ts +95 -0
- package/dist/capture.d.ts +131 -0
- package/dist/cellLayers.d.ts +75 -0
- package/dist/cinematics.d.ts +194 -0
- package/dist/clock.d.ts +32 -0
- package/dist/commands.d.ts +235 -0
- package/dist/components.d.ts +184 -0
- package/dist/computers.d.ts +108 -0
- package/dist/concealment.d.ts +61 -0
- package/dist/coreComponents-syuh2fPG.js +5149 -0
- package/dist/coreComponents-syuh2fPG.js.map +1 -0
- package/dist/coreComponents.d.ts +1 -0
- package/dist/dashing.d.ts +8 -0
- package/dist/debug.d.ts +36 -0
- package/dist/debug.js +3 -0
- package/dist/debugCommands-CzjrSm66.js +14739 -0
- package/dist/debugCommands-CzjrSm66.js.map +1 -0
- package/dist/debugCommands.d.ts +213 -0
- package/dist/debugging.d.ts +10 -0
- package/dist/definitions.d.ts +43 -0
- package/dist/defs.d.ts +1162 -0
- package/dist/denying.d.ts +81 -0
- package/dist/destructibles.d.ts +27 -0
- package/dist/determinism-BCymQwiE.js +518 -0
- package/dist/determinism-BCymQwiE.js.map +1 -0
- package/dist/determinism.d.ts +121 -0
- package/dist/dialog.d.ts +94 -0
- package/dist/effectRefs.d.ts +16 -0
- package/dist/effects.d.ts +80 -0
- package/dist/endings.d.ts +22 -0
- package/dist/engagement.d.ts +108 -0
- package/dist/engineEvents.d.ts +710 -0
- package/dist/entity.d.ts +409 -0
- package/dist/entityIndex.d.ts +50 -0
- package/dist/errors.d.ts +85 -0
- package/dist/events.d.ts +97 -0
- package/dist/exactMath.d.ts +63 -0
- package/dist/features.d.ts +10 -0
- package/dist/fields.d.ts +114 -0
- package/dist/fixture.d.ts +17 -0
- package/dist/fog.d.ts +110 -0
- package/dist/formation.d.ts +111 -0
- package/dist/friendlyFire.d.ts +26 -0
- package/dist/game-DiJEN-Ks.js +5800 -0
- package/dist/game-DiJEN-Ks.js.map +1 -0
- package/dist/game.d.ts +501 -0
- package/dist/gameData.d.ts +325 -0
- package/dist/gameFiles.d.ts +26 -0
- package/dist/gates.d.ts +28 -0
- package/dist/generate.d.ts +403 -0
- package/dist/generateWorker.d.ts +39 -0
- package/dist/grid.d.ts +53 -0
- package/dist/ground.d.ts +127 -0
- package/dist/groundSpeed.d.ts +22 -0
- package/dist/hero.d.ts +177 -0
- package/dist/home.d.ts +14 -0
- package/dist/hooks.d.ts +780 -0
- package/dist/hotReload.d.ts +76 -0
- package/dist/ids.d.ts +26 -0
- package/dist/index.d.ts +227 -0
- package/dist/index.js +4701 -0
- package/dist/index.js.map +1 -0
- package/dist/inspect-D9dWHmZ0.js +491 -0
- package/dist/inspect-D9dWHmZ0.js.map +1 -0
- package/dist/inspect.d.ts +176 -0
- package/dist/inventory.d.ts +18 -0
- package/dist/items.d.ts +91 -0
- package/dist/lanes.d.ts +213 -0
- package/dist/life.d.ts +53 -0
- package/dist/local-Dkovq42k.js +1379 -0
- package/dist/local-Dkovq42k.js.map +1 -0
- package/dist/log.d.ts +140 -0
- package/dist/manaBurn.d.ts +39 -0
- package/dist/map/file.d.ts +114 -0
- package/dist/map/images.d.ts +18 -0
- package/dist/map/look.d.ts +47 -0
- package/dist/map/pathProfile.d.ts +13 -0
- package/dist/map/resize.d.ts +54 -0
- package/dist/map/schema.d.ts +10 -0
- package/dist/map/terrain.d.ts +32 -0
- package/dist/map/types.d.ts +613 -0
- package/dist/map.d.ts +7 -0
- package/dist/mapCheck/cells.d.ts +19 -0
- package/dist/mapCheck/rule.d.ts +30 -0
- package/dist/mapCheck/rules/names.d.ts +3 -0
- package/dist/mapCheck/rules/objects.d.ts +3 -0
- package/dist/mapCheck/rules/paths.d.ts +3 -0
- package/dist/mapCheck/rules/players.d.ts +3 -0
- package/dist/mapCheck/rules/races.d.ts +3 -0
- package/dist/mapCheck/rules/random.d.ts +3 -0
- package/dist/mapCheck/rules/regions.d.ts +3 -0
- package/dist/mapCheck/rules/targets.d.ts +3 -0
- package/dist/mapCheck/rules/walking.d.ts +3 -0
- package/dist/mapCheck.d.ts +23 -0
- package/dist/mapFields.d.ts +364 -0
- package/dist/mapFile.d.ts +23 -0
- package/dist/mapMeasure.d.ts +95 -0
- package/dist/mapMerge.d.ts +19 -0
- package/dist/mapObjectives.d.ts +82 -0
- package/dist/mapObjects.d.ts +1 -0
- package/dist/math.d.ts +44 -0
- package/dist/messages.d.ts +150 -0
- package/dist/missionRules-C-bGxm0Q.js +523 -0
- package/dist/missionRules-C-bGxm0Q.js.map +1 -0
- package/dist/missionRules.d.ts +179 -0
- package/dist/mods.d.ts +146 -0
- package/dist/names.d.ts +93 -0
- package/dist/navigation/agentParams.d.ts +4 -0
- package/dist/navigation/air.d.ts +89 -0
- package/dist/navigation/builds.d.ts +140 -0
- package/dist/navigation/groundAreas.d.ts +23 -0
- package/dist/navigation/navigation.d.ts +127 -0
- package/dist/navigation/recast.d.ts +214 -0
- package/dist/navigation/sidePaths.d.ts +69 -0
- package/dist/navigation/sized.d.ts +1 -0
- package/dist/navigation-worker.js +11 -0
- package/dist/navigation-worker.js.map +1 -0
- package/dist/nearest.d.ts +8 -0
- package/dist/noise.d.ts +12 -0
- package/dist/objectives.d.ts +93 -0
- package/dist/orders/basic.d.ts +96 -0
- package/dist/orders/build.d.ts +91 -0
- package/dist/orders/cast.d.ts +105 -0
- package/dist/orders/facts.d.ts +14 -0
- package/dist/orders/harvest.d.ts +94 -0
- package/dist/orders/idle.d.ts +7 -0
- package/dist/orders/items.d.ts +14 -0
- package/dist/orders/queue.d.ts +24 -0
- package/dist/pack.schema.json +6621 -0
- package/dist/packs/director/index.d.ts +81 -0
- package/dist/packs/heroes/campaign.d.ts +137 -0
- package/dist/packs/heroes/carry.d.ts +59 -0
- package/dist/packs/heroes/commands.d.ts +6 -0
- package/dist/packs/heroes/hire.d.ts +9 -0
- package/dist/packs/heroes/index.d.ts +12 -0
- package/dist/packs/heroes/making.d.ts +16 -0
- package/dist/packs/heroes/respawn.d.ts +42 -0
- package/dist/packs/moba/index.d.ts +34 -0
- package/dist/packs/pack.d.ts +84 -0
- package/dist/packs-g5thvmGn.js +3199 -0
- package/dist/packs-g5thvmGn.js.map +1 -0
- package/dist/packs.d.ts +84 -0
- package/dist/paths.d.ts +51 -0
- package/dist/plain.d.ts +17 -0
- package/dist/player.d.ts +117 -0
- package/dist/portals.d.ts +66 -0
- package/dist/prefabs.d.ts +139 -0
- package/dist/presetBuildings.d.ts +52 -0
- package/dist/presetGround.d.ts +22 -0
- package/dist/profiles-B3NS9jwk.js +335 -0
- package/dist/profiles-B3NS9jwk.js.map +1 -0
- package/dist/races.d.ts +136 -0
- package/dist/randomGroups.d.ts +2 -0
- package/dist/registry.d.ts +464 -0
- package/dist/remains.d.ts +119 -0
- package/dist/replication.d.ts +103 -0
- package/dist/rng.d.ts +17 -0
- package/dist/rules.d.ts +395 -0
- package/dist/rulesCheck.d.ts +37 -0
- package/dist/runes.d.ts +41 -0
- package/dist/save.d.ts +277 -0
- package/dist/scenario.d.ts +56 -0
- package/dist/scheduler.d.ts +67 -0
- package/dist/score.d.ts +306 -0
- package/dist/sequences.d.ts +132 -0
- package/dist/server/doorman.d.ts +21 -0
- package/dist/server/gameServer.d.ts +346 -0
- package/dist/server/index.d.ts +24 -0
- package/dist/server/lobby.d.ts +1 -0
- package/dist/server/log.d.ts +13 -0
- package/dist/server/match.d.ts +24 -0
- package/dist/server/mode.d.ts +168 -0
- package/dist/server/navigation-worker.d.ts +1 -0
- package/dist/server/navigation.d.ts +11 -0
- package/dist/server/ops.d.ts +78 -0
- package/dist/server/packs.d.ts +15 -0
- package/dist/server/ratings.d.ts +62 -0
- package/dist/server/relay.d.ts +34 -0
- package/dist/server/rooms.d.ts +162 -0
- package/dist/server/seat.d.ts +2 -0
- package/dist/server/seatSettings.d.ts +15 -0
- package/dist/server/secret.d.ts +5 -0
- package/dist/server/start.d.ts +54 -0
- package/dist/server/websocket.d.ts +74 -0
- package/dist/server.js +2861 -0
- package/dist/server.js.map +1 -0
- package/dist/session/can.d.ts +20 -0
- package/dist/session/commandReplay.d.ts +92 -0
- package/dist/session/debug.d.ts +65 -0
- package/dist/session/delay.d.ts +15 -0
- package/dist/session/delta.d.ts +98 -0
- package/dist/session/entityState.d.ts +1 -0
- package/dist/session/local.d.ts +214 -0
- package/dist/session/memory.d.ts +27 -0
- package/dist/session/protocol.d.ts +1155 -0
- package/dist/session/remote.d.ts +530 -0
- package/dist/session/replay.d.ts +114 -0
- package/dist/session/seed.d.ts +7 -0
- package/dist/session/share.d.ts +78 -0
- package/dist/session/socket.d.ts +8 -0
- package/dist/session/wire.d.ts +153 -0
- package/dist/session/worker.d.ts +227 -0
- package/dist/shared.d.ts +171 -0
- package/dist/sides.d.ts +75 -0
- package/dist/sight.d.ts +27 -0
- package/dist/simulate-oXBiw1Ff.js +167 -0
- package/dist/simulate-oXBiw1Ff.js.map +1 -0
- package/dist/simulate-worker.d.ts +1 -0
- package/dist/simulate-worker.js +28 -0
- package/dist/simulate-worker.js.map +1 -0
- package/dist/simulate.d.ts +154 -0
- package/dist/smart.d.ts +9 -0
- package/dist/spatial.d.ts +62 -0
- package/dist/spawning.d.ts +33 -0
- package/dist/stances.d.ts +76 -0
- package/dist/start.d.ts +71 -0
- package/dist/stats.d.ts +122 -0
- package/dist/summons.d.ts +63 -0
- package/dist/systems/abilities.d.ts +3 -0
- package/dist/systems/combat.d.ts +71 -0
- package/dist/systems/combatTold.d.ts +14 -0
- package/dist/systems/construction.d.ts +34 -0
- package/dist/systems/economy.d.ts +21 -0
- package/dist/systems/fog.d.ts +19 -0
- package/dist/systems/life.d.ts +3 -0
- package/dist/systems/movement.d.ts +105 -0
- package/dist/systems/orders.d.ts +7 -0
- package/dist/systems/production.d.ts +49 -0
- package/dist/systems/productionQueue.d.ts +40 -0
- package/dist/systems/victory.d.ts +14 -0
- package/dist/talk.d.ts +65 -0
- package/dist/tech.d.ts +62 -0
- package/dist/techTree.d.ts +38 -0
- package/dist/terrain.d.ts +173 -0
- package/dist/terrainSave.d.ts +29 -0
- package/dist/testing.d.ts +58 -0
- package/dist/testing.js +822 -0
- package/dist/testing.js.map +1 -0
- package/dist/tiles.d.ts +34 -0
- package/dist/timers.d.ts +146 -0
- package/dist/tomes.d.ts +48 -0
- package/dist/trade.d.ts +28 -0
- package/dist/transport.d.ts +76 -0
- package/dist/tunables.d.ts +45 -0
- package/dist/upkeep.d.ts +16 -0
- package/dist/veterancy.d.ts +80 -0
- package/dist/walls.d.ts +86 -0
- package/dist/world.d.ts +1118 -0
- package/package.json +80 -5
- package/README.md +0 -3
package/dist/entity.d.ts
ADDED
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import { type Cost, type EffectDef, type ResourceKind, type UnitTypeDef } from './defs';
|
|
2
|
+
import { type Component } from './components';
|
|
3
|
+
import type { Rect, Vec2 } from './math';
|
|
4
|
+
import type { StatsCache } from './stats';
|
|
5
|
+
import type { OrderParams } from './registry';
|
|
6
|
+
/** @beta */
|
|
7
|
+
export type EntityId = number;
|
|
8
|
+
/** @beta */
|
|
9
|
+
export type PlayerId = number;
|
|
10
|
+
/**
|
|
11
|
+
* An order a unit carries out or has queued. `State` is what its behaviour keeps in it (`OrderBehavior<State>`): empty
|
|
12
|
+
* as the order is given, so every field of it is one that may not be there yet
|
|
13
|
+
*
|
|
14
|
+
* @beta
|
|
15
|
+
*/
|
|
16
|
+
export interface Order<State extends object = Record<string, any>, Init extends object = OrderParams> {
|
|
17
|
+
id: number;
|
|
18
|
+
type: string;
|
|
19
|
+
/** What it was given, as its type takes it (`OrderInits`): plain data, saved with the order */
|
|
20
|
+
init: Init;
|
|
21
|
+
/** Shared by every unit that received the order from the same command */
|
|
22
|
+
groupId: number;
|
|
23
|
+
started: boolean;
|
|
24
|
+
/** Scratch space owned by the order behavior: plain data, saved with the order */
|
|
25
|
+
state: State;
|
|
26
|
+
}
|
|
27
|
+
/** @beta */
|
|
28
|
+
export interface AbilityState {
|
|
29
|
+
id: string;
|
|
30
|
+
/** 0 for an ability a hero has not learned yet */
|
|
31
|
+
level: number;
|
|
32
|
+
/** Seconds until it can be used again */
|
|
33
|
+
cooldown: number;
|
|
34
|
+
/**
|
|
35
|
+
* Uses left, of an ability with charges (`AbilityDef.charges`): all it holds when left out, and `chargesLeft` says
|
|
36
|
+
* how many that is. Set while it holds fewer
|
|
37
|
+
*/
|
|
38
|
+
charges?: number;
|
|
39
|
+
/** Seconds until the next use is back, while it holds fewer than it can */
|
|
40
|
+
refill?: number;
|
|
41
|
+
autocast: boolean;
|
|
42
|
+
/** Where it was last aimed */
|
|
43
|
+
point?: Vec2;
|
|
44
|
+
}
|
|
45
|
+
/** @beta */
|
|
46
|
+
export interface BuffInstance {
|
|
47
|
+
id: string;
|
|
48
|
+
/** Level of the ability it came from */
|
|
49
|
+
level: number;
|
|
50
|
+
/** Seconds left. Infinity for buffs that stay */
|
|
51
|
+
remaining: number;
|
|
52
|
+
elapsed: number;
|
|
53
|
+
/** Entity that put it there */
|
|
54
|
+
source: EntityId;
|
|
55
|
+
/** What is left of the shield it gives */
|
|
56
|
+
shield?: number;
|
|
57
|
+
/** How many of it there are, for buffs that pile up */
|
|
58
|
+
stacks?: number;
|
|
59
|
+
/** The ability it came from, for buffs that do something when their time is up */
|
|
60
|
+
ability?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Kept up by an ability of its source's for as long as it holds (a passive's buff, an aura's): put on again every
|
|
63
|
+
* round for a moment, with no time of its own to show (`EntityState.buffTimes` says -1)
|
|
64
|
+
*/
|
|
65
|
+
kept?: boolean;
|
|
66
|
+
/** State of the game's own about this one buff: a counter, what it has done so far. Plain data: it is saved */
|
|
67
|
+
data?: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* An item someone carries
|
|
71
|
+
*
|
|
72
|
+
* @beta
|
|
73
|
+
*/
|
|
74
|
+
export interface ItemInstance {
|
|
75
|
+
id: number;
|
|
76
|
+
item: string;
|
|
77
|
+
/** Uses left, for items that run out */
|
|
78
|
+
charges: number;
|
|
79
|
+
/** Cooldown of the ability the item gives */
|
|
80
|
+
state?: AbilityState;
|
|
81
|
+
/** State of the game's own about this one item: kills it has seen, what it has stored. Plain data: it is saved */
|
|
82
|
+
data?: Record<string, unknown>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* What a shop has of one of its wares (`shopStock`, a component of the entity's)
|
|
86
|
+
*
|
|
87
|
+
* @beta
|
|
88
|
+
*/
|
|
89
|
+
export interface StockState {
|
|
90
|
+
item: string;
|
|
91
|
+
count: number;
|
|
92
|
+
/** Seconds until the next one arrives */
|
|
93
|
+
restock: number;
|
|
94
|
+
}
|
|
95
|
+
/** @beta */
|
|
96
|
+
export type MoveStatus = 'idle' | 'moving' | 'arrived' | 'failed';
|
|
97
|
+
/** @beta */
|
|
98
|
+
export interface MovementState {
|
|
99
|
+
speed: number;
|
|
100
|
+
/** The fastest it goes for now, whatever its speed: a group's slowest, as it moves together (`OrderParams.together`) */
|
|
101
|
+
cap?: number;
|
|
102
|
+
status: MoveStatus;
|
|
103
|
+
goal: Vec2;
|
|
104
|
+
/** When set the goal follows this entity */
|
|
105
|
+
goalEntity: EntityId;
|
|
106
|
+
/** Arrive once this close to the goal (edge distance for entity goals) */
|
|
107
|
+
range: number;
|
|
108
|
+
groupId: number;
|
|
109
|
+
/** Last destination handed to the navigation */
|
|
110
|
+
navGoal: Vec2;
|
|
111
|
+
navVersion: number;
|
|
112
|
+
/** Corner of the path the unit is heading for. Progress is measured towards it, so a long way round is not mistaken for standing still */
|
|
113
|
+
corner: Vec2;
|
|
114
|
+
/** Closest the unit has been to its corner, used to detect that it stopped making progress */
|
|
115
|
+
bestDistance: number;
|
|
116
|
+
stalledTime: number;
|
|
117
|
+
/**
|
|
118
|
+
* Seconds it has gone well under its speed on its way, held up by others (not counting getting going, or slowing
|
|
119
|
+
* to arrive): what has those in its way asked to step aside (see `GameRules.movement.lookAhead`)
|
|
120
|
+
*/
|
|
121
|
+
slowTime?: number;
|
|
122
|
+
/**
|
|
123
|
+
* The point it goes round standing units by, on its way to the next corner of its path, when that is not much
|
|
124
|
+
* longer (`GameRules.movement.goesAround`, the `detour` hook): none while it goes straight
|
|
125
|
+
*/
|
|
126
|
+
detour?: Vec2;
|
|
127
|
+
/** Where it heads on from `detour`: the corner of its path it went round the knot towards */
|
|
128
|
+
detourAim?: Vec2;
|
|
129
|
+
/** On a step aside for another (`MoveOptions.aside`): it goes round nobody and asks nobody to make way */
|
|
130
|
+
aside?: boolean;
|
|
131
|
+
/** Whether it was sent on past `detour`, towards its path, as it neared it */
|
|
132
|
+
detourPast?: boolean;
|
|
133
|
+
/** Whether the last move failed by getting stuck on the way (in a crowd, say), not for there being no way there */
|
|
134
|
+
stuck?: boolean;
|
|
135
|
+
anchored: boolean;
|
|
136
|
+
ghost: boolean;
|
|
137
|
+
/** Direction the unit turns to while it stands still. Null when it may face wherever it ended up */
|
|
138
|
+
finalFacing: number | null;
|
|
139
|
+
/**
|
|
140
|
+
* The route its side planned to the goal, corner by corner, with what the side knows (`GameModule.paths: 'seen'`):
|
|
141
|
+
* walked a stretch at a time. None where routes know everything, or there is no route
|
|
142
|
+
*/
|
|
143
|
+
route?: Vec2[];
|
|
144
|
+
/** The corner of `route` it heads past next */
|
|
145
|
+
routeAt?: number;
|
|
146
|
+
/** What its side knew when the route was planned (`SidePaths.version`): it is planned again once that changes */
|
|
147
|
+
routeVersion?: number;
|
|
148
|
+
/** Where along `route` the navigation was last sent it: a stretch no longer than it can see */
|
|
149
|
+
stretch?: Vec2;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* What moves of an entity: where it goes, how fast, how it is doing (`MovementState`). Units that walk, swim or fly
|
|
153
|
+
* have it from their type's speed; a building, a tree, or a unit an upgrade stopped has none. Filed (`index`), for the
|
|
154
|
+
* movement system to go through
|
|
155
|
+
*
|
|
156
|
+
* @beta
|
|
157
|
+
*/
|
|
158
|
+
export declare const moving: Component<MovementState, MovementState>;
|
|
159
|
+
/** @beta */
|
|
160
|
+
export interface CombatState {
|
|
161
|
+
/** Seconds until the next attack may start */
|
|
162
|
+
cooldown: number;
|
|
163
|
+
/** Seconds until the running swing lands. 0 when not swinging */
|
|
164
|
+
swing: number;
|
|
165
|
+
swingTarget: EntityId;
|
|
166
|
+
/**
|
|
167
|
+
* Which of its attacks the running swing, or the last, is of, by place (`UnitTypeDef.attacks`): the first when left
|
|
168
|
+
* out, as for every unit with one. It swings one at a time, and waits out the cooldown of the one that hit
|
|
169
|
+
*/
|
|
170
|
+
weapon?: number;
|
|
171
|
+
/** Target picked by the unit itself rather than by an order */
|
|
172
|
+
autoTarget: EntityId;
|
|
173
|
+
lastAttacker: EntityId;
|
|
174
|
+
/** Where an idle unit returns to after chasing */
|
|
175
|
+
guard: Vec2 | null;
|
|
176
|
+
/** Does not pick fights of its own accord until it gets an order (set by a game's rules; `stop` no longer sets it) */
|
|
177
|
+
passive: boolean;
|
|
178
|
+
/** What it is fighting or closing in on, whoever picked it: 0 for nothing (see `engagement.ts`) */
|
|
179
|
+
engaged?: EntityId;
|
|
180
|
+
/** The spot it holds around that, as an angle seen from it. Null when it has none: it flies, it hits a building */
|
|
181
|
+
slot?: number | null;
|
|
182
|
+
/** Targets it left alone because it could not get at them, and until when, in world time */
|
|
183
|
+
shunned?: [EntityId, number][];
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* How an entity fights (`CombatState`): its cooldown, its swing, what it is engaged with. What attacks has it from its
|
|
187
|
+
* type's attack; an upgrade that takes the attack away takes it. Filed (`index`), for the combat system to go through
|
|
188
|
+
*
|
|
189
|
+
* @beta
|
|
190
|
+
*/
|
|
191
|
+
export declare const fighting: Component<CombatState, CombatState>;
|
|
192
|
+
/** @beta */
|
|
193
|
+
export interface HarvesterState {
|
|
194
|
+
carrying: number;
|
|
195
|
+
/** What it is that the worker carries, or last gathered. Null for one that has not gathered anything yet */
|
|
196
|
+
kind: ResourceKind | null;
|
|
197
|
+
/** Last resource this worker gathered from */
|
|
198
|
+
resource: EntityId;
|
|
199
|
+
}
|
|
200
|
+
/** @beta */
|
|
201
|
+
export interface ResourceState {
|
|
202
|
+
amount: number;
|
|
203
|
+
occupants: number;
|
|
204
|
+
/** The building that stands on it (`UnitTypeDef.builtOn`), by id: none when nothing does */
|
|
205
|
+
under?: EntityId;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* What is left of what can be gathered from an entity, and who is at it (`ResourceState`): a mine's gold, a tree's
|
|
209
|
+
* lumber. What its type gives (`UnitTypeDef.resource`) as it is made. Filed (`index`), for what looks for the nearest
|
|
210
|
+
*
|
|
211
|
+
* @beta
|
|
212
|
+
*/
|
|
213
|
+
export declare const deposit: Component<ResourceState, ResourceState>;
|
|
214
|
+
/** @beta */
|
|
215
|
+
export interface ConstructionState {
|
|
216
|
+
/** 0..1 */
|
|
217
|
+
progress: number;
|
|
218
|
+
buildTime: number;
|
|
219
|
+
/** Builders that worked on it during the current tick */
|
|
220
|
+
builders: number;
|
|
221
|
+
/** What was paid for it, when that is not what its type costs. A cancelled site gives part of this back */
|
|
222
|
+
paid?: Cost;
|
|
223
|
+
}
|
|
224
|
+
/** @beta */
|
|
225
|
+
export interface ProductionItem {
|
|
226
|
+
kind: 'unit' | 'upgrade' | 'revive' | 'morph';
|
|
227
|
+
/** Unit type, upgrade id, the id of the hero to bring back, or the type the building turns into */
|
|
228
|
+
id: string;
|
|
229
|
+
/** What was paid, when that does not follow from the id */
|
|
230
|
+
paid?: Cost;
|
|
231
|
+
/** Seconds of work done */
|
|
232
|
+
progress: number;
|
|
233
|
+
duration: number;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Seconds an entity stays in sight of other teams, by team, for having attacked them: seen where it stands, in the fog
|
|
237
|
+
* and in a bush. Filed (`index`), for the fog to light those that have it
|
|
238
|
+
*
|
|
239
|
+
* @beta
|
|
240
|
+
*/
|
|
241
|
+
export declare const exposure: Component<Map<number, number>, Map<number, number>>;
|
|
242
|
+
/**
|
|
243
|
+
* Seconds the teams that found an invisible entity with something that reveals it can go on seeing it, by team. Filed
|
|
244
|
+
* (`index`), for the fog to light those that have it
|
|
245
|
+
*
|
|
246
|
+
* @beta
|
|
247
|
+
*/
|
|
248
|
+
export declare const detection: Component<Map<number, number>, Map<number, number>>;
|
|
249
|
+
/**
|
|
250
|
+
* A rush to a spot: nothing stops it, and what it does happens where it ends
|
|
251
|
+
*
|
|
252
|
+
* @beta
|
|
253
|
+
*/
|
|
254
|
+
export interface Dash {
|
|
255
|
+
x: number;
|
|
256
|
+
z: number;
|
|
257
|
+
/** Where it started */
|
|
258
|
+
from: Vec2;
|
|
259
|
+
/** Units per second */
|
|
260
|
+
speed: number;
|
|
261
|
+
ability: string;
|
|
262
|
+
level: number;
|
|
263
|
+
effects: EffectDef[];
|
|
264
|
+
/** How high it rises on the way: a leap, over whatever is in between */
|
|
265
|
+
height?: number;
|
|
266
|
+
/** A buff it carries for as long as the rush lasts */
|
|
267
|
+
buff?: string;
|
|
268
|
+
}
|
|
269
|
+
/** @beta */
|
|
270
|
+
export interface RallyPoint {
|
|
271
|
+
point: Vec2;
|
|
272
|
+
target: EntityId;
|
|
273
|
+
}
|
|
274
|
+
/** @beta */
|
|
275
|
+
export interface ProductionState {
|
|
276
|
+
queue: ProductionItem[];
|
|
277
|
+
rally: RallyPoint | null;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Anything in the world: a unit, a building, a tree.
|
|
281
|
+
*
|
|
282
|
+
* Fields marked `readonly` are kept in step with things elsewhere (the navigation, the spatial index, the lookups
|
|
283
|
+
* of the world), so they are changed through the world's functions only: `World.setOwner`, `World.setHidden`,
|
|
284
|
+
* `World.setLifetime`, `World.place`, `startDash`, `morph` (each through the entity's own internal writes: `moveTo`,
|
|
285
|
+
* `retype`, `changeOwner`…). The rest, like health, mana or cooldowns, a game
|
|
286
|
+
* module may change as it likes: nothing is worked out from them that would not notice.
|
|
287
|
+
*
|
|
288
|
+
* @beta
|
|
289
|
+
*/
|
|
290
|
+
export declare class Entity {
|
|
291
|
+
readonly id: EntityId;
|
|
292
|
+
/** Changes when a building is upgraded into another type */
|
|
293
|
+
readonly def: UnitTypeDef;
|
|
294
|
+
readonly owner: PlayerId;
|
|
295
|
+
readonly alive: boolean;
|
|
296
|
+
/** Hidden entities are inside something (a gold mine) and do not take part in the world */
|
|
297
|
+
readonly hidden: boolean;
|
|
298
|
+
/**
|
|
299
|
+
* Only stands there, like a tree: left out of the systems that run every tick, see `isScenery`.
|
|
300
|
+
* Becomes false for good once something gives it anything to do (`World.wake`)
|
|
301
|
+
*/
|
|
302
|
+
readonly scenery: boolean;
|
|
303
|
+
readonly pos: Readonly<Vec2>;
|
|
304
|
+
readonly prevPos: Vec2;
|
|
305
|
+
facing: number;
|
|
306
|
+
prevFacing: number;
|
|
307
|
+
/** How big it is drawn, for the look of a map. Nothing in the rules goes by it */
|
|
308
|
+
scale: number;
|
|
309
|
+
/** Which of the models of its type it is drawn with, for the look of a map. Nothing in the rules goes by it either */
|
|
310
|
+
look?: string;
|
|
311
|
+
/** Velocity of the last tick */
|
|
312
|
+
readonly velocity: Vec2;
|
|
313
|
+
hp: number;
|
|
314
|
+
/** Teams that have seen this entity at least once, one bit per team as `FogOfWar.teamBit` hands them out. Ask `World.hasSeen` */
|
|
315
|
+
seenBy: number;
|
|
316
|
+
/** When it was last hurt, in seconds of the game. Long ago for what never was */
|
|
317
|
+
hurtAt: number;
|
|
318
|
+
/** Seconds until it is gone by itself, for what does not last */
|
|
319
|
+
readonly expires: number | null;
|
|
320
|
+
/** Seconds it was given to last, for what does not */
|
|
321
|
+
lifetime: number;
|
|
322
|
+
/** Seconds until enemies cannot see it any more, for what is invisible. 0 once they cannot */
|
|
323
|
+
unseenIn: number | null;
|
|
324
|
+
/**
|
|
325
|
+
* What it was told to do, the first what it does now and the rest in turn: read here, given and ended through the
|
|
326
|
+
* orders' functions (`giveOrder`, `clearOrders`, `completeOrder`), which write it with the entity's own `addOrder`,
|
|
327
|
+
* `keepOrders` and `removeOrder`
|
|
328
|
+
*/
|
|
329
|
+
readonly orders: readonly Order[];
|
|
330
|
+
/** Invisible to enemies right now, unless they have found it */
|
|
331
|
+
get unseen(): boolean;
|
|
332
|
+
maxHp: number;
|
|
333
|
+
mana: number;
|
|
334
|
+
maxMana: number;
|
|
335
|
+
/** Does nothing by itself until something wakes it, and is drawn sleeping: creeps at night */
|
|
336
|
+
asleep: boolean;
|
|
337
|
+
/** A fallen hero that is on its way back */
|
|
338
|
+
reviving: boolean;
|
|
339
|
+
/**
|
|
340
|
+
* What it can cast, with their levels and cooldowns: each state is the game's to change (`cooldown`, `autocast`),
|
|
341
|
+
* the list the engine's (a type's own, what a hero learns), written with the entity's own internal methods
|
|
342
|
+
*/
|
|
343
|
+
readonly abilities: readonly AbilityState[];
|
|
344
|
+
/** What is on it: each instance the game's to change, the list put on and taken off by `applyBuff`, `removeBuff` */
|
|
345
|
+
readonly buffs: readonly BuffInstance[];
|
|
346
|
+
/** The resource it stands on (`UnitTypeDef.builtOn`), by id: none for what stands on the ground */
|
|
347
|
+
on?: EntityId;
|
|
348
|
+
/** Min corner of the footprint in grid cells, for buildings and resources */
|
|
349
|
+
cell?: {
|
|
350
|
+
x: number;
|
|
351
|
+
z: number;
|
|
352
|
+
};
|
|
353
|
+
/** Bookkeeping of the spatial index: the last query that found it. Not game state */
|
|
354
|
+
spatialStamp: number;
|
|
355
|
+
/** Stats as last worked out, see `statsOf`. Derived from the rest, never saved or sent */
|
|
356
|
+
statsCache: StatsCache | null;
|
|
357
|
+
/** The index of the world it is in, told when it gets or loses a component. Not game state */
|
|
358
|
+
index: {
|
|
359
|
+
componentChanged(entity: Entity, id: string, has: boolean): void;
|
|
360
|
+
} | null;
|
|
361
|
+
constructor(id: EntityId,
|
|
362
|
+
/** Changes when a building is upgraded into another type */
|
|
363
|
+
def: UnitTypeDef, owner: PlayerId, position: Vec2);
|
|
364
|
+
/** A component of a game module or a mod, see `defineComponent` */
|
|
365
|
+
get<T>(key: Component<T, unknown>): T | undefined;
|
|
366
|
+
has(key: Component<unknown>): boolean;
|
|
367
|
+
/** Gives it the component, or a new value of it. `undefined` takes it away (`remove`) */
|
|
368
|
+
set<T>(key: Component<T, unknown>, value: T): void;
|
|
369
|
+
remove(key: Component<unknown>): void;
|
|
370
|
+
/** Its components, in the order it was given them: each one's value is `get(component)` */
|
|
371
|
+
heldComponents(): readonly Component<unknown, unknown>[];
|
|
372
|
+
/**
|
|
373
|
+
* Its components' values by id, in the order it was given them: made each time it is asked, for what reads them
|
|
374
|
+
* by id now and then (a save, the inspector). What does it often goes through `heldComponents`
|
|
375
|
+
*/
|
|
376
|
+
get components(): Readonly<Record<string, unknown>>;
|
|
377
|
+
get isBuilding(): boolean;
|
|
378
|
+
get isUnit(): boolean;
|
|
379
|
+
get isResource(): boolean;
|
|
380
|
+
/** Up in the air, where the ground and what stands on it are not in the way */
|
|
381
|
+
get flying(): boolean;
|
|
382
|
+
get isStructure(): boolean;
|
|
383
|
+
/** Completed and able to do its job */
|
|
384
|
+
get operational(): boolean;
|
|
385
|
+
get currentOrder(): Order | undefined;
|
|
386
|
+
/** Ground area covered by a structure */
|
|
387
|
+
get rect(): Rect;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Anything with a place and a size: an entity, or what a client knows of one
|
|
391
|
+
*
|
|
392
|
+
* @beta
|
|
393
|
+
*/
|
|
394
|
+
export interface Placed {
|
|
395
|
+
pos: Vec2;
|
|
396
|
+
def: UnitTypeDef;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Distance from a point to the edge of an entity
|
|
400
|
+
*
|
|
401
|
+
* @beta
|
|
402
|
+
*/
|
|
403
|
+
export declare function distanceToEdge(point: Vec2, target: Placed): number;
|
|
404
|
+
/**
|
|
405
|
+
* Distance between the edges of two entities
|
|
406
|
+
*
|
|
407
|
+
* @beta
|
|
408
|
+
*/
|
|
409
|
+
export declare function edgeDistance(a: Placed, b: Placed): number;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Component } from './components';
|
|
2
|
+
import type { Entity, PlayerId } from './entity';
|
|
3
|
+
/**
|
|
4
|
+
* Entities filed by what they are asked for by: whose they are, which have a component (and, for a component that
|
|
5
|
+
* asks, whose they are too: `Component.index`). Answers questions like "the heroes of player 2"
|
|
6
|
+
* or "every shop" without going through every entity of the world, most of which are trees. Kept up to date by the
|
|
7
|
+
* world as entities come and go, and by the entities as they get or lose a component.
|
|
8
|
+
*
|
|
9
|
+
* Every set keeps entities in the order of their ids, the order they came into the world and the one a walk through
|
|
10
|
+
* `World.entities` gives, however and whenever each was filed: one that changed owner or type, or was given a component
|
|
11
|
+
* late, takes its place among the others, as it has in a world loaded from a save. Code that picks the first of equals
|
|
12
|
+
* gets the same one either way. A set an entity is filed into out of its place is made again: a walk through it under
|
|
13
|
+
* way goes on through the one it had
|
|
14
|
+
*/
|
|
15
|
+
export declare class EntityIndex {
|
|
16
|
+
private readonly componentOf;
|
|
17
|
+
/** `componentOf`: a component of the world's game by its id, an error for one it does not list (`registry.used`) */
|
|
18
|
+
constructor(componentOf: (id: string) => Component<unknown, unknown> | undefined);
|
|
19
|
+
private readonly owned;
|
|
20
|
+
private readonly components;
|
|
21
|
+
/** By component id, then by owner: for the components that ask (`index: 'owner'`) */
|
|
22
|
+
private readonly byOwner;
|
|
23
|
+
/** By component id, what has it in the order of the entities' ids (`ordered`): made again once it changes */
|
|
24
|
+
private readonly inOrder;
|
|
25
|
+
/** Everything the player owns, dead heroes waiting to be brought back included */
|
|
26
|
+
ownedBy(player: PlayerId): ReadonlySet<Entity>;
|
|
27
|
+
/**
|
|
28
|
+
* Everything that has the component; with a player, what the player owns of it, for a component filed by owner
|
|
29
|
+
* (`Component.index: 'owner'`; throws for one that is not)
|
|
30
|
+
*/
|
|
31
|
+
with(key: Component<unknown, unknown>, owner?: PlayerId): ReadonlySet<Entity>;
|
|
32
|
+
/**
|
|
33
|
+
* Everything that has the component, in the order of the entities' ids: the order a walk through `World.actors`
|
|
34
|
+
* meets them in. What a system that runs over a component goes through (`System.over`), so a game plays the same
|
|
35
|
+
* as one that looks at every actor. A list of its own, kept until what has the component changes: what is given it
|
|
36
|
+
* or loses it while the list is gone through is in the next one
|
|
37
|
+
*/
|
|
38
|
+
ordered(key: Component<unknown, unknown>): readonly Entity[];
|
|
39
|
+
add(entity: Entity): void;
|
|
40
|
+
remove(entity: Entity): void;
|
|
41
|
+
/** An entity in the index was given a component, or had it taken away. Told by the entity */
|
|
42
|
+
/** Whether the component with this id asks to be filed by owner */
|
|
43
|
+
private byOwnerOf;
|
|
44
|
+
componentChanged(entity: Entity, id: string, has: boolean): void;
|
|
45
|
+
private fileComponent;
|
|
46
|
+
private dropComponent;
|
|
47
|
+
/** Throws when the index does not say what the entities are. See `debugChecks` */
|
|
48
|
+
check(entities: Iterable<Entity>): void;
|
|
49
|
+
clear(): void;
|
|
50
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What becomes of a part of a game that throws: a hook's handler, a listener, a system, a timer, a unit's order, a
|
|
3
|
+
* player's command. The game says (`GameModule.onError`), or whoever runs it (a server, a page); a world that is told
|
|
4
|
+
* nothing throws, as it always did, so that a test sees every error.
|
|
5
|
+
*/
|
|
6
|
+
import type { EntityId, PlayerId } from './entity';
|
|
7
|
+
import type { World } from './world';
|
|
8
|
+
/**
|
|
9
|
+
* - `throw`: the error goes on to whoever stepped the world. Nothing is hidden: for tests and development
|
|
10
|
+
* - `end`: the game ends there, with the reason kept (`world.failure`) and told to the players. The world is not
|
|
11
|
+
* stepped again. What a server and a launched game do when nothing is said: one game ends, and nothing else does
|
|
12
|
+
* - `disable`: the part that threw is switched off and the game goes on without it: the handler, the listener, the
|
|
13
|
+
* system or the timer no longer runs; the order is taken off its unit, the command refused. Never done unasked: a
|
|
14
|
+
* rule that is quietly gone is a game that goes quietly wrong
|
|
15
|
+
*
|
|
16
|
+
* @beta
|
|
17
|
+
*/
|
|
18
|
+
export type ErrorAnswer = 'throw' | 'end' | 'disable';
|
|
19
|
+
/**
|
|
20
|
+
* The part of the game that threw
|
|
21
|
+
*
|
|
22
|
+
* @beta
|
|
23
|
+
*/
|
|
24
|
+
export interface ErrorSite {
|
|
25
|
+
kind: 'hook' | 'listener' | 'system' | 'timer' | 'order' | 'command';
|
|
26
|
+
/** Its id: the handler's, the listener's, the system's name, the timer's, the order's or the command's type */
|
|
27
|
+
id: string;
|
|
28
|
+
/** The hook a handler is on */
|
|
29
|
+
hook?: string;
|
|
30
|
+
/** The unit whose order it was */
|
|
31
|
+
entity?: EntityId;
|
|
32
|
+
/** The player whose command it was */
|
|
33
|
+
player?: PlayerId;
|
|
34
|
+
/** The mod that added the part or changed it last, for a game with mods (`composeGame`) */
|
|
35
|
+
mod?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* What to do about an error: the same for all of them, or decided for each
|
|
39
|
+
*
|
|
40
|
+
* @beta
|
|
41
|
+
*/
|
|
42
|
+
export type ErrorPolicy = ErrorAnswer | ((error: unknown, where: ErrorSite, world: World) => ErrorAnswer);
|
|
43
|
+
/**
|
|
44
|
+
* Why a game ended on an error (`world.failure`): plain data, for a log, a save's notes, a player's screen
|
|
45
|
+
*
|
|
46
|
+
* @beta
|
|
47
|
+
*/
|
|
48
|
+
export interface WorldFailure {
|
|
49
|
+
/** What is said to whoever played: no more than that it stopped, and in what */
|
|
50
|
+
message: string;
|
|
51
|
+
where: ErrorSite;
|
|
52
|
+
error: {
|
|
53
|
+
name: string;
|
|
54
|
+
message: string;
|
|
55
|
+
stack?: string;
|
|
56
|
+
};
|
|
57
|
+
tick: number;
|
|
58
|
+
}
|
|
59
|
+
/** Thrown to leave the tick a game ends in (`end`): caught by `World.step`, and never seen outside it */
|
|
60
|
+
export declare class GameEnded extends Error {
|
|
61
|
+
readonly failure: WorldFailure;
|
|
62
|
+
constructor(failure: WorldFailure);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Why a command was turned away (`commandRejected`): a type the game has not got, fields not as its definition says, a
|
|
66
|
+
* player not in the game, a unit not theirs, one there is not, more than a tick takes, or a director's command sent
|
|
67
|
+
* with no cinematic playing on the sender's screen (`withDirector`)
|
|
68
|
+
*
|
|
69
|
+
* @beta
|
|
70
|
+
*/
|
|
71
|
+
export type RejectedKind = 'unknownType' | 'badFields' | 'noSuchPlayer' | 'notTheirs' | 'noSuchUnit' | 'tooMany' | 'notDirecting';
|
|
72
|
+
/** What a part switched off is kept as (`world.disabled`, a save): its kind, id, hook and mod, nothing of the moment it threw */
|
|
73
|
+
export declare const siteOf: (where: ErrorSite) => ErrorSite;
|
|
74
|
+
/**
|
|
75
|
+
* A part in words: `the handler "thorns" of the hook "damage"`
|
|
76
|
+
*
|
|
77
|
+
* @beta
|
|
78
|
+
*/
|
|
79
|
+
export declare function siteWords(where: ErrorSite): string;
|
|
80
|
+
/** Kept by `composeGame` for the game it makes: who changed what, to say whose a part that throws is */
|
|
81
|
+
export declare function notePartOwners(game: object, owners: ReadonlyMap<string, string>): void;
|
|
82
|
+
/** The parts' owners as noted for a game: none for one without mods */
|
|
83
|
+
export declare const partOwners: (game: object) => ReadonlyMap<string, string>;
|
|
84
|
+
/** The mod a part is of, when a mod added it or changed it: nothing for a part of the game itself */
|
|
85
|
+
export declare const modOfPart: (game: object | null | undefined, where: ErrorSite) => string | undefined;
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { SessionView } from './replication';
|
|
2
|
+
import type { World } from './world';
|
|
3
|
+
type Handler<T> = (payload: T) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Who of the players gets an event of a game's own on their screen (see `defineEvent`): everyone, or those a
|
|
6
|
+
* function picks, from what the event says and what the seat may know (`SessionView`: its player, `knows`, `sees`)
|
|
7
|
+
*
|
|
8
|
+
* @beta
|
|
9
|
+
*/
|
|
10
|
+
export type EventAudience<T> = 'everyone' | ((payload: T, view: SessionView) => boolean);
|
|
11
|
+
/**
|
|
12
|
+
* A typed key for an event of a game's own, made with `defineEvent`
|
|
13
|
+
*
|
|
14
|
+
* @beta
|
|
15
|
+
*/
|
|
16
|
+
export interface EventKey<T> {
|
|
17
|
+
readonly id: string;
|
|
18
|
+
/** Sent to the screens of these players, in their snapshots. Only to whoever listens in the world when left out */
|
|
19
|
+
readonly replicate?: EventAudience<T>;
|
|
20
|
+
/** Only there for the type of the payload */
|
|
21
|
+
readonly payload?: T;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* An event of a game's own: `const through = defineEvent<{ unit: string }>('td.invaderThrough', { replicate: 'everyone' })`.
|
|
25
|
+
* Emitted on `world.events` like the engine's (`world.events.emit(through, { unit })`), held to the end of the tick
|
|
26
|
+
* like them, and listened to with `defineListener`. Ids are shared by every game: give them a prefix of the game's.
|
|
27
|
+
*
|
|
28
|
+
* A replicated event goes to the players' screens, where `GameView.on` and the renderers get it: what it says has
|
|
29
|
+
* to be plain data then (numbers, text, lists, plain objects), with entities by id, as it may cross a network
|
|
30
|
+
*
|
|
31
|
+
* @beta
|
|
32
|
+
*/
|
|
33
|
+
export declare function defineEvent<T>(id: string, options?: {
|
|
34
|
+
replicate?: EventAudience<T>;
|
|
35
|
+
}): EventKey<T>;
|
|
36
|
+
/** Whether an event is one of a game's own, rather than one of the engine's */
|
|
37
|
+
export declare const isGameEvent: (id: PropertyKey) => boolean;
|
|
38
|
+
/**
|
|
39
|
+
* How a game reacts to an event: the engine's (`'entityDied'`, `'enteredArea'`) or one of its own. Listeners are
|
|
40
|
+
* given in `GameModule.listeners`, and the world subscribes them when it is made, in their order: a new game, a
|
|
41
|
+
* loaded save and every player's machine get the same ones. They run at the end of the tick, once everything in it
|
|
42
|
+
* is settled, and may change the world: what happens then is part of that tick. One with the id of another takes
|
|
43
|
+
* its place, in a mod
|
|
44
|
+
*
|
|
45
|
+
* @beta
|
|
46
|
+
*/
|
|
47
|
+
export interface ListenerDef {
|
|
48
|
+
id: string;
|
|
49
|
+
event: EventKey<any>;
|
|
50
|
+
run(world: World, payload: any): void;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Typed help for writing a listener: `defineListener({ event: enteredArea, id: 'td.gate', run(world, { area, entity }) { ... } })`
|
|
54
|
+
*
|
|
55
|
+
* @beta
|
|
56
|
+
*/
|
|
57
|
+
export declare function defineListener<T>(def: {
|
|
58
|
+
id: string;
|
|
59
|
+
event: EventKey<T>;
|
|
60
|
+
run(world: World, payload: T): void;
|
|
61
|
+
}): ListenerDef;
|
|
62
|
+
/**
|
|
63
|
+
* Minimal typed event emitter: each event by its key (`EventKey`), which types what it says.
|
|
64
|
+
*
|
|
65
|
+
* While held (`hold`), what is emitted waits in a queue and goes out on `release`, in the order it happened.
|
|
66
|
+
* The world holds its events for the length of a tick, so that whoever listens sees how things stand once
|
|
67
|
+
* the tick is over, and cannot change anything halfway through it.
|
|
68
|
+
*/
|
|
69
|
+
export declare class Emitter {
|
|
70
|
+
private handlers;
|
|
71
|
+
private held;
|
|
72
|
+
private queue;
|
|
73
|
+
/** True while what was held back goes out (`release`) */
|
|
74
|
+
releasing: boolean;
|
|
75
|
+
private readonly taps;
|
|
76
|
+
private readonly watchers;
|
|
77
|
+
/**
|
|
78
|
+
* Calls back for every event as it goes out, before whoever listens to it: the event log of the debug tools, a
|
|
79
|
+
* logger. Any number of them. Returns what stops it
|
|
80
|
+
*/
|
|
81
|
+
tap(listener: (type: PropertyKey, payload: unknown) => void): () => void;
|
|
82
|
+
/**
|
|
83
|
+
* Calls back for every event as it goes out, whatever it is, after whoever listens to it by name: for what cannot
|
|
84
|
+
* know ahead which events there will be, as a player's seat that passes on a game's own. Returns what stops it
|
|
85
|
+
*/
|
|
86
|
+
watch(watcher: (type: PropertyKey, payload: unknown) => void): () => void;
|
|
87
|
+
/** Listens to an event, the engine's (`engineEvents.ts`) or a game's own. Returns what stops it */
|
|
88
|
+
on<T>(key: EventKey<T>, handler: Handler<T>): () => void;
|
|
89
|
+
emit<T>(key: EventKey<T>, payload: T): void;
|
|
90
|
+
/** Holds back what is emitted from now on, until `release` */
|
|
91
|
+
hold(): void;
|
|
92
|
+
/** Sends out everything held back, and stops holding */
|
|
93
|
+
release(): void;
|
|
94
|
+
private deliver;
|
|
95
|
+
clear(): void;
|
|
96
|
+
}
|
|
97
|
+
export {};
|