@datamoc/mw_games 0.4.1 → 0.4.3
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/README.md +2 -2
- package/dist/actors/ItemStatusEffect.d.ts +1 -1
- package/dist/actors/ItemStatusEffect.d.ts.map +1 -1
- package/dist/actors/ItemStatusEffect.js +2 -11
- package/dist/actors/ItemStatusEffect.js.map +1 -1
- package/dist/actors/StatusEffect.d.ts +11 -0
- package/dist/actors/StatusEffect.d.ts.map +1 -1
- package/dist/actors/StatusEffect.js +21 -8
- package/dist/actors/StatusEffect.js.map +1 -1
- package/dist/assets/binary.d.ts +52 -0
- package/dist/assets/binary.d.ts.map +1 -0
- package/dist/assets/binary.js +57 -0
- package/dist/assets/binary.js.map +1 -0
- package/dist/assets/index.d.ts +10 -5
- package/dist/assets/index.d.ts.map +1 -1
- package/dist/assets/index.js +9 -5
- package/dist/assets/index.js.map +1 -1
- package/dist/board/Army.d.ts +75 -0
- package/dist/board/Army.d.ts.map +1 -1
- package/dist/board/Army.js +75 -0
- package/dist/board/Army.js.map +1 -1
- package/dist/board/Classics.d.ts +297 -1
- package/dist/board/Classics.d.ts.map +1 -1
- package/dist/board/Classics.js +297 -1
- package/dist/board/Classics.js.map +1 -1
- package/dist/board/Engine.d.ts +23 -0
- package/dist/board/Engine.d.ts.map +1 -1
- package/dist/board/Engine.js +23 -0
- package/dist/board/Engine.js.map +1 -1
- package/dist/board/FogOfWar.d.ts +20 -0
- package/dist/board/FogOfWar.d.ts.map +1 -1
- package/dist/board/FogOfWar.js +20 -0
- package/dist/board/FogOfWar.js.map +1 -1
- package/dist/board/Tactics.d.ts +158 -1
- package/dist/board/Tactics.d.ts.map +1 -1
- package/dist/board/Tactics.js +125 -1
- package/dist/board/Tactics.js.map +1 -1
- package/dist/board/chess.d.ts +87 -3
- package/dist/board/chess.d.ts.map +1 -1
- package/dist/board/chess.js +96 -4
- package/dist/board/chess.js.map +1 -1
- package/dist/core/HttpTransport.d.ts +1 -1
- package/dist/core/HttpTransport.js +1 -1
- package/dist/core/News.d.ts +6 -13
- package/dist/core/News.d.ts.map +1 -1
- package/dist/core/News.js +10 -23
- package/dist/core/News.js.map +1 -1
- package/dist/core/RunHistory.d.ts +1 -2
- package/dist/core/RunHistory.d.ts.map +1 -1
- package/dist/core/RunHistory.js +5 -6
- package/dist/core/RunHistory.js.map +1 -1
- package/dist/core/Stats.d.ts +1 -2
- package/dist/core/Stats.d.ts.map +1 -1
- package/dist/core/Stats.js +5 -6
- package/dist/core/Stats.js.map +1 -1
- package/dist/core/StoredValue.d.ts +21 -0
- package/dist/core/StoredValue.d.ts.map +1 -0
- package/dist/core/StoredValue.js +28 -0
- package/dist/core/StoredValue.js.map +1 -0
- package/dist/i18n/Content.d.ts +151 -0
- package/dist/i18n/Content.d.ts.map +1 -0
- package/dist/i18n/Content.js +219 -0
- package/dist/i18n/Content.js.map +1 -0
- package/dist/i18n/index.d.ts +35 -3
- package/dist/i18n/index.d.ts.map +1 -1
- package/dist/i18n/index.js +88 -6
- package/dist/i18n/index.js.map +1 -1
- package/dist/mw_games.global.js +90 -90
- package/dist/roguelike/Level.d.ts +10 -0
- package/dist/roguelike/Level.d.ts.map +1 -1
- package/dist/roguelike/Level.js +57 -17
- package/dist/roguelike/Level.js.map +1 -1
- package/dist/roguelike/Pathfinder.js +19 -19
- package/dist/roguelike/Pathfinder.js.map +1 -1
- package/dist/roguelike/Placement.d.ts +62 -0
- package/dist/roguelike/Placement.d.ts.map +1 -0
- package/dist/roguelike/Placement.js +79 -0
- package/dist/roguelike/Placement.js.map +1 -0
- package/dist/roguelike/index.d.ts +2 -0
- 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/FreeMover.d.ts +1 -1
- package/dist/rpg/FreeMover.d.ts.map +1 -1
- package/dist/rpg/FreeMover.js +3 -6
- package/dist/rpg/FreeMover.js.map +1 -1
- package/dist/rpg/GridMover.d.ts +1 -1
- package/dist/rpg/GridMover.d.ts.map +1 -1
- package/dist/rpg/GridMover.js +3 -6
- package/dist/rpg/GridMover.js.map +1 -1
- package/dist/rpg/MovableSprite.d.ts +6 -0
- package/dist/rpg/MovableSprite.d.ts.map +1 -1
- package/dist/rpg/MovableSprite.js +9 -1
- package/dist/rpg/MovableSprite.js.map +1 -1
- package/dist/three-d/Models.d.ts +38 -1
- package/dist/three-d/Models.d.ts.map +1 -1
- package/dist/three-d/Models.js +66 -3
- package/dist/three-d/Models.js.map +1 -1
- package/dist/two-d/render/ActorAnimator.d.ts +32 -0
- package/dist/two-d/render/ActorAnimator.d.ts.map +1 -1
- package/dist/two-d/render/ActorAnimator.js +21 -0
- package/dist/two-d/render/ActorAnimator.js.map +1 -1
- package/dist/two-d/render/AnimatedSprite.d.ts +24 -4
- package/dist/two-d/render/AnimatedSprite.d.ts.map +1 -1
- package/dist/two-d/render/AnimatedSprite.js +24 -4
- package/dist/two-d/render/AnimatedSprite.js.map +1 -1
- package/dist/two-d/render/Autotile.d.ts +33 -1
- package/dist/two-d/render/Autotile.d.ts.map +1 -1
- package/dist/two-d/render/Autotile.js +33 -1
- package/dist/two-d/render/Autotile.js.map +1 -1
- package/dist/two-d/render/Camera.d.ts +53 -1
- package/dist/two-d/render/Camera.d.ts.map +1 -1
- package/dist/two-d/render/Camera.js +36 -1
- package/dist/two-d/render/Camera.js.map +1 -1
- package/dist/two-d/render/Capabilities.d.ts +33 -0
- package/dist/two-d/render/Capabilities.d.ts.map +1 -1
- package/dist/two-d/render/Capabilities.js +33 -0
- package/dist/two-d/render/Capabilities.js.map +1 -1
- package/dist/two-d/render/ColorBlindness.d.ts +23 -0
- package/dist/two-d/render/ColorBlindness.d.ts.map +1 -1
- package/dist/two-d/render/ColorBlindness.js +23 -4
- package/dist/two-d/render/ColorBlindness.js.map +1 -1
- package/dist/two-d/render/ColorTransformBatcher.d.ts +67 -1
- package/dist/two-d/render/ColorTransformBatcher.d.ts.map +1 -1
- package/dist/two-d/render/ColorTransformBatcher.js +57 -1
- package/dist/two-d/render/ColorTransformBatcher.js.map +1 -1
- package/dist/two-d/render/LayeredSprite.d.ts +19 -0
- package/dist/two-d/render/LayeredSprite.d.ts.map +1 -1
- package/dist/two-d/render/LayeredSprite.js +19 -0
- package/dist/two-d/render/LayeredSprite.js.map +1 -1
- package/dist/two-d/render/Minimap.d.ts +25 -1
- package/dist/two-d/render/Minimap.d.ts.map +1 -1
- package/dist/two-d/render/Minimap.js +25 -1
- package/dist/two-d/render/Minimap.js.map +1 -1
- package/dist/two-d/render/Particles.d.ts +26 -2
- package/dist/two-d/render/Particles.d.ts.map +1 -1
- package/dist/two-d/render/Particles.js +23 -0
- package/dist/two-d/render/Particles.js.map +1 -1
- package/dist/two-d/render/Projectile.d.ts +14 -0
- package/dist/two-d/render/Projectile.d.ts.map +1 -1
- package/dist/two-d/render/Projectile.js +14 -0
- package/dist/two-d/render/Projectile.js.map +1 -1
- package/dist/two-d/render/ScreenEffects.d.ts +15 -0
- package/dist/two-d/render/ScreenEffects.d.ts.map +1 -1
- package/dist/two-d/render/ScreenEffects.js +15 -0
- package/dist/two-d/render/ScreenEffects.js.map +1 -1
- package/dist/two-d/render/Shape2D.d.ts +58 -1
- package/dist/two-d/render/Shape2D.d.ts.map +1 -1
- package/dist/two-d/render/Shape2D.js +58 -1
- package/dist/two-d/render/Shape2D.js.map +1 -1
- package/dist/two-d/render/StatusVisuals.d.ts +22 -0
- package/dist/two-d/render/StatusVisuals.d.ts.map +1 -1
- package/dist/two-d/render/StatusVisuals.js +22 -0
- package/dist/two-d/render/StatusVisuals.js.map +1 -1
- package/dist/two-d/render/TileMap.d.ts +65 -3
- package/dist/two-d/render/TileMap.d.ts.map +1 -1
- package/dist/two-d/render/TileMap.js +65 -3
- package/dist/two-d/render/TileMap.js.map +1 -1
- package/dist/two-d/render/TiledMap.d.ts +9 -3
- package/dist/two-d/render/TiledMap.d.ts.map +1 -1
- package/dist/two-d/render/TiledMap.js +9 -3
- package/dist/two-d/render/TiledMap.js.map +1 -1
- package/dist/two-d/render/TintedSprite.d.ts +9 -2
- package/dist/two-d/render/TintedSprite.d.ts.map +1 -1
- package/dist/two-d/render/TintedSprite.js +9 -2
- package/dist/two-d/render/TintedSprite.js.map +1 -1
- package/dist/two-d/render/Types2D.d.ts +14 -2
- package/dist/two-d/render/Types2D.d.ts.map +1 -1
- package/dist/two-d/render/Types2D.js +14 -2
- package/dist/two-d/render/Types2D.js.map +1 -1
- package/dist/two-d/render/Viewport.d.ts +22 -0
- package/dist/two-d/render/Viewport.d.ts.map +1 -1
- package/dist/two-d/render/Viewport.js +22 -0
- package/dist/two-d/render/Viewport.js.map +1 -1
- package/dist/two-d/ui/Bar.d.ts +16 -3
- package/dist/two-d/ui/Bar.d.ts.map +1 -1
- package/dist/two-d/ui/Bar.js +16 -1
- package/dist/two-d/ui/Bar.js.map +1 -1
- package/dist/two-d/ui/BitmapLabel.d.ts +26 -10
- package/dist/two-d/ui/BitmapLabel.d.ts.map +1 -1
- package/dist/two-d/ui/BitmapLabel.js +26 -3
- package/dist/two-d/ui/BitmapLabel.js.map +1 -1
- package/dist/two-d/ui/Button.d.ts +15 -0
- package/dist/two-d/ui/Button.d.ts.map +1 -1
- package/dist/two-d/ui/Button.js +15 -0
- package/dist/two-d/ui/Button.js.map +1 -1
- package/dist/two-d/ui/FloatingText.d.ts +15 -0
- package/dist/two-d/ui/FloatingText.d.ts.map +1 -1
- package/dist/two-d/ui/FloatingText.js +15 -0
- package/dist/two-d/ui/FloatingText.js.map +1 -1
- package/dist/two-d/ui/HelpScreen.d.ts +16 -0
- package/dist/two-d/ui/HelpScreen.d.ts.map +1 -1
- package/dist/two-d/ui/HelpScreen.js +23 -3
- package/dist/two-d/ui/HelpScreen.js.map +1 -1
- package/dist/two-d/ui/IconGrid.d.ts +27 -3
- package/dist/two-d/ui/IconGrid.d.ts.map +1 -1
- package/dist/two-d/ui/IconGrid.js +71 -55
- package/dist/two-d/ui/IconGrid.js.map +1 -1
- package/dist/two-d/ui/Label.d.ts +12 -8
- package/dist/two-d/ui/Label.d.ts.map +1 -1
- package/dist/two-d/ui/Label.js +14 -3
- package/dist/two-d/ui/Label.js.map +1 -1
- package/dist/two-d/ui/ListView.d.ts +22 -4
- package/dist/two-d/ui/ListView.d.ts.map +1 -1
- package/dist/two-d/ui/ListView.js +44 -43
- package/dist/two-d/ui/ListView.js.map +1 -1
- package/dist/two-d/ui/LoadingScreen.d.ts +24 -1
- package/dist/two-d/ui/LoadingScreen.d.ts.map +1 -1
- package/dist/two-d/ui/LoadingScreen.js +24 -1
- package/dist/two-d/ui/LoadingScreen.js.map +1 -1
- package/dist/two-d/ui/MessageBox.d.ts +21 -2
- package/dist/two-d/ui/MessageBox.d.ts.map +1 -1
- package/dist/two-d/ui/MessageBox.js +19 -0
- package/dist/two-d/ui/MessageBox.js.map +1 -1
- package/dist/two-d/ui/NinePatch.d.ts +12 -0
- package/dist/two-d/ui/NinePatch.d.ts.map +1 -1
- package/dist/two-d/ui/NinePatch.js +12 -0
- package/dist/two-d/ui/NinePatch.js.map +1 -1
- package/dist/two-d/ui/RebindScreen.d.ts +15 -0
- package/dist/two-d/ui/RebindScreen.d.ts.map +1 -1
- package/dist/two-d/ui/RebindScreen.js +15 -0
- package/dist/two-d/ui/RebindScreen.js.map +1 -1
- package/dist/two-d/ui/SelectionModel.d.ts +50 -0
- package/dist/two-d/ui/SelectionModel.d.ts.map +1 -0
- package/dist/two-d/ui/SelectionModel.js +73 -0
- package/dist/two-d/ui/SelectionModel.js.map +1 -0
- package/dist/two-d/ui/StatsScreen.d.ts +15 -0
- package/dist/two-d/ui/StatsScreen.d.ts.map +1 -1
- package/dist/two-d/ui/StatsScreen.js +15 -0
- package/dist/two-d/ui/StatsScreen.js.map +1 -1
- package/dist/two-d/ui/Toast.d.ts +12 -0
- package/dist/two-d/ui/Toast.d.ts.map +1 -1
- package/dist/two-d/ui/Toast.js +12 -0
- package/dist/two-d/ui/Toast.js.map +1 -1
- package/dist/two-d/ui/Tooltip.d.ts +14 -0
- package/dist/two-d/ui/Tooltip.d.ts.map +1 -1
- package/dist/two-d/ui/Tooltip.js +14 -0
- package/dist/two-d/ui/Tooltip.js.map +1 -1
- package/dist/two-d/ui/VerticalLabel.d.ts +18 -0
- package/dist/two-d/ui/VerticalLabel.d.ts.map +1 -1
- package/dist/two-d/ui/VerticalLabel.js +18 -0
- package/dist/two-d/ui/VerticalLabel.js.map +1 -1
- package/dist/two-d/ui/Window.d.ts +12 -0
- package/dist/two-d/ui/Window.d.ts.map +1 -1
- package/dist/two-d/ui/Window.js +12 -0
- package/dist/two-d/ui/Window.js.map +1 -1
- package/dist/two-d/ui/theme.d.ts +45 -1
- package/dist/two-d/ui/theme.d.ts.map +1 -1
- package/dist/two-d/ui/theme.js +45 -1
- package/dist/two-d/ui/theme.js.map +1 -1
- package/dist/two-d/ui/themedText.d.ts +20 -0
- package/dist/two-d/ui/themedText.d.ts.map +1 -0
- package/dist/two-d/ui/themedText.js +9 -0
- package/dist/two-d/ui/themedText.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +11 -2
- package/tools/compile-resources.mjs +1 -1
- package/tools/compress-dist.d.mts +16 -0
- package/tools/compress-dist.mjs +116 -0
package/dist/three-d/Models.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import '@babylonjs/loaders/glTF/index.js';
|
|
2
|
-
import type { ImportMeshOptions, ISceneLoaderAsyncResult } from '@babylonjs/core/Loading/sceneLoader.js';
|
|
2
|
+
import type { ImportMeshOptions, ISceneLoaderAsyncResult, LoadAssetContainerOptions } from '@babylonjs/core/Loading/sceneLoader.js';
|
|
3
|
+
import type { AssetContainer } from '@babylonjs/core/assetContainer.js';
|
|
3
4
|
import type { Scene } from '@babylonjs/core/scene.js';
|
|
4
5
|
export type ModelSource3D = string | File | ArrayBufferView;
|
|
5
6
|
/**
|
|
@@ -7,6 +8,42 @@ export type ModelSource3D = string | File | ArrayBufferView;
|
|
|
7
8
|
* asset path is resolved through `mwg/assets` first, the same way every other loader in the
|
|
8
9
|
* framework becomes `file://`-safe once assets are compiled to `data:` URIs; a URI that is
|
|
9
10
|
* already resolved is passed through unchanged.
|
|
11
|
+
*
|
|
12
|
+
* For a single copy of a model this is the whole job; for several copies of the *same*
|
|
13
|
+
* model, `loadModelContainer3D` fetches and parses once and instantiates independent copies
|
|
14
|
+
* from it - calling this a second time for the same source imports and parses it again.
|
|
10
15
|
*/
|
|
11
16
|
export declare function loadModel3D(source: ModelSource3D, scene: Scene, options?: ImportMeshOptions): Promise<ISceneLoaderAsyncResult>;
|
|
17
|
+
/**
|
|
18
|
+
* Loads a model once per resolved source and caches the in-flight/loaded `AssetContainer`,
|
|
19
|
+
* so a second call for the same source returns the same container instead of importing and
|
|
20
|
+
* parsing it again over the network. A container is not itself scene content - call
|
|
21
|
+
* `container.instantiateModelsToScene()` for each independent copy a game wants to place,
|
|
22
|
+
* which is Babylon's own way to get several unaliased instances of one loaded model without
|
|
23
|
+
* a second fetch; `loadModel3D` imports straight into the scene instead, for the common case
|
|
24
|
+
* of only ever wanting one copy.
|
|
25
|
+
*
|
|
26
|
+
* Only caches when `source` is a string (an asset path or already-resolved URI) - a `File`
|
|
27
|
+
* or in-memory byte view has no stable identity to key a cache on, so those always load
|
|
28
|
+
* fresh, the same way `loadModel3D` never tries to resolve them as a path either.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { loadModelContainer3D, isModelContainerLoaded, releaseModelContainer } from '@datamoc/mw_games/3d/models';
|
|
33
|
+
*
|
|
34
|
+
* declare const scene: import('@babylonjs/core/scene.js').Scene;
|
|
35
|
+
*
|
|
36
|
+
* const container = await loadModelContainer3D('models/tree.glb', scene);
|
|
37
|
+
* const treeA = container.instantiateModelsToScene();
|
|
38
|
+
* const treeB = container.instantiateModelsToScene(); // a second, independent copy - no re-fetch
|
|
39
|
+
*
|
|
40
|
+
* console.log(isModelContainerLoaded('models/tree.glb')); // true
|
|
41
|
+
* releaseModelContainer('models/tree.glb'); // frees the container once every copy is placed
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function loadModelContainer3D(source: ModelSource3D, scene: Scene, options?: LoadAssetContainerOptions): Promise<AssetContainer>;
|
|
45
|
+
/** true once `loadModelContainer3D` has resolved for this source and it has not since been `releaseModelContainer`d */
|
|
46
|
+
export declare function isModelContainerLoaded(source: string): boolean;
|
|
47
|
+
/** disposes and forgets a cached container; a source never loaded (or already released) is silently skipped */
|
|
48
|
+
export declare function releaseModelContainer(source: string): Promise<void>;
|
|
12
49
|
//# sourceMappingURL=Models.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Models.d.ts","sourceRoot":"","sources":["../../src/three-d/Models.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"Models.d.ts","sourceRoot":"","sources":["../../src/three-d/Models.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAC;AACpI,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAItD,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,IAAI,GAAG,eAAe,CAAC;AAM5D;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAE9H;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,OAAO,CAAC,cAAc,CAAC,CAYtI;AAED,uHAAuH;AACvH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAG9D;AAED,+GAA+G;AAC/G,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQzE"}
|
package/dist/three-d/Models.js
CHANGED
|
@@ -1,14 +1,77 @@
|
|
|
1
1
|
import '@babylonjs/loaders/glTF/index.js';
|
|
2
|
-
import { ImportMeshAsync } from '@babylonjs/core/Loading/sceneLoader.js';
|
|
2
|
+
import { ImportMeshAsync, LoadAssetContainerAsync } from '@babylonjs/core/Loading/sceneLoader.js';
|
|
3
3
|
import { resolve } from '../assets/paths.js';
|
|
4
|
+
function resolveSource(source) {
|
|
5
|
+
return typeof source === 'string' && !/^(?:data|blob|https?):/i.test(source) ? resolve(source) : source;
|
|
6
|
+
}
|
|
4
7
|
/**
|
|
5
8
|
* Loads glTF/GLB from an asset path, data/blob/http(s) URI, File, or in-memory byte view. An
|
|
6
9
|
* asset path is resolved through `mwg/assets` first, the same way every other loader in the
|
|
7
10
|
* framework becomes `file://`-safe once assets are compiled to `data:` URIs; a URI that is
|
|
8
11
|
* already resolved is passed through unchanged.
|
|
12
|
+
*
|
|
13
|
+
* For a single copy of a model this is the whole job; for several copies of the *same*
|
|
14
|
+
* model, `loadModelContainer3D` fetches and parses once and instantiates independent copies
|
|
15
|
+
* from it - calling this a second time for the same source imports and parses it again.
|
|
9
16
|
*/
|
|
10
17
|
export function loadModel3D(source, scene, options) {
|
|
11
|
-
|
|
12
|
-
|
|
18
|
+
return ImportMeshAsync(resolveSource(source), scene, options);
|
|
19
|
+
}
|
|
20
|
+
const containerCache = new Map();
|
|
21
|
+
/**
|
|
22
|
+
* Loads a model once per resolved source and caches the in-flight/loaded `AssetContainer`,
|
|
23
|
+
* so a second call for the same source returns the same container instead of importing and
|
|
24
|
+
* parsing it again over the network. A container is not itself scene content - call
|
|
25
|
+
* `container.instantiateModelsToScene()` for each independent copy a game wants to place,
|
|
26
|
+
* which is Babylon's own way to get several unaliased instances of one loaded model without
|
|
27
|
+
* a second fetch; `loadModel3D` imports straight into the scene instead, for the common case
|
|
28
|
+
* of only ever wanting one copy.
|
|
29
|
+
*
|
|
30
|
+
* Only caches when `source` is a string (an asset path or already-resolved URI) - a `File`
|
|
31
|
+
* or in-memory byte view has no stable identity to key a cache on, so those always load
|
|
32
|
+
* fresh, the same way `loadModel3D` never tries to resolve them as a path either.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { loadModelContainer3D, isModelContainerLoaded, releaseModelContainer } from '@datamoc/mw_games/3d/models';
|
|
37
|
+
*
|
|
38
|
+
* declare const scene: import('@babylonjs/core/scene.js').Scene;
|
|
39
|
+
*
|
|
40
|
+
* const container = await loadModelContainer3D('models/tree.glb', scene);
|
|
41
|
+
* const treeA = container.instantiateModelsToScene();
|
|
42
|
+
* const treeB = container.instantiateModelsToScene(); // a second, independent copy - no re-fetch
|
|
43
|
+
*
|
|
44
|
+
* console.log(isModelContainerLoaded('models/tree.glb')); // true
|
|
45
|
+
* releaseModelContainer('models/tree.glb'); // frees the container once every copy is placed
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export function loadModelContainer3D(source, scene, options) {
|
|
49
|
+
const resolved = resolveSource(source);
|
|
50
|
+
if (typeof resolved !== 'string')
|
|
51
|
+
return LoadAssetContainerAsync(resolved, scene, options);
|
|
52
|
+
const cached = containerCache.get(resolved);
|
|
53
|
+
if (cached)
|
|
54
|
+
return cached;
|
|
55
|
+
const promise = LoadAssetContainerAsync(resolved, scene, options);
|
|
56
|
+
containerCache.set(resolved, promise);
|
|
57
|
+
//a rejected load must not poison the cache - the next call gets a fresh attempt
|
|
58
|
+
promise.catch(() => containerCache.delete(resolved));
|
|
59
|
+
return promise;
|
|
60
|
+
}
|
|
61
|
+
/** true once `loadModelContainer3D` has resolved for this source and it has not since been `releaseModelContainer`d */
|
|
62
|
+
export function isModelContainerLoaded(source) {
|
|
63
|
+
const resolved = resolveSource(source);
|
|
64
|
+
return typeof resolved === 'string' && containerCache.has(resolved);
|
|
65
|
+
}
|
|
66
|
+
/** disposes and forgets a cached container; a source never loaded (or already released) is silently skipped */
|
|
67
|
+
export async function releaseModelContainer(source) {
|
|
68
|
+
const resolved = resolveSource(source);
|
|
69
|
+
if (typeof resolved !== 'string')
|
|
70
|
+
return;
|
|
71
|
+
const cached = containerCache.get(resolved);
|
|
72
|
+
if (!cached)
|
|
73
|
+
return;
|
|
74
|
+
containerCache.delete(resolved);
|
|
75
|
+
(await cached).dispose();
|
|
13
76
|
}
|
|
14
77
|
//# sourceMappingURL=Models.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Models.js","sourceRoot":"","sources":["../../src/three-d/Models.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"Models.js","sourceRoot":"","sources":["../../src/three-d/Models.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAKlG,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAI7C,SAAS,aAAa,CAAC,MAAqB;IAC3C,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AACzG,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CAAC,MAAqB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C,MAAM,MAAM,GAAG,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5C,IAAI,CAAC,MAAM;QAAE,OAAO;IACpB,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC,MAAM,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;AAC1B,CAAC"}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import type { AnimatedSprite } from './AnimatedSprite.ts';
|
|
2
2
|
/** the three states any character's animation ever needs to be in */
|
|
3
3
|
export type ActorAnimationState = 'idle' | 'move' | 'action';
|
|
4
|
+
/**
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import type { ActorAnimatorOptions } from '@datamoc/mw_games/two-d/render';
|
|
8
|
+
*
|
|
9
|
+
* const options: ActorAnimatorOptions = {
|
|
10
|
+
* animationName: (state, facing) => `${state}-${facing}`,
|
|
11
|
+
* variant: 'down',
|
|
12
|
+
* };
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
4
15
|
export interface ActorAnimatorOptions {
|
|
5
16
|
/**
|
|
6
17
|
* Names a state's animation, given whatever varies it - a facing direction for a grid
|
|
@@ -30,6 +41,27 @@ export interface ActorAnimatorOptions {
|
|
|
30
41
|
*
|
|
31
42
|
* This owns the sprite's `onFinish` hook entirely; a game driving one through
|
|
32
43
|
* `ActorAnimator` should not also set `onFinish` itself.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { ActorAnimator, AnimatedSprite, SpriteSheet } from '@datamoc/mw_games/two-d/render';
|
|
48
|
+
*
|
|
49
|
+
* declare const sheet: SpriteSheet;
|
|
50
|
+
*
|
|
51
|
+
* const hero = new AnimatedSprite();
|
|
52
|
+
* hero.add('idle-down', sheet.pick(0), { fps: 2 });
|
|
53
|
+
* hero.add('move-down', sheet.range(1, 4), { fps: 10 });
|
|
54
|
+
* hero.add('action-down', sheet.range(5, 7), { fps: 12, loop: false });
|
|
55
|
+
*
|
|
56
|
+
* const animator = new ActorAnimator(hero, {
|
|
57
|
+
* animationName: (state, facing) => `${state}-${facing}`,
|
|
58
|
+
* variant: 'down',
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* animator.setMoving(true); // walk cycle starts
|
|
62
|
+
* animator.playAction(); // an attack swing cuts in over the walk cycle
|
|
63
|
+
* console.log(animator.state); // 'action' - overrides idle/move while it plays
|
|
64
|
+
* ```
|
|
33
65
|
*/
|
|
34
66
|
export declare class ActorAnimator {
|
|
35
67
|
private sprite;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorAnimator.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/ActorAnimator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,qEAAqE;AACrE,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE7D,MAAM,WAAW,oBAAoB;IACpC;;;;;;OAMG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;IAEvE,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED
|
|
1
|
+
{"version":3,"file":"ActorAnimator.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/ActorAnimator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,qEAAqE;AACrE,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE7D;;;;;;;;;;GAUG;AACH,MAAM,WAAW,oBAAoB;IACpC;;;;;;OAMG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;IAEvE,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,qBAAa,aAAa;IACzB,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,aAAa,CAA0D;IAE/E,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,QAAQ,CAAS;IAEzB,YAAY,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,oBAAoB,EAOhE;IAED,2FAA2F;IAC3F,IAAI,KAAK,IAAI,mBAAmB,CAE/B;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAIjD;IAED;;;;;;OAMG;IACH,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,IAAI,CAMlD;IAED,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,KAAK;CAIb"}
|
|
@@ -15,6 +15,27 @@
|
|
|
15
15
|
*
|
|
16
16
|
* This owns the sprite's `onFinish` hook entirely; a game driving one through
|
|
17
17
|
* `ActorAnimator` should not also set `onFinish` itself.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { ActorAnimator, AnimatedSprite, SpriteSheet } from '@datamoc/mw_games/two-d/render';
|
|
22
|
+
*
|
|
23
|
+
* declare const sheet: SpriteSheet;
|
|
24
|
+
*
|
|
25
|
+
* const hero = new AnimatedSprite();
|
|
26
|
+
* hero.add('idle-down', sheet.pick(0), { fps: 2 });
|
|
27
|
+
* hero.add('move-down', sheet.range(1, 4), { fps: 10 });
|
|
28
|
+
* hero.add('action-down', sheet.range(5, 7), { fps: 12, loop: false });
|
|
29
|
+
*
|
|
30
|
+
* const animator = new ActorAnimator(hero, {
|
|
31
|
+
* animationName: (state, facing) => `${state}-${facing}`,
|
|
32
|
+
* variant: 'down',
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* animator.setMoving(true); // walk cycle starts
|
|
36
|
+
* animator.playAction(); // an attack swing cuts in over the walk cycle
|
|
37
|
+
* console.log(animator.state); // 'action' - overrides idle/move while it plays
|
|
38
|
+
* ```
|
|
18
39
|
*/
|
|
19
40
|
export class ActorAnimator {
|
|
20
41
|
constructor(sprite, options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorAnimator.js","sourceRoot":"","sources":["../../../src/two-d/render/ActorAnimator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ActorAnimator.js","sourceRoot":"","sources":["../../../src/two-d/render/ActorAnimator.ts"],"names":[],"mappings":"AA8BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,OAAO,aAAa;IAQzB,YAAY,MAAsB,EAAE,OAA6B;QAHzD,eAAU,GAAoB,MAAM,CAAC;QACrC,aAAQ,GAAG,KAAK,CAAC;QAGxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;QAErC,IAAI,CAAC,MAAM,CAAC,QAAQ,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;QACnD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC7B,CAAC;IAED,2FAA2F;IAC3F,IAAI,KAAK;QACR,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;IACnD,CAAC;IAED,IAAI,WAAW;QACd,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,SAAS,CAAC,MAAe,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
11
|
+
* ```ts
|
|
12
|
+
* import { Animation } from '@datamoc/mw_games/two-d/render';
|
|
13
|
+
* import type { Texture2D } from '@datamoc/mw_games/two-d/render';
|
|
14
|
+
*
|
|
15
|
+
* declare const frames: Texture2D[];
|
|
16
|
+
*
|
|
17
|
+
* const walk = new Animation(frames, { fps: 10 });
|
|
18
|
+
* console.log(walk.duration); // frames.length / 10, in seconds
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
9
21
|
export declare class Animation {
|
|
10
22
|
readonly frames: readonly Texture2D[];
|
|
11
23
|
readonly frameDuration: number;
|
|
@@ -17,18 +29,26 @@ export declare class Animation {
|
|
|
17
29
|
* A sprite that plays named animations, and can still be tinted.
|
|
18
30
|
*
|
|
19
31
|
* Animations are registered once and played by name, which is how a character ends up
|
|
20
|
-
* reading as `hero.play('walk')` rather than juggling frame arrays
|
|
32
|
+
* reading as `hero.play('walk')` rather than juggling frame arrays.
|
|
21
33
|
*
|
|
34
|
+
* Nothing advances on its own: call `update(dt)` from the scene, or add the sprite to a
|
|
35
|
+
* `SpriteGroup`, so that pausing the game pauses the animations with it.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
22
38
|
* ```ts
|
|
39
|
+
* import { AnimatedSprite, SpriteSheet } from '@datamoc/mw_games/two-d/render';
|
|
40
|
+
*
|
|
41
|
+
* declare const sheet: SpriteSheet;
|
|
42
|
+
*
|
|
23
43
|
* const hero = new AnimatedSprite();
|
|
24
44
|
* hero.add('idle', sheet.pick(0, 0, 0, 1), { fps: 2 });
|
|
25
45
|
* hero.add('walk', sheet.range(6, 10), { fps: 10 });
|
|
26
46
|
* hero.add('die', sheet.range(11, 14), { fps: 10, loop: false });
|
|
27
47
|
* hero.play('idle');
|
|
28
|
-
* ```
|
|
29
48
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
49
|
+
* hero.onFinish = (name) => console.log(`${name} finished`);
|
|
50
|
+
* hero.update(1 / 60); // advance one frame's worth of time
|
|
51
|
+
* ```
|
|
32
52
|
*/
|
|
33
53
|
export declare class AnimatedSprite extends TintedSprite {
|
|
34
54
|
private animations;
|
|
@@ -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,wBAAwB;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,mEAAmE;IACnE,IAAI,CAAC,EAAE,OAAO,CAAC;CACf;AAED,qBAAa,SAAS;IACrB,QAAQ,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;IACtC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAEvB,YAAY,MAAM,EAAE,SAAS,SAAS,EAAE,EAAE,EAAE,GAAQ,EAAE,IAAW,EAAE,GAAE,gBAAqB,EAKzF;IAED,IAAI,QAAQ,IAAI,MAAM,CAErB;CACD;AAED
|
|
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,wBAAwB;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,mEAAmE;IACnE,IAAI,CAAC,EAAE,OAAO,CAAC;CACf;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,SAAS;IACrB,QAAQ,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;IACtC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAEvB,YAAY,MAAM,EAAE,SAAS,SAAS,EAAE,EAAE,EAAE,GAAQ,EAAE,IAAW,EAAE,GAAE,gBAAqB,EAKzF;IAED,IAAI,QAAQ,IAAI,MAAM,CAErB;CACD;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,cAAe,SAAQ,YAAY;IAC/C,OAAO,CAAC,UAAU,CAAgC;IAElD,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,QAAQ,CAAS;IAEzB,qEAAqE;IACrE,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,IAAI,CAAQ;IAEjD,MAAM,UAAS;IAEf,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,SAAS,EAAE,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAGhF;IAED,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzB;IAED,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAE3B;IAED,IAAI,UAAU,IAAI,OAAO,CAExB;IAED;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,IAAI,CAcxC;IAED,IAAI,IAAI,IAAI,CAGX;IAED,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAuBvB;CACD"}
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { TintedSprite } from './TintedSprite.js';
|
|
2
|
+
/**
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* import { Animation } from '@datamoc/mw_games/two-d/render';
|
|
6
|
+
* import type { Texture2D } from '@datamoc/mw_games/two-d/render';
|
|
7
|
+
*
|
|
8
|
+
* declare const frames: Texture2D[];
|
|
9
|
+
*
|
|
10
|
+
* const walk = new Animation(frames, { fps: 10 });
|
|
11
|
+
* console.log(walk.duration); // frames.length / 10, in seconds
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
2
14
|
export class Animation {
|
|
3
15
|
constructor(frames, { fps = 10, loop = true } = {}) {
|
|
4
16
|
if (frames.length === 0)
|
|
@@ -15,18 +27,26 @@ export class Animation {
|
|
|
15
27
|
* A sprite that plays named animations, and can still be tinted.
|
|
16
28
|
*
|
|
17
29
|
* Animations are registered once and played by name, which is how a character ends up
|
|
18
|
-
* reading as `hero.play('walk')` rather than juggling frame arrays
|
|
30
|
+
* reading as `hero.play('walk')` rather than juggling frame arrays.
|
|
19
31
|
*
|
|
32
|
+
* Nothing advances on its own: call `update(dt)` from the scene, or add the sprite to a
|
|
33
|
+
* `SpriteGroup`, so that pausing the game pauses the animations with it.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
20
36
|
* ```ts
|
|
37
|
+
* import { AnimatedSprite, SpriteSheet } from '@datamoc/mw_games/two-d/render';
|
|
38
|
+
*
|
|
39
|
+
* declare const sheet: SpriteSheet;
|
|
40
|
+
*
|
|
21
41
|
* const hero = new AnimatedSprite();
|
|
22
42
|
* hero.add('idle', sheet.pick(0, 0, 0, 1), { fps: 2 });
|
|
23
43
|
* hero.add('walk', sheet.range(6, 10), { fps: 10 });
|
|
24
44
|
* hero.add('die', sheet.range(11, 14), { fps: 10, loop: false });
|
|
25
45
|
* hero.play('idle');
|
|
26
|
-
* ```
|
|
27
46
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
47
|
+
* hero.onFinish = (name) => console.log(`${name} finished`);
|
|
48
|
+
* hero.update(1 / 60); // advance one frame's worth of time
|
|
49
|
+
* ```
|
|
30
50
|
*/
|
|
31
51
|
export class AnimatedSprite extends TintedSprite {
|
|
32
52
|
constructor() {
|
|
@@ -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;AAWjD,MAAM,OAAO,SAAS;IAKrB,YAAY,MAA4B,EAAE,EAAE,GAAG,GAAG,EAAE,EAAE,IAAI,GAAG,IAAI,EAAE,GAAqB,EAAE;QACzF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAClF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG,CAAC,GAAG,GAAG,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;IAED,IAAI,QAAQ;QACX,OAAO,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAChD,CAAC;CACD;AAED
|
|
1
|
+
{"version":3,"file":"AnimatedSprite.js","sourceRoot":"","sources":["../../../src/two-d/render/AnimatedSprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAWjD;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,SAAS;IAKrB,YAAY,MAA4B,EAAE,EAAE,GAAG,GAAG,EAAE,EAAE,IAAI,GAAG,IAAI,EAAE,GAAqB,EAAE;QACzF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAClF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG,CAAC,GAAG,GAAG,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;IAED,IAAI,QAAQ;QACX,OAAO,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAChD,CAAC;CACD;AAED;;;;;;;;;;;;;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's autotile layout will need its frames reordered into this one. What is
|
|
25
25
|
* guaranteed: `BLOB_SHAPES` lists all 47 shapes in the exact order `blobIndex` returns them
|
|
26
26
|
* in, so a tool (or a person, reading it once) can draw or arrange frames against it directly.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { BLOB_SHAPES } from '@datamoc/mw_games/two-d/render';
|
|
31
|
+
*
|
|
32
|
+
* console.log(BLOB_SHAPES.length); // 47
|
|
33
|
+
* console.log(BLOB_SHAPES[0]); // { n: false, e: false, s: false, w: false, ne: false, se: false, sw: false, nw: false }
|
|
34
|
+
* ```
|
|
27
35
|
*/
|
|
28
36
|
export declare const BLOB_SHAPES: readonly NeighborMask[];
|
|
29
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* the blob index (0 to 46) for one cell's 8-neighbour membership test
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { blobIndex } from '@datamoc/mw_games/two-d/render';
|
|
43
|
+
*
|
|
44
|
+
* const surroundedOnAllSides = blobIndex({
|
|
45
|
+
* n: true, e: true, s: true, w: true,
|
|
46
|
+
* ne: true, se: true, sw: true, nw: true,
|
|
47
|
+
* });
|
|
48
|
+
* console.log(surroundedOnAllSides); // 46 - the fully-interior shape
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
30
51
|
export declare function blobIndex(neighbors: NeighborMask): number;
|
|
31
52
|
/**
|
|
32
53
|
* One frame per cell of a terrain, autotiled from a same-terrain test alone.
|
|
@@ -37,6 +58,17 @@ export declare function blobIndex(neighbors: NeighborMask): number;
|
|
|
37
58
|
* @param frames the 47 frames a `blobIndex` of 0 to 46 selects between, drawn (or arranged)
|
|
38
59
|
* against `BLOB_SHAPES`
|
|
39
60
|
* @returns one frame index per cell, row-major, `EMPTY` wherever `sameTerrain` is false
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { autotileFrames, BLOB_SHAPES } from '@datamoc/mw_games/two-d/render';
|
|
65
|
+
*
|
|
66
|
+
* const water = new Set([0, 1, 10, 11]); // a 2x2 pond in a wider grid
|
|
67
|
+
* const frames = Array.from({ length: BLOB_SHAPES.length }, (_, index) => index); // frame N = shape N
|
|
68
|
+
*
|
|
69
|
+
* const cellFrames = autotileFrames(10, 10, (x, y) => water.has(y * 10 + x), frames);
|
|
70
|
+
* console.log(cellFrames[0]); // the blob frame for the pond's top-left corner
|
|
71
|
+
* ```
|
|
40
72
|
*/
|
|
41
73
|
export declare function autotileFrames(width: number, height: number, sameTerrain: (x: number, y: number) => boolean, frames: readonly number[]): Int32Array;
|
|
42
74
|
//# sourceMappingURL=Autotile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Autotile.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/Autotile.ts"],"names":[],"mappings":"AAEA,yFAAyF;AACzF,MAAM,WAAW,YAAY;IAC5B,CAAC,EAAE,OAAO,CAAC;IACX,CAAC,EAAE,OAAO,CAAC;IACX,CAAC,EAAE,OAAO,CAAC;IACX,CAAC,EAAE,OAAO,CAAC;IACX,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;CACZ;AAED
|
|
1
|
+
{"version":3,"file":"Autotile.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/Autotile.ts"],"names":[],"mappings":"AAEA,yFAAyF;AACzF,MAAM,WAAW,YAAY;IAC5B,CAAC,EAAE,OAAO,CAAC;IACX,CAAC,EAAE,OAAO,CAAC;IACX,CAAC,EAAE,OAAO,CAAC;IACX,CAAC,EAAE,OAAO,CAAC;IACX,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;CACZ;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,WAAW,EAAE,SAAS,YAAY,EAAsB,CAAC;AAoEtE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,YAAY,GAAG,MAAM,CAEzD;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAC7B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,EAC9C,MAAM,EAAE,SAAS,MAAM,EAAE,GACvB,UAAU,CA+BZ"}
|
|
@@ -14,6 +14,14 @@ import { EMPTY } from './TileMap.js';
|
|
|
14
14
|
* different engine's autotile layout will need its frames reordered into this one. What is
|
|
15
15
|
* guaranteed: `BLOB_SHAPES` lists all 47 shapes in the exact order `blobIndex` returns them
|
|
16
16
|
* in, so a tool (or a person, reading it once) can draw or arrange frames against it directly.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { BLOB_SHAPES } from '@datamoc/mw_games/two-d/render';
|
|
21
|
+
*
|
|
22
|
+
* console.log(BLOB_SHAPES.length); // 47
|
|
23
|
+
* console.log(BLOB_SHAPES[0]); // { n: false, e: false, s: false, w: false, ne: false, se: false, sw: false, nw: false }
|
|
24
|
+
* ```
|
|
17
25
|
*/
|
|
18
26
|
export const BLOB_SHAPES = buildBlobShapes();
|
|
19
27
|
const blobIndexByMask = new Map(BLOB_SHAPES.map((shape, index) => [maskOf(shape), index]));
|
|
@@ -73,7 +81,20 @@ function buildBlobShapes() {
|
|
|
73
81
|
shapes.sort((a, b) => a.mask - b.mask);
|
|
74
82
|
return shapes.map((entry) => entry.shape);
|
|
75
83
|
}
|
|
76
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* the blob index (0 to 46) for one cell's 8-neighbour membership test
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* import { blobIndex } from '@datamoc/mw_games/two-d/render';
|
|
90
|
+
*
|
|
91
|
+
* const surroundedOnAllSides = blobIndex({
|
|
92
|
+
* n: true, e: true, s: true, w: true,
|
|
93
|
+
* ne: true, se: true, sw: true, nw: true,
|
|
94
|
+
* });
|
|
95
|
+
* console.log(surroundedOnAllSides); // 46 - the fully-interior shape
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
77
98
|
export function blobIndex(neighbors) {
|
|
78
99
|
return blobIndexByMask.get(maskOf(neighbors));
|
|
79
100
|
}
|
|
@@ -86,6 +107,17 @@ export function blobIndex(neighbors) {
|
|
|
86
107
|
* @param frames the 47 frames a `blobIndex` of 0 to 46 selects between, drawn (or arranged)
|
|
87
108
|
* against `BLOB_SHAPES`
|
|
88
109
|
* @returns one frame index per cell, row-major, `EMPTY` wherever `sameTerrain` is false
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* import { autotileFrames, BLOB_SHAPES } from '@datamoc/mw_games/two-d/render';
|
|
114
|
+
*
|
|
115
|
+
* const water = new Set([0, 1, 10, 11]); // a 2x2 pond in a wider grid
|
|
116
|
+
* const frames = Array.from({ length: BLOB_SHAPES.length }, (_, index) => index); // frame N = shape N
|
|
117
|
+
*
|
|
118
|
+
* const cellFrames = autotileFrames(10, 10, (x, y) => water.has(y * 10 + x), frames);
|
|
119
|
+
* console.log(cellFrames[0]); // the blob frame for the pond's top-left corner
|
|
120
|
+
* ```
|
|
89
121
|
*/
|
|
90
122
|
export function autotileFrames(width, height, sameTerrain, frames) {
|
|
91
123
|
if (frames.length !== BLOB_SHAPES.length) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Autotile.js","sourceRoot":"","sources":["../../../src/two-d/render/Autotile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAcrC
|
|
1
|
+
{"version":3,"file":"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6 +7,23 @@ import { Container } from 'pixi.js';
|
|
|
7
7
|
* anything that should stay put on screen (the HUD, a dialogue box) goes outside it.
|
|
8
8
|
*
|
|
9
9
|
* Positions are in world units. At `zoom = 3` a 16px tile is 48 screen pixels.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { Camera, createCamera } from '@datamoc/mw_games/two-d/render';
|
|
14
|
+
* import type { Container2D } from '@datamoc/mw_games/two-d/render';
|
|
15
|
+
*
|
|
16
|
+
* declare const stage: Container2D;
|
|
17
|
+
* declare const hero: { x: number; y: number };
|
|
18
|
+
*
|
|
19
|
+
* const camera = createCamera({ zoom: 3, deadzone: 0.3, pixelPerfectTileSize: 16 });
|
|
20
|
+
* stage.addChild(camera.world);
|
|
21
|
+
* camera.follow(hero);
|
|
22
|
+
*
|
|
23
|
+
* function onFrame(dt: number): void {
|
|
24
|
+
* camera.update(dt);
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
10
27
|
*/
|
|
11
28
|
export interface CameraOptions {
|
|
12
29
|
/** screen pixels per world unit */
|
|
@@ -33,6 +50,25 @@ export interface CameraOptions {
|
|
|
33
50
|
*/
|
|
34
51
|
pixelPerfectTileSize?: number;
|
|
35
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { Camera } from '@datamoc/mw_games/two-d/render';
|
|
57
|
+
* import type { Container2D } from '@datamoc/mw_games/two-d/render';
|
|
58
|
+
*
|
|
59
|
+
* declare const stage: Container2D;
|
|
60
|
+
*
|
|
61
|
+
* const camera = new Camera({ zoom: 2 });
|
|
62
|
+
* camera.setViewport(960, 540);
|
|
63
|
+
* stage.addChild(camera.world);
|
|
64
|
+
*
|
|
65
|
+
* camera.snapTo(160, 160); // jump to the start room, no easing
|
|
66
|
+
* camera.follow({ x: 176, y: 160 }); // then ease towards wherever the hero is
|
|
67
|
+
* camera.update(1 / 60);
|
|
68
|
+
*
|
|
69
|
+
* const screenPoint = camera.toScreen(160, 160);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
36
72
|
export declare class Camera {
|
|
37
73
|
/** put the map and everything in it here */
|
|
38
74
|
readonly world: Container<import("pixi.js").ContainerChild>;
|
|
@@ -109,8 +145,24 @@ export declare class Camera {
|
|
|
109
145
|
* The nearest zoom to `zoom` at which `tileSize * zoom` is a whole number of screen pixels -
|
|
110
146
|
* the pure math behind `CameraOptions.pixelPerfectTileSize`, exported so a game can snap a
|
|
111
147
|
* zoom value (from a slider, say) before ever handing it to a `Camera`.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* import { snapZoom } from '@datamoc/mw_games/two-d/render';
|
|
152
|
+
*
|
|
153
|
+
* console.log(snapZoom(2.4, 16)); // 2.375 - 16 * 2.375 = 38, a whole number of pixels
|
|
154
|
+
* ```
|
|
112
155
|
*/
|
|
113
156
|
export declare function snapZoom(zoom: number, tileSize: number): number;
|
|
114
|
-
/**
|
|
157
|
+
/**
|
|
158
|
+
* a camera sized to the running game's viewport, updated on every frame
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* import { createCamera } from '@datamoc/mw_games/two-d/render';
|
|
163
|
+
*
|
|
164
|
+
* const camera = createCamera({ zoom: 2 }); // sized to Game.current automatically
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
115
167
|
export declare function createCamera(options?: CameraOptions): Camera;
|
|
116
168
|
//# sourceMappingURL=Camera.d.ts.map
|
|
@@ -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;AAIpC
|
|
1
|
+
{"version":3,"file":"Camera.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/Camera.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,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,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG/D;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,CAMhE"}
|
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
import { Container } from 'pixi.js';
|
|
2
2
|
import { Game } from '../Game.js';
|
|
3
3
|
import * as Random from '../../core/Random.js';
|
|
4
|
+
/**
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { Camera } from '@datamoc/mw_games/two-d/render';
|
|
8
|
+
* import type { Container2D } from '@datamoc/mw_games/two-d/render';
|
|
9
|
+
*
|
|
10
|
+
* declare const stage: Container2D;
|
|
11
|
+
*
|
|
12
|
+
* const camera = new Camera({ zoom: 2 });
|
|
13
|
+
* camera.setViewport(960, 540);
|
|
14
|
+
* stage.addChild(camera.world);
|
|
15
|
+
*
|
|
16
|
+
* camera.snapTo(160, 160); // jump to the start room, no easing
|
|
17
|
+
* camera.follow({ x: 176, y: 160 }); // then ease towards wherever the hero is
|
|
18
|
+
* camera.update(1 / 60);
|
|
19
|
+
*
|
|
20
|
+
* const screenPoint = camera.toScreen(160, 160);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
4
23
|
export class Camera {
|
|
5
24
|
constructor(options = {}) {
|
|
6
25
|
/** put the map and everything in it here */
|
|
@@ -166,12 +185,28 @@ function clamp(value, min, max) {
|
|
|
166
185
|
* The nearest zoom to `zoom` at which `tileSize * zoom` is a whole number of screen pixels -
|
|
167
186
|
* the pure math behind `CameraOptions.pixelPerfectTileSize`, exported so a game can snap a
|
|
168
187
|
* zoom value (from a slider, say) before ever handing it to a `Camera`.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* import { snapZoom } from '@datamoc/mw_games/two-d/render';
|
|
192
|
+
*
|
|
193
|
+
* console.log(snapZoom(2.4, 16)); // 2.375 - 16 * 2.375 = 38, a whole number of pixels
|
|
194
|
+
* ```
|
|
169
195
|
*/
|
|
170
196
|
export function snapZoom(zoom, tileSize) {
|
|
171
197
|
const pixels = Math.max(1, Math.round(zoom * tileSize));
|
|
172
198
|
return pixels / tileSize;
|
|
173
199
|
}
|
|
174
|
-
/**
|
|
200
|
+
/**
|
|
201
|
+
* a camera sized to the running game's viewport, updated on every frame
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* import { createCamera } from '@datamoc/mw_games/two-d/render';
|
|
206
|
+
*
|
|
207
|
+
* const camera = createCamera({ zoom: 2 }); // sized to Game.current automatically
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
175
210
|
export function createCamera(options = {}) {
|
|
176
211
|
const camera = new Camera(options);
|
|
177
212
|
const game = Game.current;
|