@adatechnology/game-characters 0.2.7 → 0.2.9
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/index.global.js +73 -2
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +24 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -814,7 +814,24 @@ var createCharacterCore = ({ spec, bodySpec, hitPointsOf }) => {
|
|
|
814
814
|
const parts = describeBody({ rig, body: bodySpec, build: spec.build, name: spec.kind });
|
|
815
815
|
const fresh = () => createBodyState({ vitality: spec.vitality, detail: spec.detail, crawling: spec.crawling ?? false, hitPointsOf: hitPointsOf ?? ((kind) => SEGMENT_NUMBERS[kind].hitPoints) });
|
|
816
816
|
const body = fresh();
|
|
817
|
-
|
|
817
|
+
let cachedState;
|
|
818
|
+
const core = {
|
|
819
|
+
spec,
|
|
820
|
+
rig,
|
|
821
|
+
body,
|
|
822
|
+
position: [0, 0, 0],
|
|
823
|
+
rotation: [0, 0, 0, 1],
|
|
824
|
+
describe: () => parts,
|
|
825
|
+
resetBody: () => {
|
|
826
|
+
Object.assign(body, fresh());
|
|
827
|
+
cachedState = void 0;
|
|
828
|
+
},
|
|
829
|
+
readState: () => cachedState ?? (cachedState = toObjectState({ id: spec.id, name: spec.kind, position: core.position, rotation: core.rotation, body, spec: parts })),
|
|
830
|
+
invalidateState: () => {
|
|
831
|
+
cachedState = void 0;
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
return core;
|
|
818
835
|
};
|
|
819
836
|
var characterView = (core) => ({
|
|
820
837
|
id: core.spec.id,
|
|
@@ -832,13 +849,15 @@ var characterView = (core) => ({
|
|
|
832
849
|
if (detail === "regions") regionsFromSegments(core.body);
|
|
833
850
|
else segmentsFromRegions(core.body);
|
|
834
851
|
core.body.detail = detail;
|
|
852
|
+
core.invalidateState();
|
|
835
853
|
},
|
|
836
854
|
setTransform(position, rotation) {
|
|
837
855
|
core.position = [...position];
|
|
838
856
|
if (rotation) core.rotation = [...rotation];
|
|
857
|
+
core.invalidateState();
|
|
839
858
|
},
|
|
840
859
|
describe: core.describe,
|
|
841
|
-
state:
|
|
860
|
+
state: core.readState,
|
|
842
861
|
reset: core.resetBody
|
|
843
862
|
});
|
|
844
863
|
|
|
@@ -1602,7 +1621,9 @@ var createDamageCharacter = (core, setup) => {
|
|
|
1602
1621
|
hitCounter += 1;
|
|
1603
1622
|
const random = core.spec.random ?? createRng((core.spec.seed ^ hitCounter) >>> 0);
|
|
1604
1623
|
const ops = opsFor(random, hit.source);
|
|
1624
|
+
core.invalidateState();
|
|
1605
1625
|
lastHit = applyBlow({ ops, hit, setup, worn, localPoint: toLocal(transform(), hit.point), jointOf, describe: core.describe });
|
|
1626
|
+
core.invalidateState();
|
|
1606
1627
|
return ops.events;
|
|
1607
1628
|
},
|
|
1608
1629
|
update(dt) {
|
|
@@ -1637,6 +1658,7 @@ var createDamageCharacter = (core, setup) => {
|
|
|
1637
1658
|
bleeders = structuredClone(saved.bleeders);
|
|
1638
1659
|
hitCounter = saved.hitCounter;
|
|
1639
1660
|
clock = saved.clock;
|
|
1661
|
+
core.invalidateState();
|
|
1640
1662
|
}
|
|
1641
1663
|
};
|
|
1642
1664
|
return character;
|