Skip to content

Commit 4529461

Browse files
fix(data): fix processing saves with missing country types, trade hubs, or planet species population
1 parent f457310 commit 4529461

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

‎src/renderer/src/lib/GameState.ts‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ const galacticObjectSchema = z
6565
.optional(),
6666
planet: z.number().optional(),
6767
fleet_presence: z.array(z.number()).default([]),
68-
trade_hub: z.object({
69-
collected: z.number().optional(), // this does NOT include value delivered by other trade routes
70-
destination: z.number().optional(), // trade_route ID
71-
collected_from: z.array(z.number()).optional(), // galactic_object IDs
72-
sources: z.array(z.number()).optional(), // trade_route IDs
73-
}),
68+
trade_hub: z
69+
.object({
70+
collected: z.number().optional(), // this does NOT include value delivered by other trade routes
71+
destination: z.number().optional(), // trade_route ID
72+
collected_from: z.array(z.number()).optional(), // galactic_object IDs
73+
sources: z.array(z.number()).optional(), // trade_route IDs
74+
})
75+
.optional(), // pre-4.0 only
7476
asteroid_belts: z
7577
.array(
7678
z.object({
@@ -101,7 +103,10 @@ const planetSchema = z.object({
101103
owner: z.number().optional(),
102104
num_sapient_pops: z.number().optional(),
103105
species_information: z
104-
.record(z.string(), z.object({ num_pops: z.number(), num_enslaved: z.number().optional() }))
106+
.record(
107+
z.string(),
108+
z.object({ num_pops: z.number().optional(), num_enslaved: z.number().optional() }),
109+
)
105110
.optional(),
106111
planet_size: z.number(),
107112
planet_class: z.string(),
@@ -165,7 +170,7 @@ const relationSchema = z.object({
165170
export type Relation = z.infer<typeof relationSchema>;
166171

167172
const countrySchema = z.object({
168-
type: z.string(),
173+
type: z.string().default('unknown'),
169174
name: localizedTextSchema,
170175
flag: z
171176
.object({

‎src/renderer/src/lib/map/data/mapModes.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export const mapModes: Record<string, MapMode> = {
216216
gameState.species_db[speciesId]?.base_ref === selectedSpecies.id)
217217
) {
218218
freePlanetPopulation +=
219-
speciesPopulation.num_pops - (speciesPopulation.num_enslaved ?? 0);
219+
(speciesPopulation.num_pops ?? 0) - (speciesPopulation.num_enslaved ?? 0);
220220
enslavedPlanetPopulation += speciesPopulation.num_enslaved ?? 0;
221221
}
222222
}
@@ -369,10 +369,10 @@ export const mapModes: Record<string, MapMode> = {
369369
scale: 0.25,
370370
getValues(gameState, system, povCountry, _species, owner) {
371371
const ownedByPov = owner != null && owner.id === povCountry?.id;
372-
const collectedValue = !ownedByPov ? 0 : system.trade_hub.collected ?? 0;
372+
const collectedValue = !ownedByPov ? 0 : system.trade_hub?.collected ?? 0;
373373
const incomingValue = !ownedByPov
374374
? undefined
375-
: system.trade_hub.sources?.reduce(
375+
: system.trade_hub?.sources?.reduce(
376376
(acc, cur) => acc + (gameState.trade_routes[cur]?.delivered ?? 0),
377377
0,
378378
);

0 commit comments

Comments
 (0)