Skip to content

Commit

Permalink
fixed it so that if you remove a fish from your inventory it still ke…
Browse files Browse the repository at this point in the history
…eps the record
  • Loading branch information
plaaosert committed Jan 26, 2025
1 parent eae1ec6 commit 2216954
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
28 changes: 15 additions & 13 deletions fishing/fish.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,31 +508,33 @@ const fish_unknown = {
fish_types.forEach((f, i) => f.index = i);

function update_best_fishs(fishs) {
let best_fishs = {};
let old_best_fishs_data = localStorage.getItem("best_fishs");
let old_best_fishs = JSON.parse(old_best_fishs_data ? old_best_fishs_data : "{}");
let new_best_fishs = {};

// overall
best_fishs.overall = {
Longest: fishs.reduce((p, c) => c.length > p.length ? c : p),
Heaviest: fishs.reduce((p, c) => c.weight > p.weight ? c : p),
Rarest: fishs.reduce((p, c) => c.rarity[2] > p.rarity[2] ? c : p),
"Most Valuable": fishs.reduce((p, c) => c.value > p.value ? c : p),
new_best_fishs.overall = {
Longest: fishs.reduce((p, c) => !p || c.length > p.length ? c : p, old_best_fishs.overall?.Longest),
Heaviest: fishs.reduce((p, c) => !p || c.weight > p.weight ? c : p, old_best_fishs.overall?.Heaviest),
Rarest: fishs.reduce((p, c) => !p || c.rarity[2] > p.rarity[2] ? c : p, old_best_fishs.overall?.Rarest),
Most_Valuable: fishs.reduce((p, c) => !p || c.value > p.value ? c : p, old_best_fishs.overall?.Most_Valuable),
};

// per category
fish_types.forEach(typ => {
let filt_fishs = fishs.filter(f => f.type.sprite == typ.sprite);

best_fishs[typ.sprite] = {
Longest: filt_fishs.reduce((p, c) => !p || c.length > p.length ? c : p, null),
Heaviest: filt_fishs.reduce((p, c) => !p || c.weight > p.weight ? c : p, null),
Rarest: filt_fishs.reduce((p, c) => !p || c.rarity[2] > p.rarity[2] ? c : p, null),
"Most Valuable": filt_fishs.reduce((p, c) => !p || c.value > p.value ? c : p, null),
new_best_fishs[typ.sprite] = {
Longest: filt_fishs.reduce((p, c) => !p || c.length > p.length ? c : p, old_best_fishs[typ.sprite]?.Longest),
Heaviest: filt_fishs.reduce((p, c) => !p || c.weight > p.weight ? c : p, old_best_fishs[typ.sprite]?.Heaviest),
Rarest: filt_fishs.reduce((p, c) => !p || c.rarity[2] > p.rarity[2] ? c : p, old_best_fishs[typ.sprite]?.Rarest),
Most_Valuable: filt_fishs.reduce((p, c) => !p || c.value > p.value ? c : p, old_best_fishs[typ.sprite]?.Most_Valuable),
}
});

localStorage.setItem("best_fishs", JSON.stringify(best_fishs));
localStorage.setItem("best_fishs", JSON.stringify(new_best_fishs));

return best_fishs;
return new_best_fishs;
}

function load_fishs() {
Expand Down
5 changes: 4 additions & 1 deletion fishing/fishingscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function sell_fish(fish) {
}

function put_fish_into_inventory(fish) {
fishs.push(JSON.parse(JSON.stringify(fish)));
fishs.push(fish);
localStorage.setItem("fishs", JSON.stringify(fishs));
snd_success.play();
}
Expand Down Expand Up @@ -155,6 +155,9 @@ function get_fish() {
let fishcaught = parseInt(localStorage.getItem("fish_caught"));
localStorage.setItem("fish_caught", fishcaught += 1);

// update best fish including this one
update_best_fishs([...fishs, got_fish]);

update_counters();
}

Expand Down
4 changes: 2 additions & 2 deletions fishing/hall_of_fish.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@
<div id="quality"></div>
</body>
<script src="../helpers.js?v=02"></script>
<script src="fish.js?v=12"></script>
<script src="hall_of_fish.js?v=01"></script>
<script src="fish.js?v=13"></script>
<script src="hall_of_fish.js?v=02"></script>
4 changes: 2 additions & 2 deletions fishing/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
</div>
</body>
<script src="../helpers.js?v=01"></script>
<script src="fish.js?v=12"></script>
<script src="fishingscript.js?v=04"></script>
<script src="fish.js?v=13"></script>
<script src="fishingscript.js?v=05"></script>

0 comments on commit 2216954

Please sign in to comment.