Skip to content

Commit

Permalink
put mission deserialization code in mission
Browse files Browse the repository at this point in the history
No need to split
  • Loading branch information
BarthPaleologue committed Oct 9, 2024
1 parent 8648a65 commit 3edd50e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
14 changes: 0 additions & 14 deletions src/ts/missions/deserializeMission.ts

This file was deleted.

14 changes: 12 additions & 2 deletions src/ts/missions/mission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { MissionNode, MissionNodeSerialized } from "./nodes/missionNode";
import { MissionContext } from "./missionContext";
import { SpaceStationModel } from "../spacestation/spacestationModel";
import { SystemSeed } from "../utils/systemSeed";
import { getUniverseIdForSpaceStationModel } from "../utils/orbitalObjectId";
import { getObjectModelByUniverseId, getUniverseIdForSpaceStationModel } from "../utils/orbitalObjectId";
import i18n from "../i18n";
import { UniverseObjectId } from "../saveFile/universeCoordinates";
import { SeededStarSystemModel } from "../starSystem/seededStarSystemModel";
import { deserializeMissionNode } from "./nodes/deserializeNode";

/**
* Registered mission types. Those are used to display localized strings in the UI
Expand Down Expand Up @@ -116,7 +117,7 @@ export class Mission {
*/
describe(): string {
const originSystem = this.missionGiver.starSystem;
if(!(originSystem instanceof SeededStarSystemModel)) {
if (!(originSystem instanceof SeededStarSystemModel)) {
throw new Error("Mission giver is not in a seeded star system");
}
const originSeed = originSystem.seed;
Expand Down Expand Up @@ -151,4 +152,13 @@ export class Mission {
if (this.isCompleted()) return;
this.tree.updateState(context);
}

static Deserialize(missionSerialized: MissionSerialized) {
return new Mission(
deserializeMissionNode(missionSerialized.tree),
missionSerialized.reward,
getObjectModelByUniverseId(missionSerialized.missionGiver) as SpaceStationModel,
missionSerialized.type
);
}
}
5 changes: 2 additions & 3 deletions src/ts/player/player.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { SystemSeed, SystemSeedSerialized } from "../utils/systemSeed";
import { Mission, MissionSerialized } from "../missions/mission";
import { deserializeMission } from "../missions/deserializeMission";

export type SerializedPlayer = {
name: string;
Expand Down Expand Up @@ -45,8 +44,8 @@ export class Player {
new Date(serializedPlayer.creationDate),
serializedPlayer.currentItinerary.map((seed) => SystemSeed.Deserialize(seed)),
serializedPlayer.systemBookmarks.map((seed) => SystemSeed.Deserialize(seed)),
serializedPlayer.currentMissions.map((mission) => deserializeMission(mission)),
serializedPlayer.completedMissions.map((mission) => deserializeMission(mission))
serializedPlayer.currentMissions.map((mission) => Mission.Deserialize(mission)),
serializedPlayer.completedMissions.map((mission) => Mission.Deserialize(mission))
);
}

Expand Down

0 comments on commit 3edd50e

Please sign in to comment.