From 3d59fd7aa7fb8189ab4fc93e09fbdfe94503150b Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Fri, 18 Jun 2021 23:29:48 +0200 Subject: [PATCH] More fixes --- src/game/scripting/array.cpp | 49 ++++++++++++++------------------ src/game/scripting/execution.cpp | 20 ------------- src/game/scripting/execution.hpp | 2 -- 3 files changed, 22 insertions(+), 49 deletions(-) diff --git a/src/game/scripting/array.cpp b/src/game/scripting/array.cpp index 659e3e5..67f704a 100644 --- a/src/game/scripting/array.cpp +++ b/src/game/scripting/array.cpp @@ -56,7 +56,7 @@ namespace scripting for (const auto& value : values) { - add_array_value(this->id_, value); + this->push(value); } } @@ -66,7 +66,7 @@ namespace scripting for (const auto& value : values) { - add_array_key_value(this->id_, value.first, value.second); + this->set(value.first, value.second); } } @@ -117,7 +117,7 @@ namespace scripting void array::push(script_value value) const { - add_array_value(this->id_, value); + this->set(this->size(), value); } script_value array::get(const std::string& key) const @@ -167,8 +167,7 @@ namespace scripting if (!variable_id) { - add_array_key_value(this->id_, key, {}); - return this->get_value_id(key); + return game::GetNewVariable(this->id_, string_value); } return variable_id; @@ -190,43 +189,39 @@ namespace scripting const auto value = _value.get_raw(); const auto string_value = game::SL_GetString(key.data(), 0); - const auto variable_id = game::GetVariable(this->id_, string_value); + const auto variable_id = this->get_value_id(key); - if (variable_id) + if (!variable_id) { - const auto variable = &game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)]; - - game::AddRefToValue(value.type, value.u); - game::RemoveRefToValue(variable->type, variable->u.u); - - variable->type = value.type; - variable->u.u = value.u; - return; } - add_array_key_value(this->id_, key, _value); + const auto variable = &game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)]; + + game::AddRefToValue(value.type, value.u); + game::RemoveRefToValue(variable->type, variable->u.u); + + variable->type = value.type; + variable->u.u = value.u; } void array::set(const unsigned int index, const script_value& _value) const { const auto value = _value.get_raw(); - const auto variable_id = game::GetVariable(this->id_, (index - 0x800000) & 0xFFFFFF); + const auto variable_id = this->get_value_id(index); - if (variable_id) + if (!variable_id) { - const auto variable = &game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)]; - - game::AddRefToValue(value.type, value.u); - game::RemoveRefToValue(variable->type, variable->u.u); - - variable->type = value.type; - variable->u.u = value.u; - return; } - add_array_value(this->id_, _value); + const auto variable = &game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)]; + + game::AddRefToValue(value.type, value.u); + game::RemoveRefToValue(variable->type, variable->u.u); + + variable->type = value.type; + variable->u.u = value.u; } entity array::get_raw() const diff --git a/src/game/scripting/execution.cpp b/src/game/scripting/execution.cpp index bad77a6..9f1047a 100644 --- a/src/game/scripting/execution.cpp +++ b/src/game/scripting/execution.cpp @@ -280,24 +280,4 @@ namespace scripting return index; } - - void add_array_key_value(unsigned int parent_id, const std::string& _key, const scripting::script_value& value) - { - stack_isolation _; - - const auto key = game::SL_GetString(_key.data(), 0); - - scripting::push_value(scripting::entity(parent_id)); - scripting::push_value(value); - game::Scr_AddArrayStringIndexed(key); - } - - void add_array_value(unsigned int parent_id, const scripting::script_value& value) - { - stack_isolation _; - - scripting::push_value(scripting::entity(parent_id)); - scripting::push_value(value); - game::Scr_AddArray(); - } } \ No newline at end of file diff --git a/src/game/scripting/execution.hpp b/src/game/scripting/execution.hpp index 7a3a51e..f2cac08 100644 --- a/src/game/scripting/execution.hpp +++ b/src/game/scripting/execution.hpp @@ -36,6 +36,4 @@ namespace scripting void notify(const entity& entity, const std::string& event, const std::vector& arguments); unsigned int make_array(); - void add_array_key_value(unsigned int parent_id, const std::string& _key, const scripting::script_value& value); - void add_array_value(unsigned int parent_id, const scripting::script_value& value); }