Skip to content

Commit

Permalink
Fixed editing farmhands
Browse files Browse the repository at this point in the history
  • Loading branch information
colecrouter committed Jun 23, 2024
1 parent 448f1b9 commit b5111ee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/lib/SaveFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CharacterSelector {
this._character.set(save.SaveGame.player);

// Set the players array, so we can iterate over it
this._players = [save.SaveGame.player, ...save.SaveGame.locations.GameLocation.find((loc) => loc.name === "Farm")?.buildings?.Building.map((b) => b.indoors?.farmhand!).filter((f) => f) ?? []];
this._players = [save.SaveGame.player, ...save.SaveGame.farmhands.Farmer ?? []];
};

public next = () => {
Expand Down Expand Up @@ -126,11 +126,11 @@ export const SaveConverter = {

// Get an array of player and farmhands
// We have to apply a handful of changes to each of them, so it's easier to do it in a loop, rather than doing them separately
const players = [json.SaveGame.player, ...json.SaveGame.locations.GameLocation.find((loc) => loc.name === "Farm")?.buildings?.Building.map((b) => b.indoors?.farmhand!).filter((f) => f) ?? []];
const players = [json.SaveGame.player, ...json.SaveGame.farmhands.Farmer ?? []];

// Type safety enhancements
// 1. Inventory, switch <string xsi:nil="true" /> into undefined
players.forEach((player) => player.items.Item = player.items.Item.map((item) => JSON.stringify(item) === '{"@_xsi:nil":"true"}' ? undefined : item));
players.forEach((player) => player.items.Item = player.items.Item.map((item) => JSON.stringify(item) === '{"@_xsi:nil":"true"}' ? undefined : item) as any);
// 2. For some reason, if your character knows only 1 crafting or cooking recipe, it will be an object, not an array
players.forEach((player) => {
if (player.craftingRecipes?.item && !Array.isArray(player.craftingRecipes.item)) {
Expand All @@ -149,7 +149,7 @@ export const SaveConverter = {

// Get an array of player and farmhands
// We have to apply a handful of changes to each of them, so it's easier to do it in a loop, rather than doing them separately
const players = [json.SaveGame.player, ...json.SaveGame.locations.GameLocation.find((loc) => loc.name === "Farm")?.buildings?.Building.map((b) => b.indoors?.farmhand!).filter((f) => f) ?? []];
const players = [json.SaveGame.player, ...json.SaveGame.farmhands.Farmer ?? []];

// Undo type safety enhancements
// 1. Inventory, switch undefined into <string xsi:nil="true" /> (for farmhands, too)
Expand Down
3 changes: 1 addition & 2 deletions src/types/save/1.6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { FurnitureType } from "$types/items/1.6";

export interface Save {
player: Player;
farmhands: string;
farmhands: { Farmer: Player[]; };
locations: Locations;
currentSeason: Season;
samBandName?: string;
Expand Down Expand Up @@ -624,7 +624,6 @@ export interface Indoors {
appliedWallpaper?: IndoorsAppliedFloor;
floor?: string;
appliedFloor?: IndoorsAppliedFloor;
farmhand?: Player;
}

export interface IndoorsAnimals {
Expand Down

0 comments on commit b5111ee

Please sign in to comment.