@combos-fun/engine 0.1.17 → 0.1.19
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/dist/engine.cjs.js +118 -4
- package/dist/engine.cjs.js.map +1 -1
- package/dist/engine.cjs.prod.js +1 -1
- package/dist/engine.d.ts +26 -3
- package/dist/engine.esm.js +116 -5
- package/dist/engine.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/engine.cjs.js
CHANGED
|
@@ -891,7 +891,7 @@ class Scene extends GameObject {
|
|
|
891
891
|
}
|
|
892
892
|
|
|
893
893
|
/** Generated at build from package.json */
|
|
894
|
-
const version = "0.1.
|
|
894
|
+
const version = "0.1.19";
|
|
895
895
|
|
|
896
896
|
/**
|
|
897
897
|
* Sent to `window.parent` after each `System.init` completes during `Game.addSystem`
|
|
@@ -1683,9 +1683,30 @@ function missingUrlError(resourceName, slot) {
|
|
|
1683
1683
|
`Use { type, url } (e.g. { type: "webp", url: "https://..." }). ` +
|
|
1684
1684
|
`A flat path string is also accepted and will be normalized.`);
|
|
1685
1685
|
}
|
|
1686
|
+
function isSpriteSheetResource(resourceType) {
|
|
1687
|
+
return resourceType === 'SPRITE' || resourceType === 'SPRITE_ANIMATION';
|
|
1688
|
+
}
|
|
1689
|
+
/**
|
|
1690
|
+
* Agent atlases name the sheet `atlas_json` and may also attach `animation_json`.
|
|
1691
|
+
* Playback only reads `data.json`. Prefer an existing `json` slot, and drop the
|
|
1692
|
+
* animator so a failed extra request cannot fail the whole resource.
|
|
1693
|
+
*/
|
|
1694
|
+
function foldSpriteSheetSlots(src) {
|
|
1695
|
+
const next = { ...src };
|
|
1696
|
+
delete next.animation_json;
|
|
1697
|
+
if (next.json != null) {
|
|
1698
|
+
delete next.atlas_json;
|
|
1699
|
+
}
|
|
1700
|
+
else if (next.atlas_json != null) {
|
|
1701
|
+
next.json = next.atlas_json;
|
|
1702
|
+
delete next.atlas_json;
|
|
1703
|
+
}
|
|
1704
|
+
return next;
|
|
1705
|
+
}
|
|
1686
1706
|
/**
|
|
1687
1707
|
* Accept the documented `{ type, url }` slots, plus the common guesses
|
|
1688
1708
|
* `src: "file.png"` and `src: { image: "a.webp", json: "a.json" }`.
|
|
1709
|
+
* `SPRITE` / `SPRITE_ANIMATION` also accept `atlas_json` in place of `json`.
|
|
1689
1710
|
*/
|
|
1690
1711
|
function normalizeResourceSrc(src, resourceType, resourceName = '(unnamed)') {
|
|
1691
1712
|
if (src == null) {
|
|
@@ -1698,8 +1719,11 @@ function normalizeResourceSrc(src, resourceType, resourceName = '(unnamed)') {
|
|
|
1698
1719
|
if (typeof src !== 'object' || Array.isArray(src)) {
|
|
1699
1720
|
throw new Error(`Resource "${resourceName}" src must be a url string or a slot object.`);
|
|
1700
1721
|
}
|
|
1722
|
+
const slots = isSpriteSheetResource(resourceType)
|
|
1723
|
+
? foldSpriteSheetSlots(src)
|
|
1724
|
+
: src;
|
|
1701
1725
|
const out = {};
|
|
1702
|
-
for (const [slot, value] of Object.entries(
|
|
1726
|
+
for (const [slot, value] of Object.entries(slots)) {
|
|
1703
1727
|
if (value == null)
|
|
1704
1728
|
continue;
|
|
1705
1729
|
out[slot] = wrapSlot(slot, value, resourceName);
|
|
@@ -1842,6 +1866,35 @@ function frameFromPackedItem(item) {
|
|
|
1842
1866
|
sourceSize: item.sourceSize,
|
|
1843
1867
|
};
|
|
1844
1868
|
}
|
|
1869
|
+
function cloneAnimations(source) {
|
|
1870
|
+
const animations = {};
|
|
1871
|
+
if (!source || typeof source !== 'object')
|
|
1872
|
+
return animations;
|
|
1873
|
+
for (const key of Object.keys(source)) {
|
|
1874
|
+
const list = source[key];
|
|
1875
|
+
animations[key] = Array.isArray(list) ? list.map((frame) => String(frame)) : [];
|
|
1876
|
+
}
|
|
1877
|
+
return animations;
|
|
1878
|
+
}
|
|
1879
|
+
function deriveClipNames(names, animations) {
|
|
1880
|
+
const listed = new Set();
|
|
1881
|
+
for (const frames of Object.values(animations)) {
|
|
1882
|
+
for (const name of frames)
|
|
1883
|
+
listed.add(name);
|
|
1884
|
+
}
|
|
1885
|
+
for (const name of names) {
|
|
1886
|
+
if (!name || listed.has(name))
|
|
1887
|
+
continue;
|
|
1888
|
+
const slash = name.lastIndexOf('/');
|
|
1889
|
+
if (slash <= 0)
|
|
1890
|
+
continue;
|
|
1891
|
+
const clip = name.slice(0, slash);
|
|
1892
|
+
if (!animations[clip])
|
|
1893
|
+
animations[clip] = [];
|
|
1894
|
+
animations[clip].push(name);
|
|
1895
|
+
listed.add(name);
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1845
1898
|
function collectArrayFrames(list, frames, animations) {
|
|
1846
1899
|
for (const raw of list) {
|
|
1847
1900
|
if (!raw || typeof raw !== 'object')
|
|
@@ -1876,15 +1929,17 @@ function normalizeSpritesheetData(raw) {
|
|
|
1876
1929
|
}
|
|
1877
1930
|
const json = raw;
|
|
1878
1931
|
if (isFrameMap(json.frames)) {
|
|
1932
|
+
const animations = cloneAnimations(json.animations);
|
|
1933
|
+
deriveClipNames(Object.keys(json.frames), animations);
|
|
1879
1934
|
return {
|
|
1880
1935
|
...json,
|
|
1881
1936
|
frames: json.frames,
|
|
1882
|
-
animations
|
|
1937
|
+
animations,
|
|
1883
1938
|
meta: { scale: 1, ...(json.meta || {}) },
|
|
1884
1939
|
};
|
|
1885
1940
|
}
|
|
1886
1941
|
const frames = {};
|
|
1887
|
-
const animations =
|
|
1942
|
+
const animations = cloneAnimations(json.animations);
|
|
1888
1943
|
if (Array.isArray(json.textures)) {
|
|
1889
1944
|
for (const sheet of json.textures) {
|
|
1890
1945
|
if (!sheet || typeof sheet !== 'object')
|
|
@@ -1921,6 +1976,62 @@ function normalizeSpritesheetData(raw) {
|
|
|
1921
1976
|
meta: { scale: 1, ...(json.meta || {}) },
|
|
1922
1977
|
};
|
|
1923
1978
|
}
|
|
1979
|
+
function spriteClipKeyOrder(raw) {
|
|
1980
|
+
if (!raw || typeof raw !== 'object')
|
|
1981
|
+
return 'insertion';
|
|
1982
|
+
const frames = raw.frames;
|
|
1983
|
+
if (isFrameMap(frames))
|
|
1984
|
+
return 'lexical';
|
|
1985
|
+
return 'insertion';
|
|
1986
|
+
}
|
|
1987
|
+
/**
|
|
1988
|
+
* Ordered frames plus clips named by the path prefix (`idle/frame0000` → `idle`).
|
|
1989
|
+
* TexturePacker `textures[].frames` and a top-level `frames` array keep source order.
|
|
1990
|
+
* A top-level `frames` object uses lexical key order.
|
|
1991
|
+
*/
|
|
1992
|
+
function readSpriteClipSheet(raw, keyOrder = spriteClipKeyOrder(raw)) {
|
|
1993
|
+
const normalized = normalizeSpritesheetData(raw);
|
|
1994
|
+
const names = Object.keys(normalized.frames);
|
|
1995
|
+
if (keyOrder === 'lexical')
|
|
1996
|
+
names.sort();
|
|
1997
|
+
const frames = names.map((name) => ({ ...normalized.frames[name], name }));
|
|
1998
|
+
const byName = new Map(frames.map((frame) => [frame.name, frame]));
|
|
1999
|
+
const animations = {};
|
|
2000
|
+
const declared = normalized.animations || {};
|
|
2001
|
+
for (const clip of Object.keys(declared)) {
|
|
2002
|
+
const sourceNames = declared[clip] || [];
|
|
2003
|
+
const frameNames = keyOrder === 'lexical' ? [...sourceNames].sort() : sourceNames;
|
|
2004
|
+
const list = [];
|
|
2005
|
+
for (const frameName of frameNames) {
|
|
2006
|
+
const frame = byName.get(frameName);
|
|
2007
|
+
if (frame)
|
|
2008
|
+
list.push(frame);
|
|
2009
|
+
}
|
|
2010
|
+
if (list.length)
|
|
2011
|
+
animations[clip] = list;
|
|
2012
|
+
}
|
|
2013
|
+
if (Object.keys(animations).length === 0) {
|
|
2014
|
+
for (const frame of frames) {
|
|
2015
|
+
const slash = frame.name.lastIndexOf('/');
|
|
2016
|
+
if (slash <= 0)
|
|
2017
|
+
continue;
|
|
2018
|
+
const clip = frame.name.slice(0, slash);
|
|
2019
|
+
if (!animations[clip])
|
|
2020
|
+
animations[clip] = [];
|
|
2021
|
+
animations[clip].push(frame);
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
return { frames, animations, meta: normalized.meta };
|
|
2025
|
+
}
|
|
2026
|
+
function resolveSpriteClip(frames, animations, name) {
|
|
2027
|
+
const clip = String(name ?? '').trim();
|
|
2028
|
+
if (!clip)
|
|
2029
|
+
return { frames: [...frames], clip: '', missing: false };
|
|
2030
|
+
const found = animations[clip];
|
|
2031
|
+
if (!found || found.length === 0)
|
|
2032
|
+
return { frames: [], clip, missing: true };
|
|
2033
|
+
return { frames: [...found], clip, missing: false };
|
|
2034
|
+
}
|
|
1924
2035
|
|
|
1925
2036
|
/** Resource type */
|
|
1926
2037
|
exports.RESOURCE_TYPE = void 0;
|
|
@@ -2398,9 +2509,12 @@ exports.parseSetPlayingMessage = parseSetPlayingMessage;
|
|
|
2398
2509
|
exports.postParentGameReady = postParentGameReady;
|
|
2399
2510
|
exports.postParentGameState = postParentGameState;
|
|
2400
2511
|
exports.postParentPluginInitSuccess = postParentPluginInitSuccess;
|
|
2512
|
+
exports.readSpriteClipSheet = readSpriteClipSheet;
|
|
2401
2513
|
exports.resolveRenderQuality = resolveRenderQuality;
|
|
2514
|
+
exports.resolveSpriteClip = resolveSpriteClip;
|
|
2402
2515
|
exports.resource = resource;
|
|
2403
2516
|
exports.resourceLoader = resourceLoader;
|
|
2404
2517
|
exports.shouldPauseRendering = shouldPauseRendering;
|
|
2518
|
+
exports.spriteClipKeyOrder = spriteClipKeyOrder;
|
|
2405
2519
|
exports.version = version;
|
|
2406
2520
|
//# sourceMappingURL=engine.cjs.js.map
|