mirror of
https://github.com/XLabsProject/s1x-client.git
synced 2023-08-02 15:02:12 +02:00
Add custom field support
This commit is contained in:
parent
51f0742ef8
commit
d04a8fd19e
@ -110,6 +110,29 @@ namespace scripting
|
||||
return call_function(name, arguments);
|
||||
}
|
||||
|
||||
static std::unordered_map<unsigned int, std::unordered_map<std::string, script_value>> custom_fields;
|
||||
|
||||
script_value get_custom_field(const entity& entity, const std::string& field)
|
||||
{
|
||||
auto fields = custom_fields[entity.get_entity_id()];
|
||||
const auto _field = fields.find(field);
|
||||
if (_field != fields.end())
|
||||
{
|
||||
return _field->second;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void set_custom_field(const entity& entity, const std::string& field, const script_value& value)
|
||||
{
|
||||
custom_fields[entity.get_entity_id()].insert(std::make_pair(field, value));
|
||||
}
|
||||
|
||||
void clear_custom_fields()
|
||||
{
|
||||
custom_fields.clear();
|
||||
}
|
||||
|
||||
void set_entity_field(const entity& entity, const std::string& field, const script_value& value)
|
||||
{
|
||||
const auto entref = entity.get_entity_reference();
|
||||
@ -131,6 +154,7 @@ namespace scripting
|
||||
else
|
||||
{
|
||||
// Read custom fields
|
||||
set_custom_field(entity, field, value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,6 +183,7 @@ namespace scripting
|
||||
else
|
||||
{
|
||||
// Add custom fields
|
||||
return get_custom_field(entity, field);
|
||||
}
|
||||
|
||||
return {};
|
||||
|
@ -21,6 +21,8 @@ namespace scripting
|
||||
return call<script_value>(name, arguments).as<T>();
|
||||
}
|
||||
|
||||
void clear_custom_fields();
|
||||
|
||||
void set_entity_field(const entity& entity, const std::string& field, const script_value& value);
|
||||
script_value get_entity_field(const entity& entity, const std::string& field);
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include "engine.hpp"
|
||||
#include "context.hpp"
|
||||
|
||||
#include "../execution.hpp"
|
||||
|
||||
#include <utils/io.hpp>
|
||||
|
||||
namespace scripting::lua::engine
|
||||
@ -43,6 +45,7 @@ namespace scripting::lua::engine
|
||||
return;
|
||||
}
|
||||
|
||||
clear_custom_fields();
|
||||
get_scripts().clear();
|
||||
load_scripts();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user