mirror of
https://github.com/XLabsProject/s1x-client.git
synced 2023-08-02 15:02:12 +02:00
More custom fields support
This commit is contained in:
parent
3659fbeaee
commit
ea733bba53
@ -7,6 +7,7 @@
|
||||
#include "game/scripting/entity.hpp"
|
||||
#include "game/scripting/event.hpp"
|
||||
#include "game/scripting/lua/engine.hpp"
|
||||
#include "game/scripting/execution.hpp"
|
||||
|
||||
#include "scheduler.hpp"
|
||||
|
||||
@ -35,6 +36,11 @@ namespace scripting
|
||||
e.arguments.emplace_back(*value);
|
||||
}
|
||||
|
||||
if (e.name == "connected")
|
||||
{
|
||||
scripting::clear_entity_fields(e.entity);
|
||||
}
|
||||
|
||||
lua::engine::notify(e);
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +125,25 @@ namespace scripting
|
||||
|
||||
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));
|
||||
const auto id = entity.get_entity_id();
|
||||
|
||||
if (custom_fields[id].find(field) != custom_fields[id].end())
|
||||
{
|
||||
custom_fields[id][field] = value;
|
||||
return;
|
||||
}
|
||||
|
||||
custom_fields[id].insert(std::make_pair(field, value));
|
||||
}
|
||||
|
||||
void clear_entity_fields(const entity& entity)
|
||||
{
|
||||
const auto id = entity.get_entity_id();
|
||||
|
||||
if (custom_fields.find(id) != custom_fields.end())
|
||||
{
|
||||
custom_fields[id].clear();
|
||||
}
|
||||
}
|
||||
|
||||
void clear_custom_fields()
|
||||
|
@ -21,6 +21,7 @@ namespace scripting
|
||||
return call<script_value>(name, arguments).as<T>();
|
||||
}
|
||||
|
||||
void clear_entity_fields(const entity& entity);
|
||||
void clear_custom_fields();
|
||||
|
||||
void set_entity_field(const entity& entity, const std::string& field, const script_value& value);
|
||||
|
@ -185,6 +185,17 @@ namespace scripting::lua
|
||||
return convert(s, entity.call(function, arguments));
|
||||
};
|
||||
|
||||
entity_type[sol::meta_function::new_index] = [](const entity& entity, const std::string& field,
|
||||
const sol::lua_value& value)
|
||||
{
|
||||
entity.set(field, convert(value));
|
||||
};
|
||||
|
||||
entity_type[sol::meta_function::index] = [](const entity& entity, const sol::this_state s, const std::string& field)
|
||||
{
|
||||
return convert(s, entity.get(field));
|
||||
};
|
||||
|
||||
struct game
|
||||
{
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user