stable
This commit is contained in:
parent
fbdac9ebf1
commit
86226ccc94
97 changed files with 5790 additions and 2307 deletions
|
|
@ -2,24 +2,23 @@
|
|||
|
||||
(function (global) {
|
||||
const Snapshot = global.TarinaiSnapshot;
|
||||
const SaveSchema = global.TarinaiSaveSchema;
|
||||
if (!Snapshot) throw new Error("TarinaiSnapshot is not available for save_codec.js");
|
||||
if (!SaveSchema) throw new Error("TarinaiSaveSchema is not available for save_codec.js");
|
||||
const EXPORT_PREFIX = "たり";
|
||||
const RAW_CODEC = "生";
|
||||
const DEFLATE_CODEC = "縮";
|
||||
const BINARY_SCHEMA_VERSION = 5;
|
||||
const MIN_BINARY_SCHEMA_VERSION = 4;
|
||||
const FIELD_IDS = Object.freeze(["garden", "cage", "park"]);
|
||||
const GROUND_IDS = Object.freeze(["soil", "concrete", "blanket", "foot_massage", "ice"]);
|
||||
const ITEM_TYPE_IDS = Object.freeze([
|
||||
"grass", "zunchi", "water", "grass_bed", "plushie", "nest_box", "duplicator", "sweet", "love_mochi", "fight_mochi",
|
||||
"sleep_drug", "laxative", "protein", "niteropu", "ammo", "mystery_drug", "mercury", "giant_drug", "dwarf_drug", "zunda_juice",
|
||||
"stone", "ball", "signboard", "ant_nest", "ant_corpse", "firecracker", "pushpin", "oshibyo", "fence_v", "fence_h",
|
||||
"splat", "food", "bed", "genkotsu", "bounce_fence", "bounce_fence_v", "gate_fence", "fan", "magnet"
|
||||
]);
|
||||
const STRUCTURE_TYPE_IDS = new Set([3, 4]);
|
||||
const SERVING_FOOD_TYPE_IDS = new Set([7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 31]);
|
||||
const PIN_TYPE_IDS = new Set([26, 27]);
|
||||
const ROTATABLE_ITEM_TYPE_IDS = new Set([28, 29, 34, 35, 36, 37, 38]);
|
||||
const {
|
||||
BINARY_SCHEMA_VERSION,
|
||||
MIN_BINARY_SCHEMA_VERSION,
|
||||
FIELD_IDS,
|
||||
GROUND_IDS,
|
||||
ITEM_TYPE_IDS,
|
||||
STRUCTURE_TYPE_IDS,
|
||||
SERVING_FOOD_TYPE_IDS,
|
||||
PIN_TYPE_IDS,
|
||||
ROTATABLE_ITEM_TYPE_IDS,
|
||||
} = SaveSchema;
|
||||
|
||||
const textEncoder = new TextEncoder();
|
||||
const textDecoder = new TextDecoder();
|
||||
|
|
@ -454,7 +453,7 @@
|
|||
}
|
||||
|
||||
function writeWorld(writer, w = []) {
|
||||
writeBitFields(writer, [w[0] || 0, w[1] || 0, w[2] || 0, w[4] || 0], [2, 2, 4, 3]);
|
||||
writeBitFields(writer, [w[0] || 0, w[1] || 0, w[2] || 0, w[4] || 0], [2, 3, 4, 3]);
|
||||
writer.u(w[3] || 0); // worldTick10
|
||||
writer.s(w[5] || 0); // lastBirthAt10 can be negative
|
||||
writer.u(w[6] || 1); // generation
|
||||
|
|
@ -463,7 +462,12 @@
|
|||
writer.u(w[9] || 0); // birthSerial
|
||||
}
|
||||
function readWorld(reader) {
|
||||
const [field, ground, mood, weather] = readBitFields(reader, [2, 2, 4, 3]);
|
||||
const schema = reader.schemaVersion || BINARY_SCHEMA_VERSION;
|
||||
const groundBits = schema >= 6 ? 3 : 2;
|
||||
const [field, rawGround, mood, weather] = readBitFields(reader, [2, groundBits, 4, 3]);
|
||||
// Schema 5 and earlier used [soil, concrete, blanket, foot_massage] in two bits.
|
||||
// Schema 6 inserts the new high-growth dirt at index 1, so old indices are remapped here.
|
||||
const ground = schema >= 6 ? rawGround : ([0, 2, 3, 4][Number(rawGround) | 0] ?? 0);
|
||||
return [field, ground, mood, reader.u(), weather, reader.s(), reader.u(), reader.u(), reader.str(), reader.u()];
|
||||
}
|
||||
|
||||
|
|
@ -545,6 +549,8 @@
|
|||
writer.str(extra[0] || "");
|
||||
} else if (typeId === 6) { // duplicator
|
||||
writer.s(extra[0] ?? -1);
|
||||
} else if (typeId === 39) { // rotator
|
||||
writer.str(JSON.stringify(extra || []));
|
||||
} else if (typeId === 21) { // ball
|
||||
writer.s(extra[0] || 0); writer.s(extra[1] || 0);
|
||||
} else if (typeId === 23) { // ant_nest
|
||||
|
|
@ -567,6 +573,7 @@
|
|||
if (typeId === 1) return [reader.u(), reader.s(), reader.s()];
|
||||
if (typeId === 22) return [reader.str()];
|
||||
if (typeId === 6) return [reader.s()];
|
||||
if (typeId === 39) return [reader.str()];
|
||||
if (typeId === 21) return [reader.s(), reader.s()];
|
||||
if (typeId === 23) return [reader.s(), reader.s()];
|
||||
if (typeId === 24) return [reader.s()];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue