1.9
This commit is contained in:
parent
fc7c94bd69
commit
2cc2f003df
71 changed files with 3359 additions and 1027 deletions
|
|
@ -33,7 +33,7 @@
|
|||
return Number.isFinite(n) ? n / scale : fallback;
|
||||
}
|
||||
|
||||
function birthHash32(seed = "") {
|
||||
const birthHash32 = global.TarinaiCoreHelpers?.birthHash32 || (seed => {
|
||||
const match = /^b[0-9a-z]+_([0-9a-z]+)$/i.exec(String(seed || ""));
|
||||
if (match) {
|
||||
const parsed = parseInt(match[1], 36);
|
||||
|
|
@ -46,7 +46,7 @@
|
|||
h = Math.imul(h, 16777619);
|
||||
}
|
||||
return h >>> 0;
|
||||
}
|
||||
});
|
||||
function compactBirthDescriptor(t = null, fallbackSerial = 1) {
|
||||
const seed = String(t?.birthSeed || t?.familyKey || t?.id || "");
|
||||
const parsed = global.TarinaiSeedFactory?.serialFromBirthSeed?.(seed) || 0;
|
||||
|
|
@ -76,7 +76,7 @@
|
|||
const proto = Object.getPrototypeOf(value);
|
||||
return proto === Object.prototype || proto === null;
|
||||
}
|
||||
function clonePlain(value, depth = 0) {
|
||||
function cloneSnapshotPlain(value, depth = 0) {
|
||||
if (value == null) return value;
|
||||
const type = typeof value;
|
||||
if (type === "number") return Number.isFinite(value) ? value : 0;
|
||||
|
|
@ -86,7 +86,7 @@
|
|||
if (Array.isArray(value)) {
|
||||
const out = [];
|
||||
for (const v of value) {
|
||||
const c = clonePlain(v, depth + 1);
|
||||
const c = cloneSnapshotPlain(v, depth + 1);
|
||||
if (c !== undefined) out.push(c);
|
||||
}
|
||||
return out;
|
||||
|
|
@ -95,7 +95,7 @@
|
|||
const out = {};
|
||||
for (const [key, v] of Object.entries(value)) {
|
||||
if (DEFAULT_SKIP.has(key)) continue;
|
||||
const c = clonePlain(v, depth + 1);
|
||||
const c = cloneSnapshotPlain(v, depth + 1);
|
||||
if (c !== undefined) out[key] = c;
|
||||
}
|
||||
return out;
|
||||
|
|
@ -417,6 +417,7 @@
|
|||
if (type === "zunchi") return [enumIndex(STAGE_IDS, item.stage || "fresh"), q(item.freshness, 100), q(item.fertility, 100)];
|
||||
if (type === "signboard") return [item.text || ""];
|
||||
if (type === "robot_cleaner") return [Math.max(0, Math.min(0x3f, Number(item.robotCleanerMask ?? 3) | 0)), item.robotCleanerHighSpeed ? 1 : 0];
|
||||
if (type === "circuit_board") return [JSON.stringify(global.TarinaiCircuitBoardSystem?.serializeConfig?.(item) || item.circuitConfig || {})];
|
||||
if (global.TarinaiPhysicsBodySystem.isPhysicsType(type)) {
|
||||
const packed = global.TarinaiPhysicsBodySystem.compactItemExtra(item, tarinaiIndex, itemIndex);
|
||||
if (packed) return packed;
|
||||
|
|
@ -427,7 +428,7 @@
|
|||
if (type === "ant_nest") return [q(item.antCount, 1), q(item.queenSpawnAt, 10)];
|
||||
if (type === "ant_corpse") return [q(item.decayTimer, 10)];
|
||||
if (type === "firecracker" || type === "flame_firecracker") return [q(item.fuseTimer, 10)];
|
||||
if (type === "sticky_bomb") return [q(item.fuseTimer, 10), tarinaiIndex.get(item.stickyBombCarrierId) ?? -1];
|
||||
if (type === "sticky_bomb") return [q(item.fuseTimer, 10), tarinaiIndex.get(item.stickyBombCarrierId) ?? -1, q(item.stickyBombPassCount, 1)];
|
||||
if (type === "fire") return [q(item.flameLife, 10)];
|
||||
if (type === "nest_box") return [q(item.burnTimer, 10), q(item.nestFireEvacuationTimer, 10), item.burning ? 1 : 0, item.nestFireEvacuated ? 1 : 0];
|
||||
if (global.isPinType(type)) return [enumIndex(PIN_STATE_IDS, item.pinState || "loose"), tarinaiIndex.get(item.pinTargetId) ?? -1, q(item.pinAttachAngle, 1000), q(item.pinAttachDistance, 10), q(item.pinOffsetY, 10)];
|
||||
|
|
@ -444,8 +445,8 @@
|
|||
const targets = ["tarinai", "item", "time", "hunger_avg", "stress_avg", "sleep_avg", "low_hp_count", "sick_count", "temperature", "zunchi_count", "ant_count", "water_count"];
|
||||
return [
|
||||
Math.max(0, targets.indexOf(item.pressureTarget || "tarinai")),
|
||||
item.pressureComparator === "lte" ? 1 : 0,
|
||||
q(item.pressureThreshold ?? 1, 10),
|
||||
q(item.pressureMin ?? 1, 10),
|
||||
q(item.pressureMax ?? 300, 10),
|
||||
Math.max(60, Math.min(840, Number(item.pressureWidth || 220) | 0)),
|
||||
Math.max(60, Math.min(840, Number(item.pressureHeight || 160) | 0)),
|
||||
Math.max(0, Math.min(1435, Number(item.pressureTimeStart ?? 360) | 0)),
|
||||
|
|
@ -483,8 +484,8 @@
|
|||
const def = global.StructureRegistry?.get?.(type);
|
||||
if (def) {
|
||||
item.label = def.label;
|
||||
item.roles = clonePlain(def.roles) || item.roles || {};
|
||||
item.needEffects = clonePlain(def.needEffects) || item.needEffects || {};
|
||||
item.roles = cloneSnapshotPlain(def.roles) || item.roles || {};
|
||||
item.needEffects = cloneSnapshotPlain(def.needEffects) || item.needEffects || {};
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -516,7 +517,7 @@
|
|||
} else if (type === "firecracker" || type === "flame_firecracker") {
|
||||
item.fuseTimer = u(extra[0], 10); item.fuseMax = Math.max(item.fuseMax || 5, item.fuseTimer || 0);
|
||||
} else if (type === "sticky_bomb") {
|
||||
item.fuseTimer = u(extra[0], 10, item.fuseTimer || 12); item.fuseMax = Math.max(item.fuseMax || 12, item.fuseTimer || 0); item.stickyBombCarrierId = tarinaiList[extra[1]]?.id || "";
|
||||
item.fuseTimer = u(extra[0], 10, item.fuseTimer || 12); item.fuseMax = Math.max(item.fuseMax || 12, item.fuseTimer || 0); item.stickyBombCarrierId = tarinaiList[extra[1]]?.id || ""; item.stickyBombPassCount = Math.max(0, u(extra[2], 1, 0));
|
||||
} else if (type === "fire") {
|
||||
item.flameLife = u(extra[0], 10, item.flameLife || 6);
|
||||
} else if (type === "nest_box") {
|
||||
|
|
@ -530,6 +531,11 @@
|
|||
}
|
||||
} else if (global.isPinType(type)) {
|
||||
item.pinState = enumValue(PIN_STATE_IDS, extra[0], "loose"); item.pinTargetId = tarinaiList[extra[1]]?.id || ""; item.pinAttachAngle = u(extra[2], 1000); item.pinAttachDistance = u(extra[3], 10); item.pinOffsetY = u(extra[4], 10);
|
||||
} else if (type === "circuit_board") {
|
||||
let config = {};
|
||||
try { config = JSON.parse(String(extra[0] || "{}")); } catch (_) { config = {}; }
|
||||
global.TarinaiCircuitBoardSystem?.applySerializedConfig?.(item, config);
|
||||
global.TarinaiCircuitBoardSystem?.evaluate?.(item);
|
||||
} else if (type === "fan") {
|
||||
const fallback = global.defaultItemAngle(type);
|
||||
item.angle = global.normalizedItemAngle(u(extra[0], 1000, fallback), fallback);
|
||||
|
|
@ -542,8 +548,9 @@
|
|||
} else if (type === "pressure_switch") {
|
||||
const targets = ["tarinai", "item", "time", "hunger_avg", "stress_avg", "sleep_avg", "low_hp_count", "sick_count", "temperature", "zunchi_count", "ant_count", "water_count"];
|
||||
item.pressureTarget = targets[Number(extra[0]) | 0] || "tarinai";
|
||||
item.pressureComparator = Number(extra[1]) === 1 ? "lte" : "gte";
|
||||
item.pressureThreshold = u(extra[2], 10, 1);
|
||||
item.pressureMin = u(extra[1], 10, 1);
|
||||
item.pressureMax = u(extra[2], 10, 300);
|
||||
if (item.pressureMin > item.pressureMax) { const swap = item.pressureMin; item.pressureMin = item.pressureMax; item.pressureMax = swap; }
|
||||
item.pressureWidth = Math.max(60, Math.min(840, Number(extra[3] || 220) | 0));
|
||||
item.pressureHeight = Math.max(60, Math.min(840, Number(extra[4] || 160) | 0));
|
||||
item.pressureTimeStart = Math.max(0, Math.min(1435, Number(extra[5] ?? 360) | 0));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue