mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Fix serialization errors and implement hub deserialization
This commit is contained in:
parent
330c98267a
commit
a1fd83c03c
@ -35,7 +35,24 @@ export class HubGoals extends BasicSerializableObject {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
console.error("TODO: HubGoals deserialize() properly");
|
||||
// Compute gained rewards
|
||||
for (let i = 0; i < this.level; ++i) {
|
||||
if (i < tutorialGoals.length) {
|
||||
const reward = tutorialGoals[i].reward;
|
||||
this.gainedRewards[reward] = (this.gainedRewards[reward] || 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Compute upgrade improvements
|
||||
for (const upgradeId in UPGRADES) {
|
||||
const upgradeHandle = UPGRADES[upgradeId];
|
||||
const level = this.upgradeLevels[upgradeId] || 0;
|
||||
let totalImprovement = upgradeHandle.baseValue || 1;
|
||||
for (let i = 0; i < level; ++i) {
|
||||
totalImprovement += upgradeHandle.tiers[i].improvement;
|
||||
}
|
||||
this.upgradeImprovements[upgradeId] = totalImprovement;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,7 +80,6 @@ export class HUDGameMenu extends BaseHUDPart {
|
||||
}
|
||||
|
||||
onGameSaved() {
|
||||
console.log("ON GAME SAVED");
|
||||
this.saveButton.classList.toggle("animEven");
|
||||
this.saveButton.classList.toggle("animOdd");
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ function compressObjectInternal(obj, keys = [], values = []) {
|
||||
result.push(compressObjectInternal(obj[i], keys, values));
|
||||
}
|
||||
return result;
|
||||
} else if (typeof obj === "object") {
|
||||
} else if (typeof obj === "object" && obj !== null) {
|
||||
let result = {};
|
||||
for (const key in obj) {
|
||||
let index = keys.indexOf(key);
|
||||
@ -108,7 +108,7 @@ function decompressObjectInternal(obj, keys = [], values = []) {
|
||||
result.push(decompressObjectInternal(obj[i], keys, values));
|
||||
}
|
||||
return result;
|
||||
} else if (typeof obj === "object") {
|
||||
} else if (typeof obj === "object" && obj !== null) {
|
||||
let result = {};
|
||||
for (const key in obj) {
|
||||
const realIndex = decompressInt(key);
|
||||
@ -124,11 +124,11 @@ function decompressObjectInternal(obj, keys = [], values = []) {
|
||||
}
|
||||
|
||||
export function decompressObject(obj) {
|
||||
if (G_IS_DEV) {
|
||||
return obj;
|
||||
}
|
||||
if (obj.keys && obj.values && obj.data) {
|
||||
const keys = obj.keys;
|
||||
const values = obj.values;
|
||||
const result = decompressObjectInternal(obj.data, keys, values);
|
||||
return result;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ export class SavegameSerializer {
|
||||
if (!verifyResult.result) {
|
||||
return ExplainedResult.bad(verifyResult.reason);
|
||||
}
|
||||
|
||||
console.log("SAVEGAME:", savegame);
|
||||
let errorReason = null;
|
||||
|
||||
errorReason = errorReason || root.entityMgr.deserialize(savegame.entityMgr);
|
||||
|
@ -82,7 +82,7 @@ export class MainMenuState extends GameState {
|
||||
for (let i = 0; i < games.length; ++i) {
|
||||
const elem = makeDiv(parent, null, ["savegame"]);
|
||||
|
||||
makeDiv(elem, null, ["internalId"], games[i].internalId.substr(0, 15));
|
||||
makeDiv(elem, null, ["internalId"], games[i].internalId.substr(0, 6));
|
||||
makeDiv(
|
||||
elem,
|
||||
null,
|
||||
|
Loading…
Reference in New Issue
Block a user