Skip to content

Commit

Permalink
empty add_custom_type
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Auto committed Oct 16, 2023
1 parent 33db1fd commit ac7cc6a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
5 changes: 5 additions & 0 deletions docs/game_data/spel2.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/src/includes/_globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,10 @@ default game value are: y_limit = 98.5, rising_speed_x = 0, rising_speed_y = 0.0
#### [ENT_TYPE](#ENT_TYPE) add_custom_type(array<[ENT_TYPE](#ENT_TYPE)> types)

#### [ENT_TYPE](#ENT_TYPE) add_custom_type()

Adds new custom type (group of ENT_TYPE) that can be later used in functions like get_entities_by or set_(pre/post)_entity_spawn
Use empty array or no parameter to get new uniqe [ENT_TYPE](#ENT_TYPE) that can be used for custom [EntityDB](#EntityDB)

### add_money

Expand Down
7 changes: 4 additions & 3 deletions src/game_api/custom_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1578,10 +1578,11 @@ std::span<const ENT_TYPE> get_custom_entity_types(CUSTOM_TYPE type)

CUSTOM_TYPE add_new_custom_type(std::vector<ENT_TYPE> types)
{
if (types.empty())
return (CUSTOM_TYPE)0;

++g_last_custom_id;
if (types.empty())
{
types.push_back(g_last_custom_id);
}
user_custom_types.emplace((CUSTOM_TYPE)g_last_custom_id, std::move(types));
return (CUSTOM_TYPE)g_last_custom_id;
}
Expand Down
5 changes: 5 additions & 0 deletions src/game_api/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,11 @@ ENT_TYPE add_custom_type(std::vector<ENT_TYPE> types)
return (ENT_TYPE)add_new_custom_type(std::move(types));
}

ENT_TYPE add_custom_type()
{
return (ENT_TYPE)add_new_custom_type({});
}

int32_t get_current_money()
{
auto state = State::get().ptr();
Expand Down
1 change: 1 addition & 0 deletions src/game_api/rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ std::optional<double> get_frametime();
void set_frametime_inactive(std::optional<double> frametime);
std::optional<double> get_frametime_inactive();
ENT_TYPE add_custom_type(std::vector<ENT_TYPE> types);
ENT_TYPE add_custom_type();
int32_t get_current_money();
int32_t add_money(int32_t amount, std::optional<uint8_t> display_time);
int32_t add_money_slot(int32_t amount, uint8_t player_slot, std::optional<uint8_t> display_time);
Expand Down
5 changes: 5 additions & 0 deletions src/game_api/script/lua_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2101,7 +2101,12 @@ end
/// Get engine target frametime when game is unfocused (1/framerate, default 1/33).
lua["get_frametime_unfocused"] = get_frametime_inactive;

auto add_custom_type = sol::overload(
static_cast<ENT_TYPE (*)(std::vector<ENT_TYPE>)>(::add_custom_type),
static_cast<ENT_TYPE (*)()>(::add_custom_type));

/// Adds new custom type (group of ENT_TYPE) that can be later used in functions like get_entities_by or set_(pre/post)_entity_spawn
/// Use empty array or no parameter to get new uniqe ENT_TYPE that can be used for custom EntityDB
lua["add_custom_type"] = add_custom_type;

auto get_entities_by_draw_depth = sol::overload(
Expand Down

0 comments on commit ac7cc6a

Please sign in to comment.