Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random stuff, again #349

Merged
merged 33 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d991bc9
one pattern less
Mr-Auto Oct 20, 2023
6c1673c
4 pattern less
Mr-Auto Oct 20, 2023
5cfba4a
another one
Mr-Auto Oct 20, 2023
9438478
just rename
Mr-Auto Oct 20, 2023
4b92f05
Merge remote-tracking branch 'origin/main' into stuff
Mr-Auto Oct 21, 2023
704d9b9
make it big letters
Mr-Auto Oct 21, 2023
ff9b1da
screen level thing
Mr-Auto Oct 21, 2023
56e3813
super small optimisation in `get_entities_by`
Mr-Auto Oct 21, 2023
8432219
comment out unused stuff
Mr-Auto Oct 21, 2023
31c9628
fix some super rare bug
Mr-Auto Oct 21, 2023
b256fda
if layer() and layer_local() do the same thing, just use one, so ever…
Mr-Auto Oct 21, 2023
e649a77
use advantages of map and initializer list for `worn_backitem` functi…
Mr-Auto Oct 21, 2023
f6ab87e
one more pattern gone
Mr-Auto Oct 21, 2023
7c357f2
add `set_camera_layer_control_enabled`
Mr-Auto Oct 22, 2023
7965a6f
this idea is as dead as it can be
Mr-Auto Oct 22, 2023
824380a
use local, why not
Mr-Auto Oct 22, 2023
cf4745e
move illumination to separate file, expose the full version of the fu…
Mr-Auto Oct 28, 2023
a01e9f4
Merge remote-tracking branch 'origin/main' into stuff
Mr-Auto Oct 28, 2023
837cd4a
fix and update doc
Mr-Auto Oct 28, 2023
b64d34c
some more doc stuff
Mr-Auto Oct 28, 2023
1c425b4
game api stuff
Mr-Auto Oct 29, 2023
de66eaa
fix example
Mr-Auto Oct 29, 2023
33b6df2
why this is fine locally but not on remote?
Mr-Auto Oct 29, 2023
78546ae
bring back zoom hack
Mr-Auto Oct 29, 2023
b8ad3f0
fix ui flags
Mr-Auto Oct 30, 2023
91c3c2e
improve flags in UI
Mr-Auto Oct 31, 2023
be56a7d
small random stuff
Mr-Auto Oct 31, 2023
4c5c4f6
add more `:set()` functions, unless there is some lua alternative?
Mr-Auto Nov 1, 2023
4881181
wtf
Mr-Auto Nov 1, 2023
5b317b8
some non important changes
Mr-Auto Nov 1, 2023
c99216a
particle stuff, move the particle functions from rpc, expose some mor…
Mr-Auto Nov 1, 2023
07e37a3
update doc
Mr-Auto Nov 1, 2023
4efa404
write our some more obvious stuff
Mr-Auto Nov 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/examples/set_camera_layer_control_enabled.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
set_camera_layer_control_enabled(false)

g_current_timer = nil
-- default load_time 36
function change_layer(layer_to, load_time)

if state.camera_layer == layer_to then
return
end
if g_current_timer ~= nil then
clear_callback(g_current_timer)
g_current_timer = nil
end
-- if we don't want the load time, we can just change the actual layer
if load_time == nil or load_time == 0 then
state.camera_layer = layer_to
return
end

state.layer_transition_timer = load_time
state.transition_to_layer = layer_to
state.camera_layer = layer_to
end
29 changes: 24 additions & 5 deletions docs/game_data/spel2.lua

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

2 changes: 1 addition & 1 deletion docs/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def print_lf(lf):
---- | ---- | -----------"""
)
print("bool | all:empty() | Returns true if container is empty, false otherwise")
print("int | aLL:size() | Same as `#container`")
print("int | all:size() | Same as `#container`")

print("any | vector:at(int index) | Same as `vector[index]`")
print("any | span:at(int index) | Same as `span[index]`")
Expand Down
1 change: 1 addition & 0 deletions docs/parse_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"../src/game_api/game_manager.hpp",
"../src/game_api/state.hpp",
"../src/game_api/state_structs.hpp",
"../src/game_api/illumination.hpp",
"../src/game_api/prng.hpp",
"../src/game_api/entities_floors.hpp",
"../src/game_api/entities_activefloors.hpp",
Expand Down
14 changes: 14 additions & 0 deletions docs/src/includes/_enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,20 @@ Name | Data | Description
[MAX_LIQUID_PARTICLES](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=LEVEL_CONFIG.MAX_LIQUID_PARTICLES) | 15 |
[FLAGGED_LIQUID_ROOMS](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=LEVEL_CONFIG.FLAGGED_LIQUID_ROOMS) | 16 |

## LIGHT_TYPE


> Search script examples for [LIGHT_TYPE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=LIGHT_TYPE)



Name | Data | Description
---- | ---- | -----------
[NONE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=LIGHT_TYPE.NONE) | LIGHT_TYPE::NONE | Normal static light, position can be edited to move it around<br/>
[FOLLOW_CAMERA](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=LIGHT_TYPE.FOLLOW_CAMERA) | LIGHT_TYPE::FOLLOW_CAMERA | Position is updated to the camera position, can be moved around via offset<br/>
[FOLLOW_ENTITY](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=LIGHT_TYPE.FOLLOW_ENTITY) | LIGHT_TYPE::FOLLOW_ENTITY | Position is updated to the entity position (from the uid field), if the uid is not found it will behave as [LIGHT_TYPE](#LIGHT_TYPE).NONE, can be moved around via offset<br/>
[ROOM_LIGHT](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=LIGHT_TYPE.ROOM_LIGHT) | LIGHT_TYPE::ROOM_LIGHT | Rectangle, full brightness always uses light1, disabling light1 does nothing<br/>

## LIQUID_POOL


Expand Down
48 changes: 45 additions & 3 deletions docs/src/includes/_globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ They come with some extra functionality:
Type | Name | Description
---- | ---- | -----------
bool | all:empty() | Returns true if container is empty, false otherwise
int | aLL:size() | Same as `#container`
int | all:size() | Same as `#container`
any | vector:at(int index) | Same as `vector[index]`
any | span:at(int index) | Same as `span[index]`
any | set:at(int order) | Returns elements in order, it's not an index as sets don't have one
Expand Down Expand Up @@ -1710,6 +1710,46 @@ Seed the game prng.

Set the current adventure seed pair

### set_camera_layer_control_enabled


```lua
set_camera_layer_control_enabled(false)

g_current_timer = nil
-- default load_time 36
function change_layer(layer_to, load_time)

if state.camera_layer == layer_to then
return
end
if g_current_timer ~= nil then
clear_callback(g_current_timer)
g_current_timer = nil
end
-- if we don't want the load time, we can just change the actual layer
if load_time == nil or load_time == 0 then
state.camera_layer = layer_to
return
end

state.layer_transition_timer = load_time
state.transition_to_layer = layer_to
-- actual layer change after time delay
set_timeout(function() state.camera_layer = layer_to end, load_time)
end

```


> Search script examples for [set_camera_layer_control_enabled](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_camera_layer_control_enabled)

#### nil set_camera_layer_control_enabled(bool enable)

This disables the `state.camera_layer` to be forced to the `(leader player).layer` and setting of the `state.layer_transition_timer` & `state.transition_to_layer` when player enters layer door.
Letting you control those manually.
Look at the example on how to mimic game layer switching behavior

### set_character_heart_color


Expand Down Expand Up @@ -2042,11 +2082,13 @@ Steal input from a [Player](#Player), HiredHand or [PlayerGhost](#PlayerGhost)

> Search script examples for [create_illumination](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=create_illumination)

#### [Illumination](#Illumination) create_illumination([Vec2](#Vec2) pos, [Color](#Color) color, [LIGHT_TYPE](#LIGHT_TYPE) type, float size, int flags, int uid, [LAYER](#LAYER) layer)

#### [Illumination](#Illumination) create_illumination([Color](#Color) color, float size, float x, float y)

#### [Illumination](#Illumination) create_illumination([Color](#Color) color, float size, int uid)

Creates a new [Illumination](#Illumination). Don't forget to continuously call [refresh_illumination](#refresh_illumination), otherwise your light emitter fades out! Check out the [illumination.lua](https://github.com/spelunky-fyi/overlunky/blob/main/examples/illumination.lua) script for an example
Creates a new [Illumination](#Illumination). Don't forget to continuously call [refresh_illumination](#refresh_illumination), otherwise your light emitter fades out! Check out the [illumination.lua](https://github.com/spelunky-fyi/overlunky/blob/main/examples/illumination.lua) script for an example.

### refresh_illumination

Expand All @@ -2055,7 +2097,7 @@ Creates a new [Illumination](#Illumination). Don't forget to continuously call [

#### nil refresh_illumination([Illumination](#Illumination) illumination)

Refreshes an [Illumination](#Illumination), keeps it from fading out
Refreshes an [Illumination](#Illumination), keeps it from fading out (updates the timer, keeping it in sync with the game render)

## Message functions

Expand Down
7 changes: 5 additions & 2 deletions docs/src/includes/_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -1287,8 +1287,9 @@ float | [offset_x](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=offs
float | [offset_y](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=offset_y) |
float | [distortion](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=distortion) |
int | [entity_uid](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=entity_uid) |
int | [timer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=timer) |
int | [flags](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=flags) | see [flags.hpp](https://github.com/spelunky-fyi/overlunky/blob/main/src/game_api/flags.hpp) illumination_flags
int | [type_flags](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=type_flags) | Only one can be set: 1 - Follow camera, 2 - Follow [Entity](#Entity), 3 - Rectangle, full brightness<br/>Rectangle always uses light1, even when it's disabled in flags
[LIGHT_TYPE](#LIGHT_TYPE) | [type_flags](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=type_flags) |
bool | [enabled](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=enabled) |
int | [layer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=layer) |

Expand Down Expand Up @@ -2261,6 +2262,7 @@ Derived from [Screen](#Screen)
Type | Name | Description
---- | ---- | -----------
int | [buttons](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=buttons) |
int | [time_till_death_screen](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=time_till_death_screen) | Delay after player death to open the death screen

### ScreenLogo

Expand Down Expand Up @@ -2879,8 +2881,9 @@ int | [speechbubble_owner](https://github.com/spelunky-fyi/overlunky/search?l=Lu
[LevelGenSystem](#LevelGenSystem) | [level_gen](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=level_gen) | Entrance and exit coordinates, shop types and all themes
int | [correct_ushabti](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=correct_ushabti) | See `get_correct_ushabti`. == anim_frame - (2 * floor(anim_frame/12))
[Items](#Items) | [items](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=items) | Has the current player count, player inventories and character selections
int | [camera_layer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=camera_layer) | The currently drawn layer, can't be changed
int | [camera_layer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=camera_layer) |
int | [layer_transition_timer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=layer_transition_timer) |
int | [transition_to_layer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=transition_to_layer) |
[ScreenTeamSelect](#ScreenTeamSelect) | [screen_team_select](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=screen_team_select) |
[ScreenCharacterSelect](#ScreenCharacterSelect) | [screen_character_select](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=screen_character_select) |
[ScreenTransition](#ScreenTransition) | [screen_transition](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=screen_transition) |
Expand Down
2 changes: 1 addition & 1 deletion src/game_api/entities_chars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ uint8_t Player::kapala_blood_amount()
void Player::set_jetpack_fuel(uint8_t fuel)
{
static auto jetpackID = to_id("ENT_TYPE_ITEM_JETPACK");
for (auto item : items.entities())
for (auto item : items.entities()) // TODO: should probably change to powerups right?
{
if (item->type->id == jetpackID)
{
Expand Down
9 changes: 5 additions & 4 deletions src/game_api/entities_chars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
#include <string> // for u16string, allocator
#include <vector> // for vector

#include "aliases.hpp" // for ENT_TYPE
#include "color.hpp" // for Color
#include "movable.hpp" // for Movable
#include "aliases.hpp" // for ENT_TYPE
#include "color.hpp" // for Color
#include "containers/custom_map.hpp" //
#include "movable.hpp" // for Movable

struct Illumination;
struct PlayerInputs;
Expand Down Expand Up @@ -60,7 +61,7 @@ class Ai
class PowerupCapable : public Movable
{
public:
std::map<ENT_TYPE, Entity*> powerups; // type id -> entity
custom_map<ENT_TYPE, Entity*> powerups; // type id -> entity

/// Removes a currently applied powerup. Specify `ENT_TYPE.ITEM_POWERUP_xxx`, not `ENT_TYPE.ITEM_PICKUP_xxx`! Removing the Eggplant crown does not seem to undo the throwing of eggplants, the other powerups seem to work.
void remove_powerup(ENT_TYPE powerup_type);
Expand Down
2 changes: 1 addition & 1 deletion src/game_api/entities_floors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ void Door::unlock(bool unlock)
{
if (!main_door->door_blocker)
{
main_door->door_blocker = state.layer_local(layer)->spawn_entity_over(door_bg_large, this, 0, 2.0);
main_door->door_blocker = state.layer(layer)->spawn_entity_over(door_bg_large, this, 0, 2.0);
main_door->door_blocker->animation_frame = 1;
}
}
Expand Down
26 changes: 15 additions & 11 deletions src/game_api/entity_lookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void foreach_mask(uint32_t mask, Layer* l, FunT&& fun)

std::vector<uint32_t> get_entities_by(std::vector<ENT_TYPE> entity_types, uint32_t mask, LAYER layer)
{
auto state = State::get();
auto state = State::get().ptr();
std::vector<uint32_t> found;
const std::vector<ENT_TYPE> proper_types = get_proper_types(std::move(entity_types));

Expand All @@ -124,37 +124,39 @@ std::vector<uint32_t> get_entities_by(std::vector<ENT_TYPE> entity_types, uint32

if (layer == LAYER::BOTH)
{
auto layer_front = state->layers[0];
auto layer_back = state->layers[1];
if (proper_types.empty() || proper_types[0] == 0)
{
if (mask == 0) // all entities
{
// this exception for small improvments with calling reserve once
found.reserve(found.size() + (size_t)state.layer(0)->all_entities.size + (size_t)state.layer(1)->all_entities.size);
found.insert(found.end(), state.layer(0)->all_entities.uids().begin(), state.layer(0)->all_entities.uids().end());
found.insert(found.end(), state.layer(1)->all_entities.uids().begin(), state.layer(1)->all_entities.uids().end());
found.reserve(found.size() + (size_t)layer_front->all_entities.size + (size_t)layer_back->all_entities.size);
found.insert(found.end(), layer_front->all_entities.uids().begin(), layer_front->all_entities.uids().end());
found.insert(found.end(), layer_back->all_entities.uids().begin(), layer_back->all_entities.uids().end());
}
else // all types
{
foreach_mask(mask, state.layer(0), insert_all_uids);
foreach_mask(mask, state.layer(1), insert_all_uids);
foreach_mask(mask, layer_front, insert_all_uids);
foreach_mask(mask, layer_back, insert_all_uids);
}
}
else
{
foreach_mask(mask, state.layer(0), push_matching_types);
foreach_mask(mask, state.layer(1), push_matching_types);
foreach_mask(mask, layer_front, push_matching_types);
foreach_mask(mask, layer_back, push_matching_types);
}
}
else
{
uint8_t correct_layer = enum_to_layer(layer);
if (proper_types.empty() || proper_types[0] == 0) // all types
{
foreach_mask(mask, state.layer(correct_layer), insert_all_uids);
foreach_mask(mask, state->layers[correct_layer], insert_all_uids);
}
else
{
foreach_mask(mask, state.layer(correct_layer), push_matching_types);
foreach_mask(mask, state->layers[correct_layer], push_matching_types);
}
}
return found;
Expand All @@ -167,6 +169,7 @@ std::vector<uint32_t> get_entities_by(ENT_TYPE entity_type, uint32_t mask, LAYER

std::vector<uint32_t> get_entities_at(std::vector<ENT_TYPE> entity_types, uint32_t mask, float x, float y, LAYER layer, float radius)
{
// TODO: use entitie regions?
auto state = State::get();
std::vector<uint32_t> found;
const std::vector<ENT_TYPE> proper_types = get_proper_types(std::move(entity_types));
Expand All @@ -175,7 +178,7 @@ std::vector<uint32_t> get_entities_at(std::vector<ENT_TYPE> entity_types, uint32
for (auto& item : entities.entities())
{
auto [ix, iy] = item->position();
float distance = sqrt(pow(x - ix, 2.0f) + pow(y - iy, 2.0f));
float distance = std::sqrt(std::pow(x - ix, 2.0f) + std::pow(y - iy, 2.0f));
if (distance < radius && entity_type_check(proper_types, item->type->id))
{
found.push_back(item->uid);
Expand All @@ -201,6 +204,7 @@ std::vector<uint32_t> get_entities_at(ENT_TYPE entity_type, uint32_t mask, float

std::vector<uint32_t> get_entities_overlapping_hitbox(std::vector<ENT_TYPE> entity_types, uint32_t mask, AABB hitbox, LAYER layer)
{
// TODO: use entitie regions?
auto state = State::get();
std::vector<uint32_t> result;
const std::vector<ENT_TYPE> proper_types = get_proper_types(std::move(entity_types));
Expand Down
Loading
Loading