From 79d4b4968d3a696cca679c535302dce8cd593dfb Mon Sep 17 00:00:00 2001 From: Untrustedlife Date: Fri, 11 Jan 2019 00:32:32 -0600 Subject: [PATCH] Biome dissolved compound numbers are now applied whenever the biome is set. --- scripts/gui/microbe_hud.mjs | 14 ++++++++++++++ scripts/gui/thrive_gui.html | 2 +- scripts/microbe_stage/biome.as | 11 +++++++++++ scripts/microbe_stage/microbe_operations.as | 4 +++- src/scripting/script_initializer.cpp | 2 +- 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/scripts/gui/microbe_hud.mjs b/scripts/gui/microbe_hud.mjs index fff717c06f8..3e159265140 100644 --- a/scripts/gui/microbe_hud.mjs +++ b/scripts/gui/microbe_hud.mjs @@ -68,6 +68,11 @@ export function runMicrobeHUDSetup(){ checkExtinction(vars.population); }); + // Event for updating o2 and c02 numbers + Leviathan.OnGeneric("UpdateDissolvedGasses", (event, vars) => { + updateDissolvedGasses(vars.oxygenPercent, vars.co2Percent); + }); + // Event for checking win conditions Leviathan.OnGeneric("CheckWin", (event, vars) => { checkGeneration(vars.generation, vars.population); @@ -392,6 +397,15 @@ function updatePopulation(population){ population; } +// Update dissolved gasses +function updateDissolvedGasses(oxygen, c02){ + document.getElementById("oxygenPercent").textContent = + "O2: " + oxygen + "%"; + document.getElementById("carbonDioxidePercent").textContent = + "CO2: " + c02 + "%"; +} + + //! Checks if the player is extinct function checkExtinction(population){ if(population <= 0){ diff --git a/scripts/gui/thrive_gui.html b/scripts/gui/thrive_gui.html index 516787460d6..e98479589ab 100644 --- a/scripts/gui/thrive_gui.html +++ b/scripts/gui/thrive_gui.html @@ -121,7 +121,7 @@
- O2: 20% + O2: 21%
diff --git a/scripts/microbe_stage/biome.as b/scripts/microbe_stage/biome.as index 1819c39f50a..46f1bb9709a 100644 --- a/scripts/microbe_stage/biome.as +++ b/scripts/microbe_stage/biome.as @@ -96,6 +96,17 @@ void setBiome(uint64 biomeId, CellStageWorld@ world){ GetThriveGame().setBackgroundMaterial(biome.background); //Update biome for process system world.GetProcessSystem().setProcessBiome(biomeId); + + // Update oxygen and carbon dioxide numbers + auto oxyId = SimulationParameters::compoundRegistry().getTypeId("oxygen"); + auto c02Id = SimulationParameters::compoundRegistry().getTypeId("carbondioxide"); + GenericEvent@ updateDissolvedGasses = GenericEvent("UpdateDissolvedGasses"); + NamedVars@ vars = updateDissolvedGasses.GetNamedVars(); + vars.AddValue(ScriptSafeVariableBlock("oxygenPercent", + world.GetProcessSystem().getDissolved(oxyId)*100)); + vars.AddValue(ScriptSafeVariableBlock("co2Percent", + world.GetProcessSystem().getDissolved(c02Id)*100)); + GetEngine().GetEventHandler().CallEvent(updateDissolvedGasses); } void setSunlightForBiome(CellStageWorld@ world){ diff --git a/scripts/microbe_stage/microbe_operations.as b/scripts/microbe_stage/microbe_operations.as index 65df873c3be..9e0fbfa6a55 100644 --- a/scripts/microbe_stage/microbe_operations.as +++ b/scripts/microbe_stage/microbe_operations.as @@ -289,8 +289,10 @@ void respawnPlayer(CellStageWorld@ world) sceneNodeComponent.Marked = true; setRandomBiome(world); + cast(world.GetScriptSystem("MicrobeStageHudSystem")). - suicideButtonreset(); + suicideButtonreset(); + // Reset membrane color to fix the bug that made membranes sometimes red after you respawn. MicrobeOperations::applyMembraneColour(world, playerEntity); } diff --git a/src/scripting/script_initializer.cpp b/src/scripting/script_initializer.cpp index 3cba9c41b3e..6b816a227fb 100644 --- a/src/scripting/script_initializer.cpp +++ b/src/scripting/script_initializer.cpp @@ -1150,7 +1150,7 @@ bool } if(engine->RegisterObjectMethod("ProcessSystem", - "void getDissolved(CompoundId compoundData)", + "double getDissolved(CompoundId compoundData)", asMETHOD(ProcessSystem, getDissolved), asCALL_THISCALL) < 0) { ANGELSCRIPT_REGISTERFAIL; }