Skip to content

Commit

Permalink
Merge pull request #40 from colecrouter/farmhands
Browse files Browse the repository at this point in the history
  • Loading branch information
colecrouter authored Nov 25, 2024
2 parents 1c5835d + 70920f8 commit c58d1cb
Show file tree
Hide file tree
Showing 16 changed files with 817 additions and 469 deletions.
19 changes: 11 additions & 8 deletions src/lib/proxies/SaveFile.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,17 @@ export class SaveProxy {

get players() {
if (!this.raw) return [];
const farmers =
this.raw.SaveGame.farmhands.Farmer === undefined
const unfiltered =
this.raw.SaveGame.farmhands === ""
? []
: Array.isArray(this.raw.SaveGame.farmhands.Farmer)
? this.raw.SaveGame.farmhands.Farmer
: [this.raw.SaveGame.farmhands.Farmer];
: this.raw.SaveGame.farmhands.Farmer;
const farmers = unfiltered.filter((f) => f !== undefined);
const mainPlayer = this.raw.SaveGame.player;

return [mainPlayer, ...farmers].map((f) => new Farmer(f));
}

set players(players: Farmer[]) {
set players(players) {
if (!this.raw) return;
if (!players[0]) throw new Error("Main player is required");

Expand All @@ -86,11 +85,15 @@ export class SaveProxy {

if (mainPlayer === undefined)
throw new Error("Main player is required");
if (someTyped(farmhands) === false)
if (farmhands.length && someTyped(farmhands) === false)
throw new Error("Farmhands are required");

this.raw.SaveGame.player = mainPlayer;
this.raw.SaveGame.farmhands.Farmer = farmhands;
if (this.raw.SaveGame.farmhands === "") {
this.raw.SaveGame.farmhands = { Farmer: farmhands };
} else {
this.raw.SaveGame.farmhands.Farmer = farmhands;
}
}

get farm() {
Expand Down
8 changes: 7 additions & 1 deletion src/lib/save.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { XMLParser } from "fast-xml-parser";
// The XML parser has no idea what should be an array and what should be an object
// This isn't a huge deal, but we can make it a little easier to work with by
// supplying a list of things we want to be arrays
const arrayTags = new Set(["item", "GameLocations", "characters", "objects"]);
const arrayTags = new Set([
"item",
"GameLocations",
"characters",
"objects",
"Farmer",
]);

export const importSave = async (file: File) => {
if (!file) {
Expand Down
1 change: 1 addition & 0 deletions src/lib/ui/UIContainerSmall.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
0 0 0 2px #b14e05,
0 0 0 4px #dc7b05,
0 0 0 6px #5b2b29;
pointer-events: none;
}
.outer {
Expand Down
9 changes: 6 additions & 3 deletions src/routes/(edit)/(list)/cooking/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<script lang="ts">
import { saveManager } from "$lib/save.svelte";
import Recipes from "../Recipes.svelte";
const save = saveManager.save;
if (!save) throw new Error("No save data found");
</script>

{#if saveManager.save}
<Recipes recipes={saveManager.save.player.cookingRecipes} />
{/if}
{#key save.player}
<Recipes recipes={save.player.cookingRecipes} />
{/key}
9 changes: 6 additions & 3 deletions src/routes/(edit)/(list)/crafting/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<script lang="ts">
import { saveManager } from "$lib/save.svelte";
import Recipes from "../Recipes.svelte";
const save = saveManager.save;
if (!save) throw new Error("No save data found");
</script>

{#if saveManager.save}
<Recipes recipes={saveManager.save.player.craftingRecipes} />
{/if}
{#key save.player}
<Recipes recipes={save.player.craftingRecipes} />
{/key}
7 changes: 4 additions & 3 deletions src/routes/(edit)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@
>
💾
</UiButton>
<UiButton alt="Previous Character" onclick={save?.prevFarmer}
>⬅️</UiButton
<UiButton
alt="Previous Character"
onclick={() => save?.prevFarmer()}>⬅️</UiButton
>
<UiButton alt="Next Character" onclick={save?.nextFarmer}
<UiButton alt="Next Character" onclick={() => save?.nextFarmer()}
>➡️</UiButton
>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/routes/(edit)/Router.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<UiButton href={`${base}/relationships`} alt="Relationships">💖</UiButton>
<UiButton href={`${base}/crafting`} alt="Crafting">🔨</UiButton>
<UiButton href={`${base}/cooking`} alt="Cooking">🍫</UiButton>
<UiButton href={`${base}/farmhands`} alt="Farmhands">👩‍🌾</UiButton>
<UiButton href={`${base}/bundles`} alt="Community Center">🎁</UiButton>
</nav>

Expand Down
136 changes: 69 additions & 67 deletions src/routes/(edit)/appearance/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,90 +23,92 @@
["Hair", "hairstyle", 0, 72],
["Acc", "accessory", -1, 29],
] satisfies [string, keyof Farmer, number, number][];
let player = saveManager.save?.player;
const save = saveManager.save;
if (!save) throw new Error("No player data found");
</script>

<UiContainer>
{#if player}
<div class="wrapper">
<div class="editor1">
<Preview {player} />
<div class="selector">
<div class="wrapper">
<div class="editor1">
<Preview player={save.player} />
<div class="selector">
<label>
🚹
<input
type="radio"
name="gender"
value="male"
checked={save.player &&
save.player.gender === Gender.Male}
onclick={() =>
save.player && (save.player.gender = Gender.Male)}
/>
</label>
<label>
🚺
<input
type="radio"
name="gender"
value="female"
checked={save.player &&
save.player.gender === Gender.Female}
onclick={() =>
save.player && (save.player.gender = Gender.Female)}
/>
</label>
</div>
<div class="appearance">
{#each numberFields as [label, key, min, max]}
<label>
🚹
{label}
<input
type="radio"
name="gender"
value="male"
checked={player && player.gender === Gender.Male}
onclick={() =>
player && (player.gender = Gender.Male)}
type="number"
data-testid={`appearance-${key}`}
{min}
{max}
bind:value={save.player[key]}
/>
</label>
{/each}
</div>
</div>
<div class="editor2">
{#each textFields as [label, key]}
<div>
<label>
🚺
<small>{label}</small>
<input
type="radio"
name="gender"
value="female"
checked={player && player.gender === Gender.Female}
onclick={() =>
player && (player.gender = Gender.Female)}
type="text"
data-testid={`appearance-${key}`}
bind:value={save.player[key]}
/>
</label>
</div>
<div class="appearance">
{#each numberFields as [label, key, min, max]}
<label>
{label}
{/each}
{#each colorFields as [label, key]}
<div>
<label>
<small>{label}</small>
<div class="selector">
<input
type="number"
type="color"
data-testid={`appearance-${key}`}
{min}
{max}
bind:value={player[key]}
value={save.player[key].toHex()}
onchange={(e) => {
save.player[key] = new Color(
// @ts-expect-error
e.target.value ?? "#0000FF",
);
// console.log(save.player[key].toHex());
}}
/>
</label>
{/each}
</div>
</label>
</div>
</div>
<div class="editor2">
{#each textFields as [label, key]}
<div>
<label>
<small>{label}</small>
<input
type="text"
data-testid={`appearance-${key}`}
bind:value={player[key]}
/>
</label>
</div>
{/each}
{#each colorFields as [label, key]}
<div>
<label>
<small>{label}</small>
<div class="selector">
<input
type="color"
data-testid={`appearance-${key}`}
value={player[key].toHex()}
onchange={(e) => {
player[key] = new Color(
// @ts-expect-error
e.target.value ?? "#0000FF",
);
// console.log(player[key].toHex());
}}
/>
</div>
</label>
</div>
{/each}
</div>
{/each}
</div>
{/if}
</div>
</UiContainer>

<style>
Expand Down
Loading

0 comments on commit c58d1cb

Please sign in to comment.