This commit is contained in:
33333-33333 2026-07-10 16:40:06 +09:00
commit 2636d580a8
75 changed files with 3890 additions and 1084 deletions

View file

@ -11,14 +11,20 @@
return (h >>> 0).toString(36);
}
function worldSeedFromWords(high = 0, low = 0) {
return `w${(Number(high) >>> 0).toString(16).padStart(8, "0")}${(Number(low) >>> 0).toString(16).padStart(8, "0")}`;
}
function createWorldSeed() {
const cryptoObj = global.crypto;
if (cryptoObj?.getRandomValues) {
const buf = new Uint32Array(2);
cryptoObj.getRandomValues(buf);
return `w${buf[0].toString(36)}${buf[1].toString(36)}`;
return worldSeedFromWords(buf[0], buf[1]);
}
return `w${Date.now().toString(36)}${Math.floor(Math.random() * 0xffffffff).toString(36)}`;
const high = Math.floor(Date.now() / 0x100000000) ^ Math.floor(Math.random() * 0xffffffff);
const low = (Date.now() >>> 0) ^ Math.floor(Math.random() * 0xffffffff);
return worldSeedFromWords(high, low);
}
function ensureWorldSeed(worldRef = null) {
@ -49,10 +55,9 @@
if (!next.birthSeed) {
worldRef.birthSerial = Math.max(0, Number(worldRef.birthSerial) || 0) + 1;
next.birthSerial = worldRef.birthSerial;
const parentSeeds = Array.isArray(next.seedParents)
? next.seedParents.map(p => typeof p === "string" ? p : (p?.birthSeed || p?.familyKey || p?.id || ""))
: [];
next.birthSeed = childSeed(worldRef.worldSeed, next.birthSerial, parentSeeds);
// Save schema 33 derives identity from worldSeed + birthSerial. Parentage is
// stored independently, so it must not be duplicated inside birthSeed.
next.birthSeed = childSeed(worldRef.worldSeed, next.birthSerial, []);
} else {
if (!Number.isFinite(next.birthSerial)) {
const parsedSerial = serialFromBirthSeed(next.birthSeed);
@ -142,6 +147,7 @@
global.TarinaiSeedFactory = Object.freeze({
createWorldSeed,
worldSeedFromWords,
ensureWorldSeed,
childSeed,
serialFromBirthSeed,