-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
389e72d
commit ef52c84
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { Player, Save } from "$types/save/1.6"; | ||
|
||
class SaveClass { | ||
private filename = $state<string>(); | ||
private saveData = $state<Save>(); | ||
|
||
public players = $state<Player[]>([]); | ||
|
||
constructor() { | ||
// Update players array when save data changes | ||
$effect(() => { | ||
// Clear the players array when the save data changes | ||
if (!this.saveData) { | ||
this.players = []; | ||
return; | ||
} | ||
|
||
const farmers = | ||
this.saveData.farmhands.Farmer === undefined | ||
? [] | ||
: Array.isArray(this.saveData.farmhands.Farmer) | ||
? this.saveData.farmhands.Farmer | ||
: [this.saveData.farmhands.Farmer]; | ||
const mainPlayer = this.saveData.player; | ||
|
||
this.players = [mainPlayer, ...farmers]; | ||
}); | ||
|
||
// Update save data when the players array changes | ||
$effect(() => { | ||
if (!this.saveData) return; | ||
|
||
this.saveData.player = this.players[0]; | ||
this.saveData.farmhands.Farmer = this.players.slice(1); | ||
}); | ||
} | ||
} |