@datamoc/mw_games 0.7.6 → 0.7.8
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/CHANGELOG.md +359 -0
- package/README.md +7 -7
- package/dist/actors/Inventory.d.ts +7 -1
- package/dist/actors/Inventory.d.ts.map +1 -1
- package/dist/actors/Inventory.js.map +1 -1
- package/dist/actors/Shop.d.ts.map +1 -1
- package/dist/actors/Shop.js +4 -1
- package/dist/actors/Shop.js.map +1 -1
- package/dist/actors/craft.d.ts +35 -14
- package/dist/actors/craft.d.ts.map +1 -1
- package/dist/actors/craft.js +56 -24
- package/dist/actors/craft.js.map +1 -1
- package/dist/actors/index.d.ts +1 -1
- package/dist/actors/index.d.ts.map +1 -1
- package/dist/ai/Heuristics.d.ts +240 -0
- package/dist/ai/Heuristics.d.ts.map +1 -0
- package/dist/ai/Heuristics.js +298 -0
- package/dist/ai/Heuristics.js.map +1 -0
- package/dist/ai/index.d.ts +4 -0
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +2 -0
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/lua.d.ts +21 -0
- package/dist/ai/lua.d.ts.map +1 -1
- package/dist/ai/lua.js +21 -0
- package/dist/ai/lua.js.map +1 -1
- package/dist/ai/score.d.ts +162 -0
- package/dist/ai/score.d.ts.map +1 -0
- package/dist/ai/score.js +147 -0
- package/dist/ai/score.js.map +1 -0
- package/dist/assets/loader.d.ts +18 -4
- package/dist/assets/loader.d.ts.map +1 -1
- package/dist/assets/loader.js +40 -11
- package/dist/assets/loader.js.map +1 -1
- package/dist/audio/Positional.d.ts +125 -0
- package/dist/audio/Positional.d.ts.map +1 -0
- package/dist/audio/Positional.js +135 -0
- package/dist/audio/Positional.js.map +1 -0
- package/dist/audio/Sound.d.ts +7 -1
- package/dist/audio/Sound.d.ts.map +1 -1
- package/dist/audio/Sound.js +8 -2
- package/dist/audio/Sound.js.map +1 -1
- package/dist/audio/index.d.ts +2 -0
- package/dist/audio/index.d.ts.map +1 -1
- package/dist/audio/index.js +1 -0
- package/dist/audio/index.js.map +1 -1
- package/dist/battle/AttackDialog.d.ts +75 -0
- package/dist/battle/AttackDialog.d.ts.map +1 -0
- package/dist/battle/AttackDialog.js +115 -0
- package/dist/battle/AttackDialog.js.map +1 -0
- package/dist/battle/AttackPreview.d.ts +70 -0
- package/dist/battle/AttackPreview.d.ts.map +1 -0
- package/dist/battle/AttackPreview.js +78 -0
- package/dist/battle/AttackPreview.js.map +1 -0
- package/dist/battle/BattleStats.d.ts +45 -0
- package/dist/battle/BattleStats.d.ts.map +1 -0
- package/dist/battle/BattleStats.js +63 -0
- package/dist/battle/BattleStats.js.map +1 -0
- package/dist/battle/UnitSelector.d.ts +72 -0
- package/dist/battle/UnitSelector.d.ts.map +1 -0
- package/dist/battle/UnitSelector.js +117 -0
- package/dist/battle/UnitSelector.js.map +1 -0
- package/dist/battle/Whiteboard.d.ts +50 -0
- package/dist/battle/Whiteboard.d.ts.map +1 -0
- package/dist/battle/Whiteboard.js +94 -0
- package/dist/battle/Whiteboard.js.map +1 -0
- package/dist/battle/index.d.ts +10 -0
- package/dist/battle/index.d.ts.map +1 -1
- package/dist/battle/index.js +5 -0
- package/dist/battle/index.js.map +1 -1
- package/dist/board/Classics.d.ts.map +1 -1
- package/dist/board/Classics.js +51 -39
- package/dist/board/Classics.js.map +1 -1
- package/dist/board/FogOfWar.d.ts +32 -2
- package/dist/board/FogOfWar.d.ts.map +1 -1
- package/dist/board/FogOfWar.js +70 -6
- package/dist/board/FogOfWar.js.map +1 -1
- package/dist/board/HexSkirmish.d.ts.map +1 -1
- package/dist/board/HexSkirmish.js +69 -20
- package/dist/board/HexSkirmish.js.map +1 -1
- package/dist/board/Tactics.d.ts +7 -0
- package/dist/board/Tactics.d.ts.map +1 -1
- package/dist/board/Tactics.js +2 -2
- package/dist/board/Tactics.js.map +1 -1
- package/dist/core/Achievements.d.ts +40 -7
- package/dist/core/Achievements.d.ts.map +1 -1
- package/dist/core/Achievements.js +53 -7
- package/dist/core/Achievements.js.map +1 -1
- package/dist/core/Hex.d.ts +26 -6
- package/dist/core/Hex.d.ts.map +1 -1
- package/dist/core/Hex.js +40 -13
- package/dist/core/Hex.js.map +1 -1
- package/dist/core/Input.d.ts +36 -0
- package/dist/core/Input.d.ts.map +1 -1
- package/dist/core/Input.js +63 -1
- package/dist/core/Input.js.map +1 -1
- package/dist/core/Random.d.ts +93 -0
- package/dist/core/Random.d.ts.map +1 -1
- package/dist/core/Random.js +177 -0
- package/dist/core/Random.js.map +1 -1
- package/dist/core/SyncGuard.d.ts +57 -0
- package/dist/core/SyncGuard.d.ts.map +1 -0
- package/dist/core/SyncGuard.js +116 -0
- package/dist/core/SyncGuard.js.map +1 -0
- package/dist/core/index.d.ts +3 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -1
- package/dist/core/index.js.map +1 -1
- package/dist/i18n/Po.d.ts +51 -0
- package/dist/i18n/Po.d.ts.map +1 -0
- package/dist/i18n/Po.js +176 -0
- package/dist/i18n/Po.js.map +1 -0
- package/dist/i18n/index.d.ts +2 -0
- package/dist/i18n/index.d.ts.map +1 -1
- package/dist/i18n/index.js +1 -0
- package/dist/i18n/index.js.map +1 -1
- package/dist/mw_games.global.js +104 -98
- package/dist/mwl/MapFile.d.ts +41 -0
- package/dist/mwl/MapFile.d.ts.map +1 -0
- package/dist/mwl/MapFile.js +43 -0
- package/dist/mwl/MapFile.js.map +1 -0
- package/dist/mwl/actors.d.ts +46 -2
- package/dist/mwl/actors.d.ts.map +1 -1
- package/dist/mwl/actors.js +46 -2
- package/dist/mwl/actors.js.map +1 -1
- package/dist/mwl/campaign.d.ts +51 -0
- package/dist/mwl/campaign.d.ts.map +1 -0
- package/dist/mwl/campaign.js +58 -0
- package/dist/mwl/campaign.js.map +1 -0
- package/dist/mwl/carryover.d.ts +86 -0
- package/dist/mwl/carryover.d.ts.map +1 -0
- package/dist/mwl/carryover.js +70 -0
- package/dist/mwl/carryover.js.map +1 -0
- package/dist/mwl/catalog.d.ts +10 -1
- package/dist/mwl/catalog.d.ts.map +1 -1
- package/dist/mwl/catalog.js +10 -1
- package/dist/mwl/catalog.js.map +1 -1
- package/dist/mwl/compiler.d.ts +70 -3
- package/dist/mwl/compiler.d.ts.map +1 -1
- package/dist/mwl/compiler.js +70 -3
- package/dist/mwl/compiler.js.map +1 -1
- package/dist/mwl/conditions.d.ts +10 -1
- package/dist/mwl/conditions.d.ts.map +1 -1
- package/dist/mwl/conditions.js +10 -1
- package/dist/mwl/conditions.js.map +1 -1
- package/dist/mwl/content.d.ts +21 -0
- package/dist/mwl/content.d.ts.map +1 -1
- package/dist/mwl/content.js +19 -0
- package/dist/mwl/content.js.map +1 -1
- package/dist/mwl/expression.d.ts +21 -0
- package/dist/mwl/expression.d.ts.map +1 -1
- package/dist/mwl/expression.js +21 -0
- package/dist/mwl/expression.js.map +1 -1
- package/dist/mwl/fengari.d.ts +12 -1
- package/dist/mwl/fengari.d.ts.map +1 -1
- package/dist/mwl/fengari.js +12 -1
- package/dist/mwl/fengari.js.map +1 -1
- package/dist/mwl/grammar.d.ts +45 -1
- package/dist/mwl/grammar.d.ts.map +1 -1
- package/dist/mwl/grammar.js +45 -1
- package/dist/mwl/grammar.js.map +1 -1
- package/dist/mwl/hooks.d.ts +51 -6
- package/dist/mwl/hooks.d.ts.map +1 -1
- package/dist/mwl/hooks.js +45 -1
- package/dist/mwl/hooks.js.map +1 -1
- package/dist/mwl/index.d.ts +9 -3
- package/dist/mwl/index.d.ts.map +1 -1
- package/dist/mwl/index.js +5 -2
- package/dist/mwl/index.js.map +1 -1
- package/dist/mwl/persistence.d.ts +32 -0
- package/dist/mwl/persistence.d.ts.map +1 -1
- package/dist/mwl/persistence.js +32 -0
- package/dist/mwl/persistence.js.map +1 -1
- package/dist/mwl/readers.d.ts +24 -2
- package/dist/mwl/readers.d.ts.map +1 -1
- package/dist/mwl/readers.js +27 -4
- package/dist/mwl/readers.js.map +1 -1
- package/dist/mwl/report.d.ts +21 -2
- package/dist/mwl/report.d.ts.map +1 -1
- package/dist/mwl/report.js +21 -2
- package/dist/mwl/report.js.map +1 -1
- package/dist/mwl/runtime.d.ts +212 -7
- package/dist/mwl/runtime.d.ts.map +1 -1
- package/dist/mwl/runtime.js +682 -90
- package/dist/mwl/runtime.js.map +1 -1
- package/dist/mwl/schema.d.ts +57 -1
- package/dist/mwl/schema.d.ts.map +1 -1
- package/dist/mwl/schema.js +181 -21
- package/dist/mwl/schema.js.map +1 -1
- package/dist/mwl/scripts.d.ts +12 -1
- package/dist/mwl/scripts.d.ts.map +1 -1
- package/dist/mwl/scripts.js +12 -1
- package/dist/mwl/scripts.js.map +1 -1
- package/dist/mwl/utils.d.ts +2 -0
- package/dist/mwl/utils.d.ts.map +1 -1
- package/dist/mwl/utils.js +4 -1
- package/dist/mwl/utils.js.map +1 -1
- package/dist/roguelike/MultiTurnBeam.d.ts +50 -12
- package/dist/roguelike/MultiTurnBeam.d.ts.map +1 -1
- package/dist/roguelike/MultiTurnBeam.js +100 -53
- package/dist/roguelike/MultiTurnBeam.js.map +1 -1
- package/dist/roguelike/Targeting.d.ts +94 -0
- package/dist/roguelike/Targeting.d.ts.map +1 -1
- package/dist/roguelike/Targeting.js +123 -0
- package/dist/roguelike/Targeting.js.map +1 -1
- package/dist/roguelike/index.d.ts +3 -1
- package/dist/roguelike/index.d.ts.map +1 -1
- package/dist/roguelike/index.js +1 -0
- package/dist/roguelike/index.js.map +1 -1
- package/dist/rpg/GameState.d.ts +2 -2
- package/dist/rpg/GameState.js +2 -2
- package/dist/simulation/CampaignSave.d.ts +68 -0
- package/dist/simulation/CampaignSave.d.ts.map +1 -0
- package/dist/simulation/CampaignSave.js +54 -0
- package/dist/simulation/CampaignSave.js.map +1 -0
- package/dist/simulation/EventPresentation.d.ts +111 -0
- package/dist/simulation/EventPresentation.d.ts.map +1 -0
- package/dist/simulation/EventPresentation.js +120 -0
- package/dist/simulation/EventPresentation.js.map +1 -0
- package/dist/simulation/index.d.ts +4 -0
- package/dist/simulation/index.d.ts.map +1 -1
- package/dist/simulation/index.js +2 -0
- package/dist/simulation/index.js.map +1 -1
- package/dist/two-d/pixi-interop.d.ts +18 -6
- package/dist/two-d/pixi-interop.d.ts.map +1 -1
- package/dist/two-d/pixi-interop.js +18 -6
- package/dist/two-d/pixi-interop.js.map +1 -1
- package/dist/two-d/render/AnimatedSprite.d.ts +74 -7
- package/dist/two-d/render/AnimatedSprite.d.ts.map +1 -1
- package/dist/two-d/render/AnimatedSprite.js +88 -26
- package/dist/two-d/render/AnimatedSprite.js.map +1 -1
- package/dist/two-d/render/Camera.d.ts +64 -4
- package/dist/two-d/render/Camera.d.ts.map +1 -1
- package/dist/two-d/render/Camera.js +132 -11
- package/dist/two-d/render/Camera.js.map +1 -1
- package/dist/two-d/render/ColorTransformBatcher.d.ts +7 -1
- package/dist/two-d/render/ColorTransformBatcher.d.ts.map +1 -1
- package/dist/two-d/render/ColorTransformBatcher.js +10 -1
- package/dist/two-d/render/ColorTransformBatcher.js.map +1 -1
- package/dist/two-d/render/Halo.d.ts +58 -0
- package/dist/two-d/render/Halo.d.ts.map +1 -0
- package/dist/two-d/render/Halo.js +48 -0
- package/dist/two-d/render/Halo.js.map +1 -0
- package/dist/two-d/render/ImageModifiers.d.ts +174 -0
- package/dist/two-d/render/ImageModifiers.d.ts.map +1 -1
- package/dist/two-d/render/ImageModifiers.js +454 -1
- package/dist/two-d/render/ImageModifiers.js.map +1 -1
- package/dist/two-d/render/LightningArc.d.ts +57 -0
- package/dist/two-d/render/LightningArc.d.ts.map +1 -0
- package/dist/two-d/render/LightningArc.js +91 -0
- package/dist/two-d/render/LightningArc.js.map +1 -0
- package/dist/two-d/render/PaletteRemap.d.ts +135 -0
- package/dist/two-d/render/PaletteRemap.d.ts.map +1 -0
- package/dist/two-d/render/PaletteRemap.js +181 -0
- package/dist/two-d/render/PaletteRemap.js.map +1 -0
- package/dist/two-d/render/Particles.d.ts +26 -0
- package/dist/two-d/render/Particles.d.ts.map +1 -1
- package/dist/two-d/render/Particles.js +23 -2
- package/dist/two-d/render/Particles.js.map +1 -1
- package/dist/two-d/render/SpriteAttachment.d.ts +55 -0
- package/dist/two-d/render/SpriteAttachment.d.ts.map +1 -0
- package/dist/two-d/render/SpriteAttachment.js +60 -0
- package/dist/two-d/render/SpriteAttachment.js.map +1 -0
- package/dist/two-d/render/TerrainGraphics.d.ts +142 -0
- package/dist/two-d/render/TerrainGraphics.d.ts.map +1 -0
- package/dist/two-d/render/TerrainGraphics.js +161 -0
- package/dist/two-d/render/TerrainGraphics.js.map +1 -0
- package/dist/two-d/render/TerrainGraphicsLayer.d.ts +55 -0
- package/dist/two-d/render/TerrainGraphicsLayer.d.ts.map +1 -0
- package/dist/two-d/render/TerrainGraphicsLayer.js +54 -0
- package/dist/two-d/render/TerrainGraphicsLayer.js.map +1 -0
- package/dist/two-d/render/TintedSprite.js +2 -2
- package/dist/two-d/render/TintedSprite.js.map +1 -1
- package/dist/two-d/render/index.d.ts +15 -3
- package/dist/two-d/render/index.d.ts.map +1 -1
- package/dist/two-d/render/index.js +7 -1
- package/dist/two-d/render/index.js.map +1 -1
- package/dist/two-d/stage/StoryScreen.d.ts +110 -0
- package/dist/two-d/stage/StoryScreen.d.ts.map +1 -0
- package/dist/two-d/stage/StoryScreen.js +178 -0
- package/dist/two-d/stage/StoryScreen.js.map +1 -0
- package/dist/two-d/stage/index.d.ts +2 -0
- package/dist/two-d/stage/index.d.ts.map +1 -1
- package/dist/two-d/stage/index.js +1 -0
- package/dist/two-d/stage/index.js.map +1 -1
- package/dist/two-d/ui/Checkbox.d.ts +44 -0
- package/dist/two-d/ui/Checkbox.d.ts.map +1 -0
- package/dist/two-d/ui/Checkbox.js +89 -0
- package/dist/two-d/ui/Checkbox.js.map +1 -0
- package/dist/two-d/ui/DataTable.d.ts +79 -0
- package/dist/two-d/ui/DataTable.d.ts.map +1 -0
- package/dist/two-d/ui/DataTable.js +164 -0
- package/dist/two-d/ui/DataTable.js.map +1 -0
- package/dist/two-d/ui/Dropdown.d.ts +72 -0
- package/dist/two-d/ui/Dropdown.d.ts.map +1 -0
- package/dist/two-d/ui/Dropdown.js +126 -0
- package/dist/two-d/ui/Dropdown.js.map +1 -0
- package/dist/two-d/ui/FloatingText.d.ts +43 -4
- package/dist/two-d/ui/FloatingText.d.ts.map +1 -1
- package/dist/two-d/ui/FloatingText.js +52 -5
- package/dist/two-d/ui/FloatingText.js.map +1 -1
- package/dist/two-d/ui/FloatingTextStack.d.ts +86 -13
- package/dist/two-d/ui/FloatingTextStack.d.ts.map +1 -1
- package/dist/two-d/ui/FloatingTextStack.js +89 -18
- package/dist/two-d/ui/FloatingTextStack.js.map +1 -1
- package/dist/two-d/ui/Layout.d.ts +105 -0
- package/dist/two-d/ui/Layout.d.ts.map +1 -0
- package/dist/two-d/ui/Layout.js +174 -0
- package/dist/two-d/ui/Layout.js.map +1 -0
- package/dist/two-d/ui/MarkupText.d.ts +53 -0
- package/dist/two-d/ui/MarkupText.d.ts.map +1 -0
- package/dist/two-d/ui/MarkupText.js +122 -0
- package/dist/two-d/ui/MarkupText.js.map +1 -0
- package/dist/two-d/ui/ScrollBox.d.ts +67 -0
- package/dist/two-d/ui/ScrollBox.d.ts.map +1 -0
- package/dist/two-d/ui/ScrollBox.js +127 -0
- package/dist/two-d/ui/ScrollBox.js.map +1 -0
- package/dist/two-d/ui/Skins.d.ts +59 -0
- package/dist/two-d/ui/Skins.d.ts.map +1 -0
- package/dist/two-d/ui/Skins.js +77 -0
- package/dist/two-d/ui/Skins.js.map +1 -0
- package/dist/two-d/ui/Slider.d.ts +91 -0
- package/dist/two-d/ui/Slider.d.ts.map +1 -0
- package/dist/two-d/ui/Slider.js +170 -0
- package/dist/two-d/ui/Slider.js.map +1 -0
- package/dist/two-d/ui/Spinner.d.ts +67 -0
- package/dist/two-d/ui/Spinner.d.ts.map +1 -0
- package/dist/two-d/ui/Spinner.js +137 -0
- package/dist/two-d/ui/Spinner.js.map +1 -0
- package/dist/two-d/ui/TabbedList.d.ts +118 -0
- package/dist/two-d/ui/TabbedList.d.ts.map +1 -0
- package/dist/two-d/ui/TabbedList.js +221 -0
- package/dist/two-d/ui/TabbedList.js.map +1 -0
- package/dist/two-d/ui/TextModel.d.ts +65 -0
- package/dist/two-d/ui/TextModel.d.ts.map +1 -0
- package/dist/two-d/ui/TextModel.js +126 -0
- package/dist/two-d/ui/TextModel.js.map +1 -0
- package/dist/two-d/ui/TreeView.d.ts +68 -0
- package/dist/two-d/ui/TreeView.d.ts.map +1 -0
- package/dist/two-d/ui/TreeView.js +133 -0
- package/dist/two-d/ui/TreeView.js.map +1 -0
- package/dist/two-d/ui/Window.d.ts +13 -0
- package/dist/two-d/ui/Window.d.ts.map +1 -1
- package/dist/two-d/ui/Window.js +23 -0
- package/dist/two-d/ui/Window.js.map +1 -1
- package/dist/two-d/ui/WindowStack.d.ts.map +1 -1
- package/dist/two-d/ui/WindowStack.js +2 -0
- package/dist/two-d/ui/WindowStack.js.map +1 -1
- package/dist/two-d/ui/index.d.ts +29 -3
- package/dist/two-d/ui/index.d.ts.map +1 -1
- package/dist/two-d/ui/index.js +15 -2
- package/dist/two-d/ui/index.js.map +1 -1
- package/dist/two-d/ui/markup.d.ts +181 -0
- package/dist/two-d/ui/markup.d.ts.map +1 -0
- package/dist/two-d/ui/markup.js +370 -0
- package/dist/two-d/ui/markup.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/world/SideTurns.d.ts +115 -0
- package/dist/world/SideTurns.d.ts.map +1 -0
- package/dist/world/SideTurns.js +138 -0
- package/dist/world/SideTurns.js.map +1 -0
- package/dist/world/index.d.ts +2 -0
- package/dist/world/index.d.ts.map +1 -1
- package/dist/world/index.js +1 -0
- package/dist/world/index.js.map +1 -1
- package/package.json +2 -1
|
@@ -1,10 +1,36 @@
|
|
|
1
1
|
import { TintedSprite } from './TintedSprite.ts';
|
|
2
2
|
import type { Texture2D } from './Types2D.ts';
|
|
3
|
+
/**
|
|
4
|
+
* One frame, with its own timing and its own place.
|
|
5
|
+
*
|
|
6
|
+
* A frame may carry its own duration, which is what Wesnoth writes as `image=a.png:120,b.png:80`: a
|
|
7
|
+
* list of frames with how long each is held. It may also sit a few pixels away from where the sprite
|
|
8
|
+
* is - a recoil, a hit shake, a frame drawn high on purpose.
|
|
9
|
+
*/
|
|
10
|
+
export interface AnimationFrame {
|
|
11
|
+
readonly texture: Texture2D;
|
|
12
|
+
/** seconds this frame is held; without it, `AnimationOptions.fps` decides */
|
|
13
|
+
readonly duration?: number;
|
|
14
|
+
/** pixels this frame is drawn away from the sprite's own position */
|
|
15
|
+
readonly offsetX?: number;
|
|
16
|
+
readonly offsetY?: number;
|
|
17
|
+
}
|
|
18
|
+
/** a plain texture is a frame with no timing or offset of its own */
|
|
19
|
+
export type AnimationFrameInput = Texture2D | AnimationFrame;
|
|
3
20
|
export interface AnimationOptions {
|
|
4
|
-
/** frames per second */
|
|
21
|
+
/** frames per second: the duration of every frame that does not carry one of its own */
|
|
5
22
|
fps?: number;
|
|
6
23
|
/** whether to start again at the end, or hold on the last frame */
|
|
7
24
|
loop?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Seconds into its own timeline this animation starts at. Positive holds the first frame that
|
|
27
|
+
* much longer, negative skips that much of the leading frames. The negative case is not a quirk:
|
|
28
|
+
* it is how Wesnoth lines an attack animation up with the frame the damage lands on, by starting
|
|
29
|
+
* mid-swing (`start_time=-450` over frames of 100ms each skips four and a half of them). The
|
|
30
|
+
* offset applies once, when playback starts; a looping animation then cycles on the frames' own
|
|
31
|
+
* length, so the delay does not repeat every lap.
|
|
32
|
+
*/
|
|
33
|
+
startTime?: number;
|
|
8
34
|
}
|
|
9
35
|
/**
|
|
10
36
|
* @example
|
|
@@ -19,11 +45,24 @@ export interface AnimationOptions {
|
|
|
19
45
|
* ```
|
|
20
46
|
*/
|
|
21
47
|
export declare class Animation {
|
|
22
|
-
readonly frames: readonly
|
|
48
|
+
readonly frames: readonly AnimationFrame[];
|
|
49
|
+
/** the duration every frame without one of its own is held for */
|
|
23
50
|
readonly frameDuration: number;
|
|
24
51
|
readonly loop: boolean;
|
|
25
|
-
|
|
26
|
-
|
|
52
|
+
readonly startTime: number;
|
|
53
|
+
/** how long one pass over the frames takes, `startTime` excluded */
|
|
54
|
+
readonly duration: number;
|
|
55
|
+
/** each frame's resolved duration, in order: `frameAt` walks these rather than the frames */
|
|
56
|
+
private readonly times;
|
|
57
|
+
constructor(frames: readonly AnimationFrameInput[], { fps, loop, startTime }?: AnimationOptions);
|
|
58
|
+
/** the frame playing `seconds` in, with `startTime` and `loop` applied */
|
|
59
|
+
frameAt(seconds: number): AnimationFrame;
|
|
60
|
+
/**
|
|
61
|
+
* Which frame plays `seconds` in. Before it starts the first frame is held, however long that
|
|
62
|
+
* is, and a non-looping animation that has run out stays on its last frame rather than running
|
|
63
|
+
* off the end.
|
|
64
|
+
*/
|
|
65
|
+
frameIndexAt(seconds: number): number;
|
|
27
66
|
}
|
|
28
67
|
/**
|
|
29
68
|
* A sprite that plays named animations, and can still be tinted.
|
|
@@ -34,6 +73,14 @@ export declare class Animation {
|
|
|
34
73
|
* Nothing advances on its own: call `update(dt)` from the scene, or add the sprite to a
|
|
35
74
|
* `SpriteGroup`, so that pausing the game pauses the animations with it.
|
|
36
75
|
*
|
|
76
|
+
* Frames may carry their own duration, and the animation may start partway into itself, which is
|
|
77
|
+
* what Wesnoth's `image=a.png:120,b.png:80` and `start_time=-450` mean. A frame may also carry an
|
|
78
|
+
* offset, so a swing recoils a few pixels without a second texture: `frameOffset` reports it, and
|
|
79
|
+
* the *caller* adds it where it already positions the sprite. The framework does not apply it
|
|
80
|
+
* itself, on purpose - this sprite's position belongs to whoever put it there (a `GridMover`, a
|
|
81
|
+
* walk tween, a camera projection), and a sprite that overwrote `y` every frame would undo that
|
|
82
|
+
* every frame. `FloatingText` learned the same rule the hard way.
|
|
83
|
+
*
|
|
37
84
|
* Reduced motion deliberately does not pause this. A frame cycle is usually game state - a
|
|
38
85
|
* walking enemy that freezes when the player has asked for less motion is a bug, not an
|
|
39
86
|
* accommodation, and the article's own "Don't Reduce Too Much" is about exactly this. A game
|
|
@@ -54,6 +101,14 @@ export declare class Animation {
|
|
|
54
101
|
* hero.add('idle', sheet.pick(0, 0, 0, 1), { fps: 2 });
|
|
55
102
|
* hero.add('walk', sheet.range(6, 10), { fps: 10 });
|
|
56
103
|
* hero.add('die', sheet.range(11, 14), { fps: 10, loop: false });
|
|
104
|
+
* hero.add(
|
|
105
|
+
* 'thrust',
|
|
106
|
+
* [
|
|
107
|
+
* { texture: sheet.get(20), duration: 0.4 },
|
|
108
|
+
* { texture: sheet.get(21), duration: 0.1, offsetX: 3 }, // the lunge
|
|
109
|
+
* ],
|
|
110
|
+
* { startTime: -0.2 },
|
|
111
|
+
* );
|
|
57
112
|
* hero.play('idle');
|
|
58
113
|
*
|
|
59
114
|
* hero.onFinish = (name) => console.log(`${name} finished`);
|
|
@@ -64,16 +119,27 @@ export declare class AnimatedSprite extends TintedSprite {
|
|
|
64
119
|
private animations;
|
|
65
120
|
private current;
|
|
66
121
|
private currentName;
|
|
67
|
-
private
|
|
68
|
-
private timer;
|
|
122
|
+
private elapsed;
|
|
69
123
|
private finished;
|
|
124
|
+
private readonly offset;
|
|
70
125
|
/** fires once when a non-looping animation reaches its last frame */
|
|
71
126
|
onFinish: ((name: string) => void) | null;
|
|
72
127
|
paused: boolean;
|
|
73
|
-
add(name: string, frames: readonly
|
|
128
|
+
add(name: string, frames: readonly AnimationFrameInput[], options?: AnimationOptions): this;
|
|
74
129
|
has(name: string): boolean;
|
|
75
130
|
get playing(): string | null;
|
|
76
131
|
get isFinished(): boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Where the current frame is drawn relative to the sprite's own position, in pixels. The caller
|
|
134
|
+
* adds it, as in `sprite.position.set(x + sprite.frameOffset.x, y + sprite.frameOffset.y)`. Both
|
|
135
|
+
* are zero for a frame with no offset of its own.
|
|
136
|
+
*/
|
|
137
|
+
get frameOffset(): {
|
|
138
|
+
readonly x: number;
|
|
139
|
+
readonly y: number;
|
|
140
|
+
};
|
|
141
|
+
/** how long the current animation has been running, `startTime` and all */
|
|
142
|
+
get elapsedTime(): number;
|
|
77
143
|
/**
|
|
78
144
|
* Starts an animation.
|
|
79
145
|
*
|
|
@@ -83,5 +149,6 @@ export declare class AnimatedSprite extends TintedSprite {
|
|
|
83
149
|
play(name: string, restart?: boolean): this;
|
|
84
150
|
stop(): void;
|
|
85
151
|
update(dt: number): void;
|
|
152
|
+
private show;
|
|
86
153
|
}
|
|
87
154
|
//# sourceMappingURL=AnimatedSprite.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnimatedSprite.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/AnimatedSprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,WAAW,gBAAgB;IAChC,
|
|
1
|
+
{"version":3,"file":"AnimatedSprite.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/AnimatedSprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC;IAE5B,6EAA6E;IAC7E,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAE3B,qEAAqE;IACrE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,qEAAqE;AACrE,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,cA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EjD,MAAM,UAAS;IAEf,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,mBAAmB,EAAE,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAG1F;IAED,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzB;IAED,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAE3B;IAED,IAAI,UAAU,IAAI,OAAO,CAExB;IAED;;;;OAIG;IACH,IAAI,WAAW,IAAI;QAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAE5D;IAED,2EAA2E;IAC3E,IAAI,WAAW,IAAI,MAAM,CAExB;IAED;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,IAAI,CAaxC;IAED,IAAI,IAAI,IAAI,CAGX;IAED,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAavB;IAED,OAAO,CAAC,IAAI;CAKZ"}
|
|
@@ -12,17 +12,57 @@ import { TintedSprite } from './TintedSprite.js';
|
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
14
|
export class Animation {
|
|
15
|
-
constructor(frames, { fps = 10, loop = true } = {}) {
|
|
15
|
+
constructor(frames, { fps = 10, loop = true, startTime = 0 } = {}) {
|
|
16
16
|
if (frames.length === 0)
|
|
17
17
|
throw new Error('an animation needs at least one frame');
|
|
18
|
-
|
|
18
|
+
if (!(fps > 0))
|
|
19
|
+
throw new Error(`an animation needs a positive fps, got ${fps}`);
|
|
19
20
|
this.frameDuration = 1 / fps;
|
|
21
|
+
this.frames = frames.map((frame) => (isFrame(frame) ? frame : { texture: frame }));
|
|
22
|
+
this.times = this.frames.map((frame) => frame.duration ?? this.frameDuration);
|
|
20
23
|
this.loop = loop;
|
|
24
|
+
this.startTime = startTime;
|
|
25
|
+
//the frames that borrow the fps are multiplied rather than added one by one: ten frames at a
|
|
26
|
+
//tenth of a second are exactly a second, where summing ten copies of 0.1 lands an ulp away
|
|
27
|
+
//from it. This total is what a loop wraps on and what a one-shot animation is timed against
|
|
28
|
+
let uniform = 0;
|
|
29
|
+
let timed = 0;
|
|
30
|
+
for (const frame of this.frames) {
|
|
31
|
+
if (frame.duration === undefined)
|
|
32
|
+
uniform++;
|
|
33
|
+
else
|
|
34
|
+
timed += frame.duration;
|
|
35
|
+
}
|
|
36
|
+
this.duration = uniform * this.frameDuration + timed;
|
|
37
|
+
}
|
|
38
|
+
/** the frame playing `seconds` in, with `startTime` and `loop` applied */
|
|
39
|
+
frameAt(seconds) {
|
|
40
|
+
return this.frames[this.frameIndexAt(seconds)];
|
|
21
41
|
}
|
|
22
|
-
|
|
23
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Which frame plays `seconds` in. Before it starts the first frame is held, however long that
|
|
44
|
+
* is, and a non-looping animation that has run out stays on its last frame rather than running
|
|
45
|
+
* off the end.
|
|
46
|
+
*/
|
|
47
|
+
frameIndexAt(seconds) {
|
|
48
|
+
const elapsed = seconds - this.startTime;
|
|
49
|
+
if (elapsed <= 0)
|
|
50
|
+
return 0;
|
|
51
|
+
const total = this.duration;
|
|
52
|
+
if (total <= 0)
|
|
53
|
+
return this.frames.length - 1;
|
|
54
|
+
let time = this.loop ? elapsed % total : Math.min(elapsed, total);
|
|
55
|
+
for (let index = 0; index < this.times.length; index++) {
|
|
56
|
+
if (time < this.times[index])
|
|
57
|
+
return index;
|
|
58
|
+
time -= this.times[index];
|
|
59
|
+
}
|
|
60
|
+
return this.frames.length - 1;
|
|
24
61
|
}
|
|
25
62
|
}
|
|
63
|
+
function isFrame(frame) {
|
|
64
|
+
return typeof frame.texture !== 'undefined';
|
|
65
|
+
}
|
|
26
66
|
/**
|
|
27
67
|
* A sprite that plays named animations, and can still be tinted.
|
|
28
68
|
*
|
|
@@ -32,6 +72,14 @@ export class Animation {
|
|
|
32
72
|
* Nothing advances on its own: call `update(dt)` from the scene, or add the sprite to a
|
|
33
73
|
* `SpriteGroup`, so that pausing the game pauses the animations with it.
|
|
34
74
|
*
|
|
75
|
+
* Frames may carry their own duration, and the animation may start partway into itself, which is
|
|
76
|
+
* what Wesnoth's `image=a.png:120,b.png:80` and `start_time=-450` mean. A frame may also carry an
|
|
77
|
+
* offset, so a swing recoils a few pixels without a second texture: `frameOffset` reports it, and
|
|
78
|
+
* the *caller* adds it where it already positions the sprite. The framework does not apply it
|
|
79
|
+
* itself, on purpose - this sprite's position belongs to whoever put it there (a `GridMover`, a
|
|
80
|
+
* walk tween, a camera projection), and a sprite that overwrote `y` every frame would undo that
|
|
81
|
+
* every frame. `FloatingText` learned the same rule the hard way.
|
|
82
|
+
*
|
|
35
83
|
* Reduced motion deliberately does not pause this. A frame cycle is usually game state - a
|
|
36
84
|
* walking enemy that freezes when the player has asked for less motion is a bug, not an
|
|
37
85
|
* accommodation, and the article's own "Don't Reduce Too Much" is about exactly this. A game
|
|
@@ -52,6 +100,14 @@ export class Animation {
|
|
|
52
100
|
* hero.add('idle', sheet.pick(0, 0, 0, 1), { fps: 2 });
|
|
53
101
|
* hero.add('walk', sheet.range(6, 10), { fps: 10 });
|
|
54
102
|
* hero.add('die', sheet.range(11, 14), { fps: 10, loop: false });
|
|
103
|
+
* hero.add(
|
|
104
|
+
* 'thrust',
|
|
105
|
+
* [
|
|
106
|
+
* { texture: sheet.get(20), duration: 0.4 },
|
|
107
|
+
* { texture: sheet.get(21), duration: 0.1, offsetX: 3 }, // the lunge
|
|
108
|
+
* ],
|
|
109
|
+
* { startTime: -0.2 },
|
|
110
|
+
* );
|
|
55
111
|
* hero.play('idle');
|
|
56
112
|
*
|
|
57
113
|
* hero.onFinish = (name) => console.log(`${name} finished`);
|
|
@@ -64,9 +120,9 @@ export class AnimatedSprite extends TintedSprite {
|
|
|
64
120
|
this.animations = new Map();
|
|
65
121
|
this.current = null;
|
|
66
122
|
this.currentName = null;
|
|
67
|
-
this.
|
|
68
|
-
this.timer = 0;
|
|
123
|
+
this.elapsed = 0;
|
|
69
124
|
this.finished = false;
|
|
125
|
+
this.offset = { x: 0, y: 0 };
|
|
70
126
|
/** fires once when a non-looping animation reaches its last frame */
|
|
71
127
|
this.onFinish = null;
|
|
72
128
|
this.paused = false;
|
|
@@ -84,6 +140,18 @@ export class AnimatedSprite extends TintedSprite {
|
|
|
84
140
|
get isFinished() {
|
|
85
141
|
return this.finished;
|
|
86
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Where the current frame is drawn relative to the sprite's own position, in pixels. The caller
|
|
145
|
+
* adds it, as in `sprite.position.set(x + sprite.frameOffset.x, y + sprite.frameOffset.y)`. Both
|
|
146
|
+
* are zero for a frame with no offset of its own.
|
|
147
|
+
*/
|
|
148
|
+
get frameOffset() {
|
|
149
|
+
return this.offset;
|
|
150
|
+
}
|
|
151
|
+
/** how long the current animation has been running, `startTime` and all */
|
|
152
|
+
get elapsedTime() {
|
|
153
|
+
return this.elapsed;
|
|
154
|
+
}
|
|
87
155
|
/**
|
|
88
156
|
* Starts an animation.
|
|
89
157
|
*
|
|
@@ -98,10 +166,9 @@ export class AnimatedSprite extends TintedSprite {
|
|
|
98
166
|
throw new Error(`no animation named "${name}" on this sprite`);
|
|
99
167
|
this.current = animation;
|
|
100
168
|
this.currentName = name;
|
|
101
|
-
this.
|
|
102
|
-
this.timer = 0;
|
|
169
|
+
this.elapsed = 0;
|
|
103
170
|
this.finished = false;
|
|
104
|
-
this.
|
|
171
|
+
this.show(animation.frameAt(0));
|
|
105
172
|
return this;
|
|
106
173
|
}
|
|
107
174
|
stop() {
|
|
@@ -112,24 +179,19 @@ export class AnimatedSprite extends TintedSprite {
|
|
|
112
179
|
const animation = this.current;
|
|
113
180
|
if (!animation || this.paused || this.finished)
|
|
114
181
|
return;
|
|
115
|
-
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
else if (animation.loop) {
|
|
124
|
-
this.frameIndex = 0;
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
this.finished = true;
|
|
128
|
-
this.onFinish?.(this.currentName);
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
182
|
+
//elapsed rather than a leftover timer: one long frame lands on the right frame instead of
|
|
183
|
+
//catching up through each of them, which keeps two sprites started together in step
|
|
184
|
+
this.elapsed += dt;
|
|
185
|
+
this.show(animation.frameAt(this.elapsed));
|
|
186
|
+
if (!animation.loop && this.elapsed >= animation.startTime + animation.duration) {
|
|
187
|
+
this.finished = true;
|
|
188
|
+
this.onFinish?.(this.currentName);
|
|
131
189
|
}
|
|
132
|
-
|
|
190
|
+
}
|
|
191
|
+
show(frame) {
|
|
192
|
+
this.texture = frame.texture;
|
|
193
|
+
this.offset.x = frame.offsetX ?? 0;
|
|
194
|
+
this.offset.y = frame.offsetY ?? 0;
|
|
133
195
|
}
|
|
134
196
|
}
|
|
135
197
|
//# sourceMappingURL=AnimatedSprite.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnimatedSprite.js","sourceRoot":"","sources":["../../../src/two-d/render/AnimatedSprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"AnimatedSprite.js","sourceRoot":"","sources":["../../../src/two-d/render/AnimatedSprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AA0CjD;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,SAAS;IAerB,YACC,MAAsC,EACtC,EAAE,GAAG,GAAG,EAAE,EAAE,IAAI,GAAG,IAAI,EAAE,SAAS,GAAG,CAAC,EAAE,GAAqB,EAAE;QAE/D,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAClF,IAAI,CAAC,CAAC,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ACH,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IACzB,CAAC;IAED,MAAM,CAAC,EAAU;QAChB,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO;QAEvD,0FAA0F;QAC1F,oFAAoF;QACpF,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;QACnB,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QAE3C,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,IAAI,SAAS,CAAC,SAAS,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;YACjF,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,WAAY,CAAC,CAAC;QACpC,CAAC;IACF,CAAC;IAEO,IAAI,CAAC,KAAqB;QACjC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;QACnC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;IACpC,CAAC;CACD"}
|
|
@@ -4,10 +4,20 @@ import { Container } from 'pixi.js';
|
|
|
4
4
|
*
|
|
5
5
|
* The camera does not move: it moves the world under a fixed viewport, which is what a
|
|
6
6
|
* renderer actually wants. `world` is the container to put the map and its inhabitants in;
|
|
7
|
-
* anything that should stay put on screen (the HUD, a dialogue box) goes outside it.
|
|
7
|
+
* anything that should stay put on screen (the HUD, a dialogue box) goes outside it. The
|
|
8
|
+
* same answers "does rotation turn the camera or the world": the layer turns, once, about
|
|
9
|
+
* the view centre - never a per-tile transform, which is what keeps rotated tiles seamless
|
|
10
|
+
* and the per-frame cost flat regardless of map size.
|
|
8
11
|
*
|
|
9
12
|
* Positions are in world units. At `zoom = 3` a 16px tile is 48 screen pixels.
|
|
10
13
|
*
|
|
14
|
+
* Rotation has two APIs sharing one angle: `setRotationStep`/`rotate` turn in the whole
|
|
15
|
+
* steps a grid closes on (item 285 - four quarter turns for a square map, six 60-degree
|
|
16
|
+
* steps for a hex one), while `rotateTo`/`animateRotationTo` turn to any angle at all (item
|
|
17
|
+
* 286), animating smoothly between two steps rather than only landing on them. `toScreen`/
|
|
18
|
+
* `toWorld`/`view`'s culling box already work at any angle, not only a step's whole
|
|
19
|
+
* multiple, so free rotation needed no change to either.
|
|
20
|
+
*
|
|
11
21
|
* @example
|
|
12
22
|
* ```ts
|
|
13
23
|
* import { Camera, createCamera } from '@datamoc/mw_games/two-d/render';
|
|
@@ -28,6 +38,13 @@ import { Container } from 'pixi.js';
|
|
|
28
38
|
export interface CameraOptions {
|
|
29
39
|
/** screen pixels per world unit */
|
|
30
40
|
zoom?: number;
|
|
41
|
+
/**
|
|
42
|
+
* The grid whose symmetry `rotate`/`setRotationStep` step in: `'square'` (the default)
|
|
43
|
+
* turns in four quarter turns, `'hex'` in six 60-degree steps, because a hex lattice comes
|
|
44
|
+
* back onto itself every 60 degrees. Only the step count depends on this; the layer and its
|
|
45
|
+
* inverse mapping are the same shape either way.
|
|
46
|
+
*/
|
|
47
|
+
grid?: 'square' | 'hex';
|
|
31
48
|
/**
|
|
32
49
|
* How much of the screen the target may drift across before the camera follows, 0 to 1.
|
|
33
50
|
*
|
|
@@ -91,7 +108,43 @@ export declare class Camera {
|
|
|
91
108
|
private shakeY;
|
|
92
109
|
/** clamps the view to these world bounds when set, so the map's edge is never crossed */
|
|
93
110
|
private bounds;
|
|
111
|
+
/** how many whole-angle positions a full turn has: 4 for a square grid, 6 for a hex one */
|
|
112
|
+
readonly stepsPerTurn: number;
|
|
113
|
+
private step;
|
|
114
|
+
private _angle;
|
|
115
|
+
private targetAngle;
|
|
116
|
+
private angleIntensity;
|
|
94
117
|
constructor(options?: CameraOptions);
|
|
118
|
+
/** the rotation step this view is turned to, always in `0 .. stepsPerTurn - 1` */
|
|
119
|
+
get rotationSteps(): number;
|
|
120
|
+
/** the view's rotation, in radians, positive turning the world counter-clockwise */
|
|
121
|
+
get rotation(): number;
|
|
122
|
+
/**
|
|
123
|
+
* The angle that cancels `rotation`: draw a label, health bar or damage number into `world`
|
|
124
|
+
* with this and it stays upright however the view is turned. A half turn would otherwise put
|
|
125
|
+
* every label upside down.
|
|
126
|
+
*/
|
|
127
|
+
get uprightRotation(): number;
|
|
128
|
+
/** turns the view to a whole step, wrapping around a full turn */
|
|
129
|
+
setRotationStep(step: number): void;
|
|
130
|
+
/** turns the view by whole steps; `rotate(1)` is the next position, `rotate(-1)` the last */
|
|
131
|
+
rotate(delta?: number): void;
|
|
132
|
+
/**
|
|
133
|
+
* Turns the view to an arbitrary angle immediately, no animation - free rotation, not
|
|
134
|
+
* confined to a grid's whole steps. `rotationSteps` is left as it was: it names where
|
|
135
|
+
* `setRotationStep`/`rotate` last put the view, not this angle, so the two APIs are best
|
|
136
|
+
* used one at a time rather than interleaved.
|
|
137
|
+
*/
|
|
138
|
+
rotateTo(angle: number): void;
|
|
139
|
+
/**
|
|
140
|
+
* Eases the view towards an arbitrary angle, taking whichever way around the turn is
|
|
141
|
+
* shorter - so animating from a hex view's fifth step back to its first sweeps the one
|
|
142
|
+
* 60-degree gap between them rather than the long way around. `intensity` behaves like
|
|
143
|
+
* `follow`'s: the remaining angle closes by that fraction each second.
|
|
144
|
+
*/
|
|
145
|
+
animateRotationTo(angle: number, intensity?: number): void;
|
|
146
|
+
/** cos/sin of the current rotation, the shared arithmetic `toScreen`/`toWorld`/`view` use */
|
|
147
|
+
private get spin();
|
|
95
148
|
get zoom(): number;
|
|
96
149
|
set zoom(value: number);
|
|
97
150
|
/**
|
|
@@ -101,7 +154,14 @@ export declare class Camera {
|
|
|
101
154
|
* the screen instead, for a split-screen layout.
|
|
102
155
|
*/
|
|
103
156
|
setViewport(width: number, height: number, screenX?: number, screenY?: number): void;
|
|
104
|
-
/**
|
|
157
|
+
/**
|
|
158
|
+
* The visible region, in world units, as an axis-aligned box: use it to cull.
|
|
159
|
+
*
|
|
160
|
+
* With the view turned, the visible region is the viewport rectangle rotated in world space,
|
|
161
|
+
* so this is the box around its four corners instead of the rectangle itself - over-inclusive
|
|
162
|
+
* rather than clipping tiles that are actually on screen. Unturned, it is the rectangle, at
|
|
163
|
+
* its exact numbers.
|
|
164
|
+
*/
|
|
105
165
|
get view(): {
|
|
106
166
|
x: number;
|
|
107
167
|
y: number;
|
|
@@ -128,12 +188,12 @@ export declare class Camera {
|
|
|
128
188
|
/** @param magnitude world units @param duration seconds */
|
|
129
189
|
shake(magnitude: number, duration?: number): void;
|
|
130
190
|
update(dt: number): void;
|
|
131
|
-
/** world point to screen pixels */
|
|
191
|
+
/** world point to screen pixels, through the current rotation */
|
|
132
192
|
toScreen(x: number, y: number): {
|
|
133
193
|
x: number;
|
|
134
194
|
y: number;
|
|
135
195
|
};
|
|
136
|
-
/** screen pixels to world point, for turning a click into a tile */
|
|
196
|
+
/** screen pixels to world point, for turning a click into a tile; the inverse of `toScreen` */
|
|
137
197
|
toWorld(x: number, y: number): {
|
|
138
198
|
x: number;
|
|
139
199
|
y: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Camera.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/Camera.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAKpC
|
|
1
|
+
{"version":3,"file":"Camera.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/Camera.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAKpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MA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