BIG UPDATE: Plants and mutations moved to database. Fetchable with API.

This commit is contained in:
sarah committed 2026-08-31 19:26:25 +02:00
1 parent 5e6e376d8e
commit dde47ff5a6
7 files changed
+272 -228

No files matched your search

+97 -110
View File
@@ -1,114 +1,101 @@
const MutationSets = {
RoseDarkening: {
Id: 1,
Name: "Rose darkening",
let MutationSets = {};
Description:
"A mutation that seems to corrupt roses.",
let MutationsLoadPromise = null;
let GameContentLoadPromise = null;
Priority: 10,
Rotation: "Any",
Chance: 0.1,
Cooldown: 120000,
Relations: {
PlantsUsed: [
1
],
PlantsCreated: [
2
]
},
Pattern: [
[
{
Tags: ["Rose"],
Capture: "ParentA"
},
"Empty"
],
[
"Empty",
{
Tags: ["Rose"],
Capture: "ParentB"
}
]
],
Success: [
[
"Empty",
"DarkRose"
],
[
"DarkRose",
"Empty"
]
],
Failure: "Keep"
},
RoseDyePurple: {
Id: 2,
Name: "Rose dying purple",
Description:
"A colourful mutation that makes a purple rose.",
Priority: 20,
Rotation: "Any",
Chance: 1.0,
Cooldown: 100000,
Relations: {
PlantsUsed: [
1,
3
],
PlantsCreated: [
4
]
},
Pattern: [
[
{
Tags: [
"Rose",
"Red"
],
Capture: "ParentA"
},
"Empty",
{
Tags: [
"Rose",
"Blue"
],
Capture: "ParentB"
}
]
],
Success: [
[
"Empty",
"PurpleRose",
"Empty"
]
],
Failure: "Keep"
async function LoadMutations() {
if (MutationsLoadPromise !== null) {
return MutationsLoadPromise;
}
};
MutationsLoadPromise =
LoadMutationsFromApi();
try {
return await MutationsLoadPromise;
} catch (Error) {
MutationsLoadPromise = null;
throw Error;
}
}
async function LoadMutationsFromApi() {
const Response =
await fetch(
ApiUrl + "/Mutations.php",
{
method: "GET",
headers: {
"Accept":
"application/json"
}
}
);
if (!Response.ok) {
throw new Error(
"Mutations API returned HTTP " +
Response.status
);
}
const Result =
await Response.json();
if (
!Result.Success ||
Result.Mutations === null ||
typeof Result.Mutations !==
"object" ||
Array.isArray(
Result.Mutations
)
) {
throw new Error(
Result.Error ??
"Mutations API returned invalid data."
);
}
MutationSets =
Result.Mutations;
return MutationSets;
}
async function LoadGameContent() {
if (GameContentLoadPromise === null) {
GameContentLoadPromise =
Promise.all([
LoadPlants(),
LoadMutations()
]);
}
try {
await GameContentLoadPromise;
} catch (Error) {
GameContentLoadPromise = null;
throw Error;
}
return {
Plants: Plants,
Mutations: MutationSets
};
}