Merge branch 'main' into update-items
This commit is contained in:
commit
c1e9976d95
@ -6,7 +6,8 @@ inair = true
|
||||
target = -1
|
||||
timer = 0.3
|
||||
|
||||
local dropitem = ARGS
|
||||
local def_index = entity:def_index()
|
||||
dropitem = ARGS
|
||||
if dropitem then
|
||||
timer = dropitem.pickup_delay or timer
|
||||
end
|
||||
@ -38,7 +39,7 @@ end
|
||||
|
||||
function on_grounded(force)
|
||||
local matrix = mat4.idt()
|
||||
mat4.rotate(matrix, {0, 1, 0}, math.random()*360, matrix)
|
||||
mat4.rotate(matrix, {0, 1, 0}, math.random() * 360, matrix)
|
||||
mat4.rotate(matrix, {1, 0, 0}, 90, matrix)
|
||||
mat4.scale(matrix, scale, matrix)
|
||||
rig:set_matrix(0, matrix)
|
||||
@ -50,14 +51,34 @@ function on_fall()
|
||||
end
|
||||
|
||||
function on_sensor_enter(index, oid)
|
||||
local playerid = hud.get_player()
|
||||
local playerentity = player.get_entity(playerid)
|
||||
if timer < 0.0 and oid == playerentity and index == 0 then
|
||||
entity:despawn()
|
||||
inventory.add(player.get_inventory(playerid), dropitem.id, dropitem.count)
|
||||
audio.play_sound_2d("events/pickup", 0.5, 0.8+math.random()*0.4, "regular")
|
||||
local other = entities.get(oid)
|
||||
if not other then
|
||||
return
|
||||
end
|
||||
if index == 1 and oid == playerentity then
|
||||
local pid = other:get_player()
|
||||
if pid == -1 then
|
||||
-- other is base:drop too
|
||||
if index == 0 and other:def_index() == def_index then
|
||||
local odrop = other:get_component("base:drop")
|
||||
if odrop.dropitem.id == dropitem.id then
|
||||
-- // TODO: replace combination logic with item.* function
|
||||
local stack = item.stack_size(dropitem.id)
|
||||
local sum = dropitem.count + odrop.dropitem.count
|
||||
if sum <= stack then
|
||||
dropitem.count = sum
|
||||
other:despawn()
|
||||
end
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if timer < 0.0 and index == 0 then
|
||||
entity:despawn()
|
||||
inventory.add(player.get_inventory(pid), dropitem.id, dropitem.count)
|
||||
audio.play_sound_2d("events/pickup", 0.5, 0.8 + math.random() * 0.4, "regular")
|
||||
end
|
||||
if index == 1 then
|
||||
target = oid
|
||||
end
|
||||
end
|
||||
@ -84,15 +105,18 @@ end
|
||||
|
||||
function on_update(tps)
|
||||
timer = timer - 1.0/tps
|
||||
if target ~= -1 then
|
||||
if timer > 0.0 then
|
||||
return
|
||||
end
|
||||
local dir = vec3.sub(entities.get(target).transform:get_pos(), tsf:get_pos())
|
||||
vec3.normalize(dir, dir)
|
||||
vec3.mul(dir, 10.0, dir)
|
||||
body:set_vel(dir)
|
||||
|
||||
if timer > 0.0 or target == -1 then
|
||||
return
|
||||
end
|
||||
local target_entity = entities.get(target)
|
||||
if not target_entity then
|
||||
return
|
||||
end
|
||||
local dir = vec3.sub(target_entity.transform:get_pos(), tsf:get_pos())
|
||||
vec3.normalize(dir, dir)
|
||||
vec3.mul(dir, 10.0, dir)
|
||||
body:set_vel(dir)
|
||||
end
|
||||
|
||||
function on_attacked(attacker, pid)
|
||||
|
||||
72
run.sh
72
run.sh
@ -1,6 +1,66 @@
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake -DCMAKE_BUILD_TYPE=Release ..
|
||||
cmake --build . -j$(nproc)
|
||||
cd ..
|
||||
build/VoxelEngine
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
|
||||
function delete {
|
||||
echo "[RUN SCRIPT] Delete build directory"
|
||||
rm -rf build
|
||||
}
|
||||
|
||||
|
||||
function build {
|
||||
echo "[RUN SCRIPT] Build project"
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake -DCMAKE_BUILD_TYPE=Release ..
|
||||
cmake --build . -j$(nproc)
|
||||
cd ..
|
||||
}
|
||||
|
||||
|
||||
function rebuild {
|
||||
delete
|
||||
build
|
||||
}
|
||||
|
||||
|
||||
run=true
|
||||
function norun {
|
||||
echo "[RUN SCRIPT] Build without run"
|
||||
run=
|
||||
}
|
||||
|
||||
|
||||
function help {
|
||||
echo "[RUN SCRIPT] Usage: ./run [ARGUMENT]..."
|
||||
echo "[RUN SCRIPT] Arguments:"
|
||||
echo "[RUN SCRIPT] -d, --delete Delete build directory"
|
||||
echo "[RUN SCRIPT] -b, --build Build project"
|
||||
echo "[RUN SCRIPT] -r, --rebuild Rebuild project"
|
||||
echo "[RUN SCRIPT] -R, --norun Build without run"
|
||||
echo "[RUN SCRIPT] -h, --help Print this page"
|
||||
}
|
||||
|
||||
|
||||
while [ -n "$1" ]; do
|
||||
case "$1" in
|
||||
-d | --delete) delete ;;
|
||||
-b | --build) build ;;
|
||||
-r | --rebuild) rebuild ;;
|
||||
-R | --norun) norun ;;
|
||||
-h | --help) help
|
||||
norun
|
||||
break ;;
|
||||
*) echo "[RUN SCRIPT] Unknown argument: $1"
|
||||
help
|
||||
norun
|
||||
break ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
|
||||
if [[ $run ]]; then
|
||||
echo "[RUN SCRIPT] Run project"
|
||||
./build/VoxelEngine
|
||||
fi
|
||||
@ -592,7 +592,10 @@ void Hud::draw(const DrawContext& ctx){
|
||||
const uint height = viewport.getHeight();
|
||||
auto menu = gui.getMenu();
|
||||
|
||||
darkOverlay->setVisible(menu->hasOpenPage());
|
||||
bool is_menu_open = menu->hasOpenPage();
|
||||
darkOverlay->setVisible(is_menu_open);
|
||||
menu->setVisible(is_menu_open);
|
||||
|
||||
updateElementsPosition(viewport);
|
||||
|
||||
uicamera->setFov(height);
|
||||
@ -693,7 +696,6 @@ void Hud::setPause(bool pause) {
|
||||
if (pause && !menu->hasOpenPage()) {
|
||||
menu->setPage("pause");
|
||||
}
|
||||
menu->setVisible(pause);
|
||||
}
|
||||
|
||||
Player* Hud::getPlayer() const {
|
||||
|
||||
@ -826,7 +826,7 @@ void TextBox::setCaret(size_t position) {
|
||||
scrolled(-glm::ceil(offset/static_cast<double>(scrollStep)+0.5f));
|
||||
}
|
||||
uint lcaret = caret - label->getTextLineOffset(line);
|
||||
int realoffset = font->calcWidth(input, lcaret)-int(textOffset) - padding.x;
|
||||
int realoffset = font->calcWidth(input, lcaret)-int(textOffset) + 2;
|
||||
if (realoffset-width > 0) {
|
||||
setTextOffset(textOffset + realoffset-width);
|
||||
} else if (realoffset < 0) {
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
#include "libhud.hpp"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include "assets/Assets.hpp"
|
||||
#include "content/Content.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "frontend/UiDocument.hpp"
|
||||
#include "frontend/hud.hpp"
|
||||
#include "graphics/ui/elements/InventoryView.hpp"
|
||||
@ -16,11 +16,7 @@
|
||||
#include "voxels/voxel.hpp"
|
||||
#include "voxels/blocks_agent.hpp"
|
||||
#include "world/Level.hpp"
|
||||
#include "api_lua.hpp"
|
||||
|
||||
namespace scripting {
|
||||
extern Hud* hud;
|
||||
}
|
||||
using namespace scripting;
|
||||
|
||||
static int l_open_inventory(lua::State*) {
|
||||
@ -176,22 +172,22 @@ static int l_set_allow_pause(lua::State* L) {
|
||||
}
|
||||
|
||||
const luaL_Reg hudlib[] = {
|
||||
{"open_inventory", lua::wrap<l_open_inventory>},
|
||||
{"close_inventory", lua::wrap<l_close_inventory>},
|
||||
{"open", lua::wrap<l_open>},
|
||||
{"open_block", lua::wrap<l_open_block>},
|
||||
{"open_permanent", lua::wrap<l_open_permanent>},
|
||||
{"show_overlay", lua::wrap<l_show_overlay>},
|
||||
{"get_block_inventory", lua::wrap<l_get_block_inventory>},
|
||||
{"close", lua::wrap<l_close>},
|
||||
{"pause", lua::wrap<l_pause>},
|
||||
{"resume", lua::wrap<l_resume>},
|
||||
{"is_paused", lua::wrap<l_is_paused>},
|
||||
{"is_inventory_open", lua::wrap<l_is_inventory_open>},
|
||||
{"get_player", lua::wrap<l_get_player>},
|
||||
{"_is_content_access", lua::wrap<l_is_content_access>},
|
||||
{"_set_content_access", lua::wrap<l_set_content_access>},
|
||||
{"_set_debug_cheats", lua::wrap<l_set_debug_cheats>},
|
||||
{"set_allow_pause", lua::wrap<l_set_allow_pause>},
|
||||
{"open_inventory", wrap_hud<l_open_inventory>},
|
||||
{"close_inventory", wrap_hud<l_close_inventory>},
|
||||
{"open", wrap_hud<l_open>},
|
||||
{"open_block", wrap_hud<l_open_block>},
|
||||
{"open_permanent", wrap_hud<l_open_permanent>},
|
||||
{"show_overlay", wrap_hud<l_show_overlay>},
|
||||
{"get_block_inventory", wrap_hud<l_get_block_inventory>},
|
||||
{"close", wrap_hud<l_close>},
|
||||
{"pause", wrap_hud<l_pause>},
|
||||
{"resume", wrap_hud<l_resume>},
|
||||
{"is_paused", wrap_hud<l_is_paused>},
|
||||
{"is_inventory_open", wrap_hud<l_is_inventory_open>},
|
||||
{"get_player", wrap_hud<l_get_player>},
|
||||
{"_is_content_access", wrap_hud<l_is_content_access>},
|
||||
{"_set_content_access", wrap_hud<l_set_content_access>},
|
||||
{"_set_debug_cheats", wrap_hud<l_set_debug_cheats>},
|
||||
{"set_allow_pause", wrap_hud<l_set_allow_pause>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
17
src/logic/scripting/lua/libs/libhud.hpp
Normal file
17
src/logic/scripting/lua/libs/libhud.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "api_lua.hpp"
|
||||
|
||||
#include "logic/scripting/scripting_hud.hpp"
|
||||
#include "graphics/render/WorldRenderer.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
|
||||
template <lua_CFunction func>
|
||||
inline int wrap_hud(lua_State* L) {
|
||||
if (scripting::hud == nullptr) {
|
||||
return luaL_error(
|
||||
L, "renderer is not initialized yet, see hud.lua on_hud_open event"
|
||||
);
|
||||
}
|
||||
return lua::wrap<func>(L);
|
||||
}
|
||||
@ -1,11 +1,8 @@
|
||||
#include "api_lua.hpp"
|
||||
#include "libhud.hpp"
|
||||
|
||||
#include "logic/scripting/scripting_hud.hpp"
|
||||
#include "graphics/render/WorldRenderer.hpp"
|
||||
#include "graphics/render/ParticlesRenderer.hpp"
|
||||
#include "graphics/render/Emitter.hpp"
|
||||
#include "assets/assets_util.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
@ -81,10 +78,10 @@ static int l_is_alive(lua::State* L) {
|
||||
}
|
||||
|
||||
const luaL_Reg particleslib[] = {
|
||||
{"emit", lua::wrap<l_emit>},
|
||||
{"stop", lua::wrap<l_stop>},
|
||||
{"is_alive", lua::wrap<l_is_alive>},
|
||||
{"get_origin", lua::wrap<l_get_origin>},
|
||||
{"set_origin", lua::wrap<l_set_origin>},
|
||||
{"emit", wrap_hud<l_emit>},
|
||||
{"stop", wrap_hud<l_stop>},
|
||||
{"is_alive", wrap_hud<l_is_alive>},
|
||||
{"get_origin", wrap_hud<l_get_origin>},
|
||||
{"set_origin", wrap_hud<l_set_origin>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
#include "api_lua.hpp"
|
||||
#include "libhud.hpp"
|
||||
|
||||
#include "logic/scripting/scripting_hud.hpp"
|
||||
#include "graphics/render/WorldRenderer.hpp"
|
||||
#include "graphics/render/TextsRenderer.hpp"
|
||||
#include "graphics/render/TextNote.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
@ -99,17 +96,17 @@ static int l_set_rotation(lua::State* L) {
|
||||
}
|
||||
|
||||
const luaL_Reg text3dlib[] = {
|
||||
{"show", lua::wrap<l_show>},
|
||||
{"hide", lua::wrap<l_hide>},
|
||||
{"get_text", lua::wrap<l_get_text>},
|
||||
{"set_text", lua::wrap<l_set_text>},
|
||||
{"get_pos", lua::wrap<l_get_pos>},
|
||||
{"set_pos", lua::wrap<l_set_pos>},
|
||||
{"get_axis_x", lua::wrap<l_get_axis_x>},
|
||||
{"set_axis_x", lua::wrap<l_set_axis_x>},
|
||||
{"get_axis_y", lua::wrap<l_get_axis_y>},
|
||||
{"set_axis_y", lua::wrap<l_set_axis_y>},
|
||||
{"set_rotation", lua::wrap<l_set_rotation>},
|
||||
{"update_settings", lua::wrap<l_update_settings>},
|
||||
{"show", wrap_hud<l_show>},
|
||||
{"hide", wrap_hud<l_hide>},
|
||||
{"get_text", wrap_hud<l_get_text>},
|
||||
{"set_text", wrap_hud<l_set_text>},
|
||||
{"get_pos", wrap_hud<l_get_pos>},
|
||||
{"set_pos", wrap_hud<l_set_pos>},
|
||||
{"get_axis_x", wrap_hud<l_get_axis_x>},
|
||||
{"set_axis_x", wrap_hud<l_set_axis_x>},
|
||||
{"get_axis_y", wrap_hud<l_get_axis_y>},
|
||||
{"set_axis_y", wrap_hud<l_set_axis_y>},
|
||||
{"set_rotation", wrap_hud<l_set_rotation>},
|
||||
{"update_settings", wrap_hud<l_update_settings>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@ -65,15 +65,22 @@ void scripting::on_frontend_render() {
|
||||
}
|
||||
|
||||
void scripting::on_frontend_close() {
|
||||
auto L = lua::get_main_state();
|
||||
for (auto& pack : engine->getAllContentPacks()) {
|
||||
lua::emit_event(
|
||||
lua::get_main_state(),
|
||||
L,
|
||||
pack.id + ":.hudclose",
|
||||
[&](lua::State* L) {
|
||||
return lua::pushinteger(L, hud->getPlayer()->getId());
|
||||
}
|
||||
);
|
||||
}
|
||||
lua::pushnil(L);
|
||||
lua::setglobal(L, "hud");
|
||||
lua::pushnil(L);
|
||||
lua::setglobal(L, "gfx");
|
||||
|
||||
scripting::renderer = nullptr;
|
||||
scripting::hud = nullptr;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user