mirror of
https://git.srhtnin.garden/sarah/srhtnin.github.io.git
synced 2026-10-13 18:38:11 +02:00
Added tools and tool upgrades.
This commit is contained in:
1 parent
fbc44883d4
commit
7b804feba8
10 files changed
+2418
-69
No files matched your search
+792
-50
File diff suppressed because it is too large.
Load diff
@@ -76,6 +76,14 @@ async function StartProfile() {
|
||||
|
||||
function BindGardenDisplayPreferences() {
|
||||
const PreferenceButtons = [
|
||||
[
|
||||
"ToggleSelectQuickBoughtPlantButton",
|
||||
"SelectQuickBoughtPlant"
|
||||
],
|
||||
[
|
||||
"ToggleSelectTrowelWithInventoryPlantButton",
|
||||
"SelectTrowelWithInventoryPlant"
|
||||
],
|
||||
[
|
||||
"TogglePlantNamesButton",
|
||||
"ShowPlantNames"
|
||||
@@ -140,11 +148,49 @@ function BindGardenDisplayPreferences() {
|
||||
|
||||
|
||||
function RenderGardenDisplayPreferences() {
|
||||
RenderToolSelectionPreferences();
|
||||
RenderPlantInformationPreferences();
|
||||
RenderGardenOverviewPreferences();
|
||||
}
|
||||
|
||||
|
||||
function RenderToolSelectionPreferences() {
|
||||
const QuickBuyButton =
|
||||
document.getElementById(
|
||||
"ToggleSelectQuickBoughtPlantButton"
|
||||
);
|
||||
|
||||
const TrowelButton =
|
||||
document.getElementById(
|
||||
"ToggleSelectTrowelWithInventoryPlantButton"
|
||||
);
|
||||
|
||||
if (
|
||||
QuickBuyButton === null ||
|
||||
TrowelButton === null
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
SetPreferenceButtonState(
|
||||
QuickBuyButton,
|
||||
"Select bought plant when you quick-buy one",
|
||||
ProfileSave.Preferences
|
||||
.SelectQuickBoughtPlant !==
|
||||
false
|
||||
);
|
||||
|
||||
SetPreferenceButtonState(
|
||||
TrowelButton,
|
||||
"Select trowel when you select an inventory plant",
|
||||
ProfileSave.Preferences
|
||||
.SelectTrowelWithInventoryPlant !==
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function RenderPlantInformationPreferences() {
|
||||
const PlantNamesButton =
|
||||
document.getElementById(
|
||||
@@ -322,6 +368,11 @@ function SetPreferenceButtonState(
|
||||
async function ToggleGardenDisplayPreference(
|
||||
PreferenceName
|
||||
) {
|
||||
const ToolSelectionPreferences = [
|
||||
"SelectQuickBoughtPlant",
|
||||
"SelectTrowelWithInventoryPlant"
|
||||
];
|
||||
|
||||
const PlantInformationPreferences = [
|
||||
"ShowPlantNames",
|
||||
"ShowGrowthTimers"
|
||||
@@ -337,6 +388,11 @@ async function ToggleGardenDisplayPreference(
|
||||
];
|
||||
|
||||
|
||||
const IsToolSelectionPreference =
|
||||
ToolSelectionPreferences.includes(
|
||||
PreferenceName
|
||||
);
|
||||
|
||||
const IsPlantInformationPreference =
|
||||
PlantInformationPreferences.includes(
|
||||
PreferenceName
|
||||
@@ -349,6 +405,7 @@ async function ToggleGardenDisplayPreference(
|
||||
|
||||
|
||||
if (
|
||||
!IsToolSelectionPreference &&
|
||||
!IsPlantInformationPreference &&
|
||||
!IsGardenOverviewPreference
|
||||
) {
|
||||
|
||||
+81
-4
@@ -392,7 +392,7 @@ function CreateNewSave() {
|
||||
|
||||
|
||||
return NormalizeSaveData({
|
||||
Version: 3,
|
||||
Version: 4,
|
||||
Revision: 0,
|
||||
LastSavedAt: Date.now(),
|
||||
|
||||
@@ -413,7 +413,18 @@ function CreateNewSave() {
|
||||
},
|
||||
|
||||
Inventory: {
|
||||
Seeds: SeedInventory
|
||||
Seeds: SeedInventory,
|
||||
Fertilizer: 0
|
||||
},
|
||||
|
||||
Tools: {
|
||||
MagicTrowel: false,
|
||||
Shovel: false,
|
||||
Fertilizer: false,
|
||||
FutureSight: false,
|
||||
ShovelLevel: 0,
|
||||
FertilizerLevel: 0,
|
||||
FutureSightCooldownUntil: 0
|
||||
},
|
||||
|
||||
Upgrades: {
|
||||
@@ -432,7 +443,9 @@ function CreateNewSave() {
|
||||
ShowEmptyPlots: true,
|
||||
ShowPlantedPlots: true,
|
||||
ShowGrowingPlots: true,
|
||||
ShowReadyPlots: true
|
||||
ShowReadyPlots: true,
|
||||
SelectQuickBoughtPlant: true,
|
||||
SelectTrowelWithInventoryPlant: true
|
||||
},
|
||||
|
||||
Gardens: [
|
||||
@@ -456,7 +469,7 @@ function NormalizeSaveData(
|
||||
Number(
|
||||
SaveData.Version ?? 1
|
||||
),
|
||||
3
|
||||
4
|
||||
);
|
||||
|
||||
SaveData.Revision = Number(
|
||||
@@ -492,6 +505,14 @@ function NormalizeSaveData(
|
||||
|
||||
SaveData.Inventory ??= {};
|
||||
SaveData.Inventory.Seeds ??= {};
|
||||
SaveData.Inventory.Fertilizer = Math.max(
|
||||
0,
|
||||
Math.floor(
|
||||
Number(
|
||||
SaveData.Inventory.Fertilizer ?? 0
|
||||
) || 0
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
@@ -563,6 +584,54 @@ function NormalizeSaveData(
|
||||
delete SaveData.Seeds;
|
||||
|
||||
|
||||
SaveData.Tools ??= {};
|
||||
|
||||
SaveData.Tools.MagicTrowel =
|
||||
SaveData.Tools.MagicTrowel === true;
|
||||
|
||||
SaveData.Tools.Shovel =
|
||||
SaveData.Tools.Shovel === true;
|
||||
|
||||
SaveData.Tools.Fertilizer =
|
||||
SaveData.Tools.Fertilizer === true;
|
||||
|
||||
SaveData.Tools.FutureSight =
|
||||
SaveData.Tools.FutureSight === true;
|
||||
|
||||
SaveData.Tools.ShovelLevel = Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
3,
|
||||
Math.floor(
|
||||
Number(
|
||||
SaveData.Tools.ShovelLevel ?? 0
|
||||
) || 0
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
SaveData.Tools.FertilizerLevel = Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
5,
|
||||
Math.floor(
|
||||
Number(
|
||||
SaveData.Tools.FertilizerLevel ?? 0
|
||||
) || 0
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
SaveData.Tools.FutureSightCooldownUntil = Math.max(
|
||||
0,
|
||||
Math.floor(
|
||||
Number(
|
||||
SaveData.Tools.FutureSightCooldownUntil ?? 0
|
||||
) || 0
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
SaveData.Discoveries ??= {};
|
||||
|
||||
SaveData.Discoveries.Plants =
|
||||
@@ -654,6 +723,14 @@ function NormalizeSaveData(
|
||||
SaveData.Preferences.ShowReadyPlots !==
|
||||
false;
|
||||
|
||||
SaveData.Preferences.SelectQuickBoughtPlant =
|
||||
SaveData.Preferences.SelectQuickBoughtPlant !==
|
||||
false;
|
||||
|
||||
SaveData.Preferences.SelectTrowelWithInventoryPlant =
|
||||
SaveData.Preferences.SelectTrowelWithInventoryPlant !==
|
||||
false;
|
||||
|
||||
|
||||
const LegacyGarden =
|
||||
SaveData.Garden ??
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,3 +1,24 @@
|
||||
const MagicTrowelUnlockCost = 1000;
|
||||
const ShovelUnlockCost = 50;
|
||||
const FertilizerUnlockCost = 200;
|
||||
const FutureSightUnlockCost = 5000;
|
||||
|
||||
const ToolUpgradeCostMultiplier = 2;
|
||||
const ShovelMaximumLevel = 3;
|
||||
const FertilizerMaximumLevel = 5;
|
||||
const FertilizerUseCost = 100;
|
||||
const FertilizerGrowthMinutes = [
|
||||
10,
|
||||
20,
|
||||
30,
|
||||
40,
|
||||
50,
|
||||
60
|
||||
];
|
||||
|
||||
const FutureSightCooldown =
|
||||
2 * 60 * 60 * 1000;
|
||||
|
||||
const GardenExpansionBaseCost = 1000;
|
||||
const PlantInformationUpgradeCost = 500;
|
||||
const GardenOverviewUpgradeCost = 1000;
|
||||
@@ -281,3 +302,324 @@ function UnlockMutationHints(
|
||||
SaveData.Upgrades.MutationHints =
|
||||
true;
|
||||
}
|
||||
|
||||
|
||||
function IsGardenToolUnlocked(
|
||||
SaveData,
|
||||
Tool
|
||||
) {
|
||||
if (Tool === "Trowel") {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Tool === "MagicTrowel") {
|
||||
return SaveData?.Tools?.MagicTrowel === true;
|
||||
}
|
||||
|
||||
if (Tool === "Shovel") {
|
||||
return SaveData?.Tools?.Shovel === true;
|
||||
}
|
||||
|
||||
if (Tool === "Fertilizer") {
|
||||
return SaveData?.Tools?.Fertilizer === true;
|
||||
}
|
||||
|
||||
if (Tool === "FutureSight") {
|
||||
return SaveData?.Tools?.FutureSight === true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function GetGardenToolUnlockCost(
|
||||
Tool
|
||||
) {
|
||||
const Costs = {
|
||||
MagicTrowel: MagicTrowelUnlockCost,
|
||||
Shovel: ShovelUnlockCost,
|
||||
Fertilizer: FertilizerUnlockCost,
|
||||
FutureSight: FutureSightUnlockCost
|
||||
};
|
||||
|
||||
return Costs[Tool] ?? null;
|
||||
}
|
||||
|
||||
|
||||
function UnlockGardenTool(
|
||||
SaveData,
|
||||
Tool
|
||||
) {
|
||||
SaveData.Tools ??= {};
|
||||
|
||||
if (
|
||||
![
|
||||
"MagicTrowel",
|
||||
"Shovel",
|
||||
"Fertilizer",
|
||||
"FutureSight"
|
||||
].includes(Tool)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SaveData.Tools[Tool] = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function GetShovelLevel(
|
||||
SaveData
|
||||
) {
|
||||
return Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
ShovelMaximumLevel,
|
||||
Math.floor(
|
||||
Number(
|
||||
SaveData?.Tools?.ShovelLevel ?? 0
|
||||
) || 0
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function GetShovelUpgradeCost(
|
||||
SaveData
|
||||
) {
|
||||
const Level = GetShovelLevel(
|
||||
SaveData
|
||||
);
|
||||
|
||||
if (Level >= ShovelMaximumLevel) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Math.round(
|
||||
ShovelUnlockCost *
|
||||
Math.pow(
|
||||
ToolUpgradeCostMultiplier,
|
||||
Level + 1
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function UpgradeShovel(
|
||||
SaveData
|
||||
) {
|
||||
if (
|
||||
!IsGardenToolUnlocked(
|
||||
SaveData,
|
||||
"Shovel"
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const Level = GetShovelLevel(
|
||||
SaveData
|
||||
);
|
||||
|
||||
if (Level >= ShovelMaximumLevel) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SaveData.Tools.ShovelLevel =
|
||||
Level + 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function GetShovelRefundRate(
|
||||
SaveData
|
||||
) {
|
||||
const Level = GetShovelLevel(
|
||||
SaveData
|
||||
);
|
||||
|
||||
if (Level === 1) {
|
||||
return 0.33;
|
||||
}
|
||||
|
||||
if (Level === 2) {
|
||||
return 0.66;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
function DoesShovelReturnSeed(
|
||||
SaveData
|
||||
) {
|
||||
return GetShovelLevel(
|
||||
SaveData
|
||||
) >= 3;
|
||||
}
|
||||
|
||||
|
||||
function GetFertilizerLevel(
|
||||
SaveData
|
||||
) {
|
||||
return Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
FertilizerMaximumLevel,
|
||||
Math.floor(
|
||||
Number(
|
||||
SaveData?.Tools?.FertilizerLevel ?? 0
|
||||
) || 0
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function GetFertilizerUpgradeCost(
|
||||
SaveData
|
||||
) {
|
||||
const Level = GetFertilizerLevel(
|
||||
SaveData
|
||||
);
|
||||
|
||||
if (Level >= FertilizerMaximumLevel) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Math.round(
|
||||
FertilizerUnlockCost *
|
||||
Math.pow(
|
||||
ToolUpgradeCostMultiplier,
|
||||
Level + 1
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function UpgradeFertilizer(
|
||||
SaveData
|
||||
) {
|
||||
if (
|
||||
!IsGardenToolUnlocked(
|
||||
SaveData,
|
||||
"Fertilizer"
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const Level = GetFertilizerLevel(
|
||||
SaveData
|
||||
);
|
||||
|
||||
if (Level >= FertilizerMaximumLevel) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SaveData.Tools.FertilizerLevel =
|
||||
Level + 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function GetFertilizerGrowthMinutes(
|
||||
SaveData
|
||||
) {
|
||||
return FertilizerGrowthMinutes[
|
||||
GetFertilizerLevel(
|
||||
SaveData
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
function GetFertilizerUseCost(
|
||||
Amount = 1
|
||||
) {
|
||||
return FertilizerUseCost *
|
||||
Math.max(
|
||||
1,
|
||||
Math.floor(
|
||||
Number(Amount) || 1
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function AddFertilizerUses(
|
||||
SaveData,
|
||||
Amount = 1
|
||||
) {
|
||||
SaveData.Inventory ??= {};
|
||||
SaveData.Inventory.Fertilizer ??= 0;
|
||||
|
||||
SaveData.Inventory.Fertilizer +=
|
||||
Math.max(
|
||||
0,
|
||||
Math.floor(
|
||||
Number(Amount) || 0
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function TakeFertilizerUse(
|
||||
SaveData
|
||||
) {
|
||||
const CurrentUses = Math.max(
|
||||
0,
|
||||
Math.floor(
|
||||
Number(
|
||||
SaveData?.Inventory?.Fertilizer ?? 0
|
||||
) || 0
|
||||
)
|
||||
);
|
||||
|
||||
if (CurrentUses <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SaveData.Inventory.Fertilizer =
|
||||
CurrentUses - 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function GetFutureSightCooldownRemaining(
|
||||
SaveData,
|
||||
Now = Date.now()
|
||||
) {
|
||||
return Math.max(
|
||||
0,
|
||||
Number(
|
||||
SaveData?.Tools?.FutureSightCooldownUntil ?? 0
|
||||
) - Now
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function IsFutureSightReady(
|
||||
SaveData,
|
||||
Now = Date.now()
|
||||
) {
|
||||
return GetFutureSightCooldownRemaining(
|
||||
SaveData,
|
||||
Now
|
||||
) <= 0;
|
||||
}
|
||||
|
||||
|
||||
function StartFutureSightCooldown(
|
||||
SaveData,
|
||||
Now = Date.now()
|
||||
) {
|
||||
SaveData.Tools ??= {};
|
||||
SaveData.Tools.FutureSightCooldownUntil =
|
||||
Now + FutureSightCooldown;
|
||||
}
|
||||
Reference in new issue
Block a user