Hot wheel implementation, scroll wheel keys, better error handling
parent
83dc74004e
commit
4d49aee57c
|
@ -21,6 +21,7 @@ void Input::init(GLFWwindow *window, glm::ivec2* winDimensions) {
|
|||
this->window = window;
|
||||
this->winDimensions = winDimensions;
|
||||
glfwSetKeyCallback(window, keyCallback);
|
||||
glfwSetScrollCallback(window, scrollCallback);
|
||||
}
|
||||
|
||||
void Input::setCallback(std::function<void(bool, int)> callback) {
|
||||
|
@ -55,6 +56,10 @@ void Input::update() {
|
|||
s.released = false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 12; i++) {
|
||||
keysNew[i] = false;
|
||||
}
|
||||
|
||||
updateMouse(0);
|
||||
updateMouse(1);
|
||||
updateMouse(2);
|
||||
|
@ -119,12 +124,34 @@ void Input::updateMouse(int button) {
|
|||
void Input::keyCallback(GLFWwindow* window, int key, int code, int action, int mode) {
|
||||
auto w = static_cast<Window*>(glfwGetWindowUserPointer(window));
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
if (key > 0 && key < 1024) {
|
||||
if (key >= 32 && key < 1024) {
|
||||
if (action == GLFW_PRESS) w->input.keysNew[key] = true;
|
||||
else if (action == GLFW_RELEASE) w->input.keysNew[key] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Input::scrollCallback(GLFWwindow *window, double xO, double yO) {
|
||||
auto w = static_cast<Window*>(glfwGetWindowUserPointer(window));
|
||||
|
||||
if (xO > 0) {
|
||||
//Right
|
||||
w->input.keysNew[11] = true;
|
||||
}
|
||||
else if (xO < 0) {
|
||||
// Left
|
||||
w->input.keysNew[10] = true;
|
||||
}
|
||||
|
||||
if (yO > 0) {
|
||||
// Up
|
||||
w->input.keysNew[8] = true;
|
||||
}
|
||||
else if (yO < 0) {
|
||||
// Down
|
||||
w->input.keysNew[9] = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Input::lockMouse(bool lock) {
|
||||
forceMouseUnlocked = !lock;
|
||||
mouseIsLocked = lock;
|
||||
|
@ -141,4 +168,4 @@ glm::ivec2 Input::mousePos() {
|
|||
|
||||
glm::vec2 Input::mouseDelta() {
|
||||
return delta;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ public:
|
|||
private:
|
||||
void updateMouse(int key);
|
||||
static void keyCallback(GLFWwindow* window, int key, int code, int action, int mode);
|
||||
static void scrollCallback(GLFWwindow* window, double, double yO);
|
||||
|
||||
GLFWwindow* window = nullptr;
|
||||
glm::ivec2* winDimensions = nullptr;
|
||||
|
|
|
@ -37,11 +37,12 @@ void GuiBuilder::clear(bool deleteRoot) {
|
|||
}
|
||||
|
||||
void GuiBuilder::create(LuaGuiElement& element, std::shared_ptr<GuiComponent> parent, glm::ivec2 bounds) {
|
||||
auto component = createComponent(element, bounds);
|
||||
if (!component) throw std::runtime_error("GuiBuilder failed to create component: " + element.key);
|
||||
parent->add(component);
|
||||
|
||||
for (auto& child : element.children) create(*child, component, component->getScale());
|
||||
if (element.get_or<bool>("visible", true)) {
|
||||
auto component = createComponent(element, bounds);
|
||||
if (!component) throw std::runtime_error("GuiBuilder failed to create component: " + element.key);
|
||||
parent->add(component);
|
||||
for (auto &child : element.children) create(*child, component, component->getScale());
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<GuiComponent> GuiBuilder::createComponent(LuaGuiElement& elem, glm::ivec2 bounds) {
|
||||
|
|
|
@ -117,7 +117,7 @@ std::shared_ptr<GuiComponent> GuiComponent::insert(unsigned int index, std::shar
|
|||
std::shared_ptr<GuiComponent> GuiComponent::add(std::shared_ptr<GuiComponent> component) {
|
||||
component->parent = this;
|
||||
component->updatePos();
|
||||
children.push_back(std::move(component));
|
||||
children.push_back(component);
|
||||
return component;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ void GuiInventoryItem::create(glm::vec2 scale, unsigned short count, ItemDef& de
|
|||
|
||||
auto item = std::make_shared<GuiModel>("item");
|
||||
item->create(scale * 10.5f, model);
|
||||
item->setPos(glm::vec2{7.75, 7.75} * scale);
|
||||
item->setPos(glm::vec2{8, 8} * scale);
|
||||
|
||||
item->setRotationX(180.f - 30.f);
|
||||
item->setRotationY(45.f);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
MainMenuScene::MainMenuScene(ClientState& state) :
|
||||
Scene(state),
|
||||
sandbox(sandboxArea, state, sandboxContainer) {
|
||||
sandbox(sandboxArea, state, menuContainer) {
|
||||
|
||||
state.renderer.setClearColor(0, 0, 0);
|
||||
state.renderer.window.input.lockMouse(false);
|
||||
|
@ -15,7 +15,7 @@ MainMenuScene::MainMenuScene(ClientState& state) :
|
|||
win = state.renderer.window.getSize();
|
||||
sandboxArea = win - glm::ivec2(0, 18 * GS);
|
||||
|
||||
components.add(sandboxContainer);
|
||||
components.add(menuContainer);
|
||||
|
||||
branding = std::make_shared<GuiContainer>("zephaBranding");
|
||||
components.add(branding);
|
||||
|
|
|
@ -35,7 +35,7 @@ private:
|
|||
GuiContainer components;
|
||||
std::shared_ptr<GuiContainer> branding = nullptr;
|
||||
std::shared_ptr<GuiContainer> navigationBar = nullptr;
|
||||
std::shared_ptr<GuiContainer> sandboxContainer = std::make_shared<GuiContainer>("_sandbox");
|
||||
std::shared_ptr<GuiContainer> menuContainer = std::make_shared<GuiContainer>("__menu");
|
||||
|
||||
MenuSandbox sandbox;
|
||||
|
||||
|
|
|
@ -3,21 +3,27 @@
|
|||
//
|
||||
|
||||
#include "MenuSandbox.h"
|
||||
#include "../../../lua/ErrorFormatter.h"
|
||||
|
||||
#include "../../../lua/ErrorFormatter.h"
|
||||
#include "../../hud/components/basic/GuiText.h"
|
||||
|
||||
// Usertypes
|
||||
#include "../../../lua/api/class/LuaGuiElement.h"
|
||||
|
||||
// Modules
|
||||
#include "../../../lua/api/menu/mDelay.h"
|
||||
#include "../../../lua/api/menu/mSetGui.h"
|
||||
#include "../../../lua/api/menu/mStartGame.h"
|
||||
|
||||
#include "../../../lua/api/class/LuaGuiElement.h"
|
||||
|
||||
MenuSandbox::MenuSandbox(glm::ivec2 &win, ClientState& state, std::shared_ptr<GuiContainer> container) :
|
||||
win(win),
|
||||
state(state),
|
||||
container(container),
|
||||
builder(state.defs.textures, state.defs.models, container) {}
|
||||
luaContainer(std::dynamic_pointer_cast<GuiContainer>(container->add(std::make_shared<GuiContainer>("__lua")))),
|
||||
builder(state.defs.textures, state.defs.models, luaContainer) {}
|
||||
|
||||
void MenuSandbox::reset() {
|
||||
container->remove("error");
|
||||
builder.clear(true);
|
||||
delayed_functions.clear();
|
||||
core = {};
|
||||
|
@ -52,8 +58,8 @@ void MenuSandbox::load(const Subgame& subgame) {
|
|||
loadAndRunMod(subgame.subgamePath + "/../../assets/base");
|
||||
loadAndRunMod(subgame.subgamePath + "/menu");
|
||||
}
|
||||
catch (const std::string& e) {
|
||||
std::cout << Log::err << "Encountered an error loading menu mod for subgame '" + subgame.config.name + "':\n\t" << e << Log::endl;
|
||||
catch (const std::runtime_error& e) {
|
||||
showError(e.what(), subgame.config.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,20 +74,20 @@ void MenuSandbox::update(double delta) {
|
|||
|
||||
sol::protected_function_result MenuSandbox::runFileSandboxed(const std::string& file) {
|
||||
for (LuaModFile& f : mod.files) {
|
||||
if (f.path == file) {
|
||||
sol::environment env(lua, sol::create, lua.globals());
|
||||
env["_PATH"] = f.path.substr(0, f.path.find_last_of('/') + 1);
|
||||
env["_FILE"] = f.path;
|
||||
env["_MODNAME"] = mod.config.name;
|
||||
if (f.path != file) continue;
|
||||
|
||||
return lua.safe_script(f.file, env, std::bind(&MenuSandbox::errorCallback, this,
|
||||
std::placeholders::_2), "@" + f.path, sol::load_mode::text);
|
||||
}
|
||||
sol::environment env(lua, sol::create, lua.globals());
|
||||
env["_PATH"] = f.path.substr(0, f.path.find_last_of('/') + 1);
|
||||
env["_FILE"] = f.path;
|
||||
env["_MODNAME"] = mod.config.name;
|
||||
|
||||
return lua.safe_script(f.file, env, std::bind(&MenuSandbox::errorCallback, this, std::placeholders::_2), "@" + f.path, sol::load_mode::text);
|
||||
}
|
||||
throw std::runtime_error("Error opening \"" + file + "\", file not found.");
|
||||
}
|
||||
|
||||
void MenuSandbox::loadAndRunMod(const std::string &modPath) {
|
||||
if (!cf_file_exists(modPath.data())) throw std::string("Directory not found.");
|
||||
if (!cf_file_exists(modPath.data())) throw std::runtime_error("Directory not found.");
|
||||
|
||||
LuaMod mod;
|
||||
std::string root = modPath + "/script";
|
||||
|
@ -94,7 +100,7 @@ void MenuSandbox::loadAndRunMod(const std::string &modPath) {
|
|||
std::string dirStr = *dirsToScan.begin();
|
||||
dirsToScan.erase(dirsToScan.begin());
|
||||
|
||||
if (!cf_file_exists(dirStr.data())) throw std::string("Missing 'script' directory.");
|
||||
if (!cf_file_exists(dirStr.data())) throw std::runtime_error("Missing 'script' directory.");
|
||||
cf_dir_open(&dir, dirStr.data());
|
||||
|
||||
while (dir.has_next) {
|
||||
|
@ -123,7 +129,7 @@ void MenuSandbox::loadAndRunMod(const std::string &modPath) {
|
|||
std::string modPath = file;
|
||||
|
||||
if (rootPos == std::string::npos)
|
||||
throw std::string("Attempted to access file '") + file + "' which is outside of mod root '" + root + "'.";
|
||||
throw std::runtime_error("Attempted to access file \"" + file + "\", which is outside of the mod root.");
|
||||
|
||||
modPath.erase(rootPos, root.length() + 1);
|
||||
modPath.resize(modPath.size() - 4);
|
||||
|
@ -141,7 +147,27 @@ void MenuSandbox::loadAndRunMod(const std::string &modPath) {
|
|||
}
|
||||
|
||||
this->mod = mod;
|
||||
runFileSandboxed("main");
|
||||
runFileSandboxed("init");
|
||||
}
|
||||
|
||||
void MenuSandbox::showError(const std::string& what, const std::string& subgame) {
|
||||
const std::string errPrefixText = "Encountered an error while loading the menu for " + subgame + " ;-;";
|
||||
Font f(state.defs.textures, state.defs.textures["font"]);
|
||||
|
||||
auto errWrap = std::make_shared<GuiContainer>("error");
|
||||
container->add(errWrap);
|
||||
|
||||
auto errPrefix = std::make_shared<GuiText>("error_text");
|
||||
errPrefix->create({3, 3}, {}, {0.7, 0, 0.3, 1}, {1, 1, 1, 1}, f);
|
||||
errPrefix->setText(errPrefixText);
|
||||
errPrefix->setPos({8, 16});
|
||||
errWrap->add(errPrefix);
|
||||
|
||||
auto errMsg = std::make_shared<GuiText>("error_text");
|
||||
errMsg->create({3, 3}, {}, {}, {1, 0.5, 0.6, 1}, f);
|
||||
errMsg->setText(what);
|
||||
errMsg->setPos({8, 52});
|
||||
errWrap->add(errMsg);
|
||||
}
|
||||
|
||||
sol::protected_function_result MenuSandbox::errorCallback(sol::protected_function_result errPfr) {
|
||||
|
@ -168,4 +194,4 @@ sol::protected_function_result MenuSandbox::errorCallback(sol::protected_functio
|
|||
std::cout << std::endl << Log::err << errString << Log::endl;
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ private:
|
|||
void loadApi();
|
||||
void loadAndRunMod(const std::string& modPath);
|
||||
|
||||
void showError(const std::string& what, const std::string& subgame);
|
||||
|
||||
sol::protected_function_result runFileSandboxed(const std::string& file);
|
||||
sol::protected_function_result errorCallback(sol::protected_function_result errPfr);
|
||||
|
||||
|
@ -35,8 +37,9 @@ private:
|
|||
std::vector<std::shared_ptr<AtlasRef>> modAssets {};
|
||||
|
||||
std::shared_ptr<GuiContainer> container = nullptr;
|
||||
std::shared_ptr<GuiContainer> luaContainer = nullptr;
|
||||
GuiBuilder builder;
|
||||
|
||||
ClientState& state;
|
||||
GuiBuilder builder;
|
||||
glm::ivec2& win;
|
||||
};
|
||||
|
|
|
@ -127,6 +127,7 @@ Any LuaGuiElement::getAsAny(const std::string &key) const noexcept {
|
|||
auto object = traits.at(key);
|
||||
|
||||
if (object.is<float>()) return Any::from<float>(object.as<float>());
|
||||
else if (object.is<bool>()) return Any::from<bool>(object.as<bool>());
|
||||
else if (object.is<std::string>()) return Any::from<std::string>(object.as<std::string>());
|
||||
else if (object.is<sol::table>()) {
|
||||
auto table = object.as<sol::table>();
|
||||
|
@ -162,4 +163,5 @@ Any LuaGuiElement::getAsAny(const std::string &key) const noexcept {
|
|||
return Any::from<glm::vec4>(values);
|
||||
}
|
||||
}
|
||||
else throw "Invalid type requested in getAsAny";
|
||||
}
|
||||
|
|
|
@ -154,34 +154,24 @@ sol::protected_function_result LocalLuaParser::errorCallback(sol::protected_func
|
|||
return errPfr;
|
||||
}
|
||||
|
||||
sol::protected_function_result LocalLuaParser::runFileSandboxed(std::string file) {
|
||||
sol::protected_function_result LocalLuaParser::runFileSandboxed(const std::string& file) {
|
||||
size_t modname_length = file.find('/');
|
||||
|
||||
if (modname_length == std::string::npos) {
|
||||
std::cout << Log::err << "Filestring \"" + file + "\" is invalid." << Log::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (modname_length == std::string::npos) throw std::runtime_error("Error opening \"" + file + "\", specified file is invalid.");
|
||||
std::string modname = file.substr(0, modname_length);
|
||||
|
||||
for (const LuaMod& mod : handler.cGetMods()) {
|
||||
if (modname == mod.config.name) {
|
||||
if (modname != mod.config.name) continue;
|
||||
for (const LuaModFile& f : mod.files) {
|
||||
if (f.path != file) continue;
|
||||
|
||||
for (const LuaModFile& f : mod.files) {
|
||||
if (f.path == file) {
|
||||
sol::environment env(lua, sol::create, lua.globals());
|
||||
env["_PATH"] = f.path.substr(0, f.path.find_last_of('/') + 1);
|
||||
env["_FILE"] = f.path;
|
||||
env["_MODNAME"] = mod.config.name;
|
||||
|
||||
sol::environment env(lua, sol::create, lua.globals());
|
||||
env["_PATH"] = f.path.substr(0, f.path.find_last_of('/') + 1);
|
||||
env["_FILE"] = f.path;
|
||||
env["_MODNAME"] = mod.config.name;
|
||||
|
||||
return lua.safe_script(f.file, env, std::bind(&LocalLuaParser::errorCallback, this,
|
||||
std::placeholders::_2), "@" + f.path, sol::load_mode::text);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << Log::err << "Error opening \"" + file + "\", not found." << Log::endl;
|
||||
break;
|
||||
return lua.safe_script(f.file, env, std::bind(&LocalLuaParser::errorCallback, this, std::placeholders::_2), "@" + f.path, sol::load_mode::text);
|
||||
}
|
||||
throw std::runtime_error("Error opening \"" + file + "\", file not found.");
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("Error opening \"" + file + "\", mod not found.");
|
||||
}
|
|
@ -32,7 +32,7 @@ private:
|
|||
void registerDefs(ClientGame &defs);
|
||||
|
||||
sol::protected_function_result errorCallback(sol::protected_function_result errPfr) const;
|
||||
sol::protected_function_result runFileSandboxed(std::string file);
|
||||
sol::protected_function_result runFileSandboxed(const std::string& file);
|
||||
|
||||
LuaKeybindHandler keybinds;
|
||||
LocalModHandler handler;
|
||||
|
|
|
@ -15,13 +15,13 @@ void LocalModHandler::setModsOrder(const std::vector<std::string>& order) {
|
|||
void LocalModHandler::executeMods(std::function<void(std::string)> run) {
|
||||
for (std::string& modName : modsOrder) {
|
||||
if (modName == "base") {
|
||||
run(modName + "/main");
|
||||
run(modName + "/init");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (std::string& modName : modsOrder) {
|
||||
if (modName != "base") run(modName + "/main");
|
||||
if (modName != "base") run(modName + "/init");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -186,31 +186,22 @@ sol::protected_function_result ServerLuaParser::errorCallback(sol::protected_fun
|
|||
|
||||
sol::protected_function_result ServerLuaParser::runFileSandboxed(const std::string& file) {
|
||||
size_t modname_length = file.find('/');
|
||||
|
||||
if (modname_length == std::string::npos) {
|
||||
std::cout << Log::err << "Filestring \"" + file + "\" is invalid." << Log::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (modname_length == std::string::npos) throw std::runtime_error("Error opening \"" + file + "\", specified file is invalid.");
|
||||
std::string modname = file.substr(0, modname_length);
|
||||
|
||||
for (const LuaMod& mod : handler.cGetMods()) {
|
||||
if (modname == mod.config.name) {
|
||||
if (modname != mod.config.name) continue;
|
||||
for (const LuaModFile& f : mod.files) {
|
||||
if (f.path != file) continue;
|
||||
|
||||
for (const LuaModFile& f : mod.files) {
|
||||
if (f.path == file) {
|
||||
sol::environment env(lua, sol::create, lua.globals());
|
||||
env["_PATH"] = f.path.substr(0, f.path.find_last_of('/') + 1);
|
||||
env["_FILE"] = f.path;
|
||||
env["_MODNAME"] = mod.config.name;
|
||||
|
||||
sol::environment env(lua, sol::create, lua.globals());
|
||||
env["_PATH"] = f.path.substr(0, f.path.find_last_of('/') + 1);
|
||||
env["_FILE"] = f.path;
|
||||
env["_MODNAME"] = mod.config.name;
|
||||
|
||||
return lua.safe_script(f.file, env, std::bind(&ServerLuaParser::errorCallback, this, std::placeholders::_2), "@" + f.path);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << Log::err << "Error opening \"" + file + "\", not found." << Log::endl;
|
||||
break;
|
||||
return lua.safe_script(f.file, env, std::bind(&ServerLuaParser::errorCallback, this, std::placeholders::_2), "@" + f.path, sol::load_mode::text);
|
||||
}
|
||||
throw std::runtime_error("Error opening \"" + file + "\", file not found.");
|
||||
}
|
||||
throw std::runtime_error("Error opening \"" + file + "\", mod not found.");
|
||||
}
|
|
@ -26,13 +26,13 @@ void ServerModHandler::loadMods(ServerGame& defs, const std::string &path) {
|
|||
void ServerModHandler::executeMods(std::function<void(std::string)> run) {
|
||||
for (LuaMod& mod : mods) {
|
||||
if (mod.config.name == "base") {
|
||||
run(mod.config.name + "/main");
|
||||
run(mod.config.name + "/init");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (LuaMod& mod : mods) {
|
||||
if (mod.config.name != "base") run(mod.config.name + "/main");
|
||||
if (mod.config.name != "base") run(mod.config.name + "/init");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -107,6 +107,20 @@ namespace Util {
|
|||
static std::string getKeyStr(unsigned short key) {
|
||||
switch (key) {
|
||||
default: return "";
|
||||
|
||||
case 0: return "mouse0";
|
||||
case 1: return "mouse1";
|
||||
case 2: return "mouse2";
|
||||
case 3: return "mouse3";
|
||||
case 4: return "mouse4";
|
||||
case 5: return "mouse5";
|
||||
case 6: return "mouse6";
|
||||
case 7: return "mouse7";
|
||||
case 8: return "scrollup";
|
||||
case 9: return "scrolldown";
|
||||
case 10: return "scrollleft";
|
||||
case 11: return "scrollright";
|
||||
|
||||
case 32: return "space";
|
||||
case 39: return "'";
|
||||
case 44: return ",";
|
||||
|
@ -218,9 +232,9 @@ namespace Util {
|
|||
case 334: return "num+";
|
||||
case 335: return "numenter";
|
||||
case 336: return "num=";
|
||||
case 341: return "leftshift";
|
||||
case 342: return "leftctrl";
|
||||
case 343: return "leftalt";
|
||||
case 340: return "leftshift";
|
||||
case 341: return "leftctrl";
|
||||
case 342: return "leftalt";
|
||||
case 344: return "rightshift";
|
||||
case 345: return "rightctrl";
|
||||
case 346: return "rightalt";
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
local gui = zepha.build_gui(function()
|
||||
return Gui.Body {
|
||||
-- background = "#214a21",
|
||||
background = "#334",
|
||||
|
||||
Gui.Text {
|
||||
position = { 4, 4 },
|
||||
content = "Minimalminimalmmnal"
|
||||
},
|
||||
|
||||
Gui.Rect {
|
||||
position = { 64, 64 },
|
||||
size = { 128 * (16/9), 128 },
|
||||
|
||||
background = "zeus_background"
|
||||
},
|
||||
|
||||
Gui.Rect {
|
||||
position = { 64 + 128, 64 + 64 },
|
||||
size = { 128 * (16/9), 128 },
|
||||
|
||||
background = "zeus_background",
|
||||
|
||||
Gui.Text {
|
||||
content = "What's the fuck it'd going on?"
|
||||
}
|
||||
}
|
||||
}
|
||||
end)
|
||||
|
||||
zepha.set_gui(gui)
|
|
@ -1,10 +0,0 @@
|
|||
zepha.set_gui(zepha.build_gui(function()
|
||||
return Gui.Body {
|
||||
background = "#124778",
|
||||
|
||||
Gui.Text {
|
||||
position = { 4, 4 },
|
||||
content = "Parentheses"
|
||||
}
|
||||
}
|
||||
end))
|
|
@ -93,4 +93,4 @@ end, 0.016)
|
|||
|
||||
|
||||
|
||||
zepha.set_gui(menu)
|
||||
zepha.set_gui(menu)
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
zepha.register_item("@aurailus:basictools:flint_pickaxe", {
|
||||
name = "Flint Pick",
|
||||
textures = {
|
||||
"@aurailus:basictools:flint_pickaxe"
|
||||
}
|
||||
})
|
||||
|
||||
crafting.register_recipe({
|
||||
output = "@aurailus:basictools:flint_pickaxe",
|
||||
recipe = {
|
||||
{"zeus:materials:flint_pickaxe_head", "zeus:materials:plant_twine"},
|
||||
{"zeus:materials:stick", ""}
|
||||
}
|
||||
})
|
||||
|
||||
zepha.register_item("@aurailus:basictools:flint_hatchet", {
|
||||
name = "Flint Hatchet",
|
||||
textures = {
|
||||
"@aurailus:basictools:flint_hatchet"
|
||||
}
|
||||
})
|
||||
|
||||
crafting.register_recipe({
|
||||
output = "@aurailus:basictools:flint_hatchet",
|
||||
recipe = {
|
||||
{"zeus:materials:flint_axe_head", "zeus:materials:plant_twine"},
|
||||
{"zeus:materials:stick", ""}
|
||||
}
|
||||
})
|
||||
|
||||
zepha.register_item("@aurailus:basictools:flint_shovel", {
|
||||
name = "Flint Spade",
|
||||
textures = {
|
||||
"@aurailus:basictools:flint_shovel"
|
||||
}
|
||||
});
|
||||
|
||||
crafting.register_recipe({
|
||||
output = "@aurailus:basictools:flint_shovel",
|
||||
recipe = {
|
||||
{"zeus:materials:flint_shovel_head", "zeus:materials:plant_twine"},
|
||||
{"zeus:materials:stick", ""}
|
||||
}
|
||||
})
|
||||
|
||||
zepha.register_item("@aurailus:basictools:wooden_pickaxe", {
|
||||
name = "Wooden Pick",
|
||||
textures = {
|
||||
"@aurailus:basictools:wooden_pickaxe"
|
||||
}
|
||||
});
|
||||
|
||||
zepha.register_item("@aurailus:basictools:wooden_hatchet", {
|
||||
name = "Wooden Hatchet",
|
||||
textures = {
|
||||
"@aurailus:basictools:wooden_hatchet"
|
||||
}
|
||||
});
|
||||
|
||||
zepha.register_item("@aurailus:basictools:wooden_shovel", {
|
||||
name = "Wooden Shovel",
|
||||
textures = {
|
||||
"@aurailus:basictools:wooden_shovel"
|
||||
}
|
||||
});
|
|
@ -1,60 +0,0 @@
|
|||
_G["crafting"] = {}
|
||||
|
||||
crafting.registered_recipes = {}
|
||||
|
||||
crafting.register_recipe = fn(tbl) {
|
||||
table.insert(crafting.registered_recipes, tbl)
|
||||
}
|
||||
|
||||
crafting.bind = fn(craft_input, craft_output) {
|
||||
local width = craft_input.width
|
||||
local length = craft_input.length
|
||||
|
||||
local crafting_changed = fn() {
|
||||
local items = {}
|
||||
|
||||
local matched_any = false
|
||||
foreach r in crafting.registered_recipes {
|
||||
local matches = true
|
||||
for i = 1, length {
|
||||
local x = (i - 1) % width + 1
|
||||
local y = math.floor((i - 1) / width) + 1
|
||||
|
||||
local recipe_item_name = ""
|
||||
|
||||
if (y <= #(r.recipe) and x <= #(r.recipe[y])) {
|
||||
recipe_item_name = r.recipe[y][x]
|
||||
}
|
||||
|
||||
if (recipe_item_name ~= craft_input:get_stack(i).name) {
|
||||
matches = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (matches) {
|
||||
craft_output:set_stack(1, {r.output, 1})
|
||||
matched_any = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (not matched_any) {
|
||||
craft_output:set_stack(1, {"invalid", 0})
|
||||
}
|
||||
}
|
||||
|
||||
craft_input.on_put = crafting_changed
|
||||
craft_input.on_take = crafting_changed
|
||||
|
||||
craft_output.allow_put = fn() {
|
||||
return 0
|
||||
}
|
||||
|
||||
craft_output.on_take = fn() {
|
||||
for i = 1, length {
|
||||
craft_input:remove_stack(i, 1)
|
||||
}
|
||||
crafting_changed()
|
||||
}
|
||||
}
|
|
@ -1,29 +1,89 @@
|
|||
local root = zepha.player:get_hud():get("hot_wheel_root")
|
||||
local lists = {
|
||||
root:get("list_1"),
|
||||
root:get("list_2"),
|
||||
root:get("list_3"),
|
||||
root:get("list_4"),
|
||||
root:get("list_5"),
|
||||
root:get("list_6")
|
||||
}
|
||||
local api = aurailus_hot_wheel
|
||||
local r = 6.28319 / 6
|
||||
|
||||
local offset = 0
|
||||
local function select(n)
|
||||
offset = n - 1
|
||||
local currentRotation = 0
|
||||
local desiredRotation = 0
|
||||
|
||||
for i,list in ipairs(lists) do
|
||||
list.list = "hot_wheel_" .. tostring((i + offset - 1) % 6 + 1)
|
||||
end
|
||||
local rotating = false
|
||||
local mod = false
|
||||
|
||||
root:get("numbers").background = "@aurailus:hot_wheel:circle_numbers_" .. (offset + 1)
|
||||
zepha.player:set_selected_block(zepha.player:get_inventory():get_list("hot_wheel_" .. ((offset + 2) % 6 + 1)):get_stack(1).name)
|
||||
local slot = 1
|
||||
local item = 1
|
||||
|
||||
local function position()
|
||||
rotating = true
|
||||
zepha.delay(function()
|
||||
currentRotation = currentRotation + (desiredRotation - currentRotation) / 2
|
||||
|
||||
for i, list in ipairs(api.lists) do
|
||||
list.position = { 32.5 + 22 * math.sin(currentRotation - (r * (i + 3))), 32.5 + 22 * math.cos(currentRotation - (r * (i + 3))) } end
|
||||
for i, label in ipairs(api.labels) do
|
||||
label.position = { 37 + 35 * math.sin(currentRotation - (r * (i + 3))), 36 + 35 * math.cos(currentRotation - (r * (i + 3))) } end
|
||||
|
||||
if currentRotation == desiredRotation then
|
||||
rotating = false
|
||||
return false
|
||||
elseif math.abs(currentRotation - desiredRotation) < 0.033 then
|
||||
currentRotation = desiredRotation
|
||||
return true
|
||||
else return true end
|
||||
end, 1/60)
|
||||
end
|
||||
|
||||
local function select_slot(n)
|
||||
slot = n
|
||||
local offset = n - 1
|
||||
desiredRotation = offset * r
|
||||
|
||||
api.list_expanded.list = "hot_wheel_" .. n
|
||||
|
||||
for i, list in ipairs(api.lists) do list.visible = i ~= n end
|
||||
for i, label in ipairs(api.labels) do label.visible = i ~= n end
|
||||
|
||||
zepha.player:set_selected_block(zepha.player:get_inventory():get_list("hot_wheel_" .. slot):get_stack(item).name)
|
||||
if not rotating then position() end
|
||||
end
|
||||
|
||||
local function select_item(n)
|
||||
item = ((item + n) - 1) % 5 + 1
|
||||
local offset = slot - 1
|
||||
api.list_expanded_indicator.position = { 2 + 18 * (item - 1), 0 }
|
||||
|
||||
zepha.player:set_selected_block(zepha.player:get_inventory():get_list("hot_wheel_" .. slot):get_stack(item).name)
|
||||
end
|
||||
|
||||
local function key(n)
|
||||
select_slot(n)
|
||||
end
|
||||
|
||||
local function scroll(n)
|
||||
if mod then select_slot(((slot + n - 1) % 6) + 1)
|
||||
else select_item(n) end
|
||||
end
|
||||
|
||||
for i = 1, 6 do
|
||||
zepha.register_keybind("@aurailus:hot_wheel:select_slot_" .. i, {
|
||||
description = "Select Slot " .. i,
|
||||
default = zepha.keys[tostring(i)],
|
||||
on_press = function() select(i) end
|
||||
on_press = function() key(i) end
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
zepha.register_keybind("@aurailus:hot_wheel:item_down", {
|
||||
description = "Cycle Item Down",
|
||||
default = zepha.keys.scrolldown,
|
||||
on_press = function() scroll(1) end
|
||||
})
|
||||
|
||||
zepha.register_keybind("@aurailus:hot_wheel:item_up", {
|
||||
description = "Cycle Item Up",
|
||||
default = zepha.keys.scrollup,
|
||||
on_press = function() scroll(-1) end
|
||||
})
|
||||
|
||||
zepha.register_keybind("@aurailus:hot_wheel:mod", {
|
||||
description = "Modifier Key",
|
||||
default = zepha.keys.leftshift,
|
||||
on_press = function() mod = true end,
|
||||
on_release = function() mod = false end
|
||||
})
|
|
@ -1,8 +0,0 @@
|
|||
if zepha.server then
|
||||
runfile(_PATH .. "register")
|
||||
end
|
||||
|
||||
if zepha.client then
|
||||
runfile(_PATH .. "ui")
|
||||
runfile(_PATH .. "keys")
|
||||
end
|
|
@ -1,75 +1,130 @@
|
|||
local api = aurailus_hot_wheel
|
||||
local hud = zepha.player:get_hud()
|
||||
|
||||
hud:append(function() return Gui.Rect {
|
||||
key = "hot_wheel_root",
|
||||
hud:append(function()
|
||||
local root = Gui.Rect {
|
||||
key = "hot_wheel_root",
|
||||
|
||||
size = { 140, 80 },
|
||||
position = { "0%", "100%" },
|
||||
position_anchor = { "-10%", "110%" },
|
||||
|
||||
Gui.Rect {
|
||||
size = { 80, 80 },
|
||||
background = "@aurailus:hot_wheel:hot_wheel_circle",
|
||||
size = { 140, 80 },
|
||||
position = { "0%", "100%" },
|
||||
position_anchor = { "-10%", "110%" },
|
||||
|
||||
Gui.Rect {
|
||||
size = { 94, 18 },
|
||||
position = { 52, 19 },
|
||||
background = "@aurailus:hot_wheel:hot_wheel_line",
|
||||
|
||||
Gui.Rect {
|
||||
key = "expanded_indicator",
|
||||
size = { 18, 18 },
|
||||
position = { 2, 0 },
|
||||
background = "@aurailus:hot_wheel:hot_wheel_selection"
|
||||
},
|
||||
|
||||
Gui.InventoryList {
|
||||
key = "list_expanded",
|
||||
position = { 3, 1 },
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 6,
|
||||
source = "current_player",
|
||||
list = "hot_wheel_1",
|
||||
}
|
||||
},
|
||||
|
||||
Gui.Rect {
|
||||
key = "numbers",
|
||||
size = { 80, 80 },
|
||||
background = "@aurailus:hot_wheel:circle_numbers_1"
|
||||
},
|
||||
background = "@aurailus:hot_wheel:hot_wheel_circle",
|
||||
|
||||
Gui.InventoryList {
|
||||
key = "list_1",
|
||||
position = { 12, 22 },
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 1,
|
||||
source = "current_player",
|
||||
list = "hot_wheel_1",
|
||||
},
|
||||
Gui.InventoryList {
|
||||
key = "list_2",
|
||||
position = { 32, 11 },
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 1,
|
||||
source = "current_player",
|
||||
list = "hot_wheel_2",
|
||||
},
|
||||
Gui.InventoryList {
|
||||
key = "list_4",
|
||||
position = { 52, 43 },
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 1,
|
||||
source = "current_player",
|
||||
list = "hot_wheel_4",
|
||||
},
|
||||
Gui.InventoryList {
|
||||
key = "list_5",
|
||||
position = { 32, 54 },
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 1,
|
||||
source = "current_player",
|
||||
list = "hot_wheel_5",
|
||||
},
|
||||
Gui.InventoryList {
|
||||
key = "list_6",
|
||||
position = { 12, 43 },
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 1,
|
||||
source = "current_player",
|
||||
list = "hot_wheel_6",
|
||||
}
|
||||
},
|
||||
Gui.Rect {
|
||||
size = { 100, 18 },
|
||||
position = { 52, 19 },
|
||||
background = "@aurailus:hot_wheel:hot_wheel_line",
|
||||
Gui.InventoryList {
|
||||
key = "list_1",
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 1,
|
||||
source = "current_player",
|
||||
list = "hot_wheel_1",
|
||||
},
|
||||
Gui.InventoryList {
|
||||
key = "list_2",
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 1,
|
||||
source = "current_player",
|
||||
list = "hot_wheel_2",
|
||||
},
|
||||
Gui.InventoryList {
|
||||
key = "list_3",
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 1,
|
||||
source = "current_player",
|
||||
list = "hot_wheel_3",
|
||||
},
|
||||
Gui.InventoryList {
|
||||
key = "list_4",
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 1,
|
||||
source = "current_player",
|
||||
list = "hot_wheel_4",
|
||||
},
|
||||
Gui.InventoryList {
|
||||
key = "list_5",
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 1,
|
||||
source = "current_player",
|
||||
list = "hot_wheel_5",
|
||||
},
|
||||
Gui.InventoryList {
|
||||
key = "list_6",
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 1,
|
||||
source = "current_player",
|
||||
list = "hot_wheel_6",
|
||||
},
|
||||
|
||||
Gui.InventoryList {
|
||||
key = "list_3",
|
||||
position = { 3, 1 },
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 6,
|
||||
source = "current_player",
|
||||
list = "hot_wheel_3",
|
||||
Gui.Text {
|
||||
key = "label_1",
|
||||
content = "1"
|
||||
},
|
||||
Gui.Text {
|
||||
key = "label_2",
|
||||
content = "2"
|
||||
},
|
||||
Gui.Text {
|
||||
key = "label_3",
|
||||
content = "3"
|
||||
},
|
||||
Gui.Text {
|
||||
key = "label_4",
|
||||
content = "4"
|
||||
},
|
||||
Gui.Text {
|
||||
key = "label_5",
|
||||
content = "5"
|
||||
},
|
||||
Gui.Text {
|
||||
key = "label_6",
|
||||
content = "6"
|
||||
}
|
||||
}
|
||||
}
|
||||
} end)
|
||||
|
||||
api.labels = {
|
||||
root:get("label_1"),
|
||||
root:get("label_2"),
|
||||
root:get("label_3"),
|
||||
root:get("label_4"),
|
||||
root:get("label_5"),
|
||||
root:get("label_6")
|
||||
}
|
||||
|
||||
api.lists = {
|
||||
root:get("list_1"),
|
||||
root:get("list_2"),
|
||||
root:get("list_3"),
|
||||
root:get("list_4"),
|
||||
root:get("list_5"),
|
||||
root:get("list_6")
|
||||
}
|
||||
|
||||
api.list_expanded = root:get("list_expanded")
|
||||
api.list_expanded_indicator = root:get("expanded_indicator")
|
||||
|
||||
return root
|
||||
end)
|
Binary file not shown.
Before Width: | Height: | Size: 444 B After Width: | Height: | Size: 418 B |
|
@ -1,9 +0,0 @@
|
|||
runfile("@aurailus:item_collection/dropped_item")
|
||||
|
||||
local DROP_ENTITY = true
|
||||
if (DROP_ENTITY) {
|
||||
runfile("@aurailus:item_collection/mode/entity")
|
||||
}
|
||||
else {
|
||||
runfile("@aurailus:item_collection/mode/direct")
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
zepha.register_block("@aurailus:tnt:tnt", {
|
||||
name = "TNT",
|
||||
model = "base:block",
|
||||
textures = {
|
||||
"@aurailus:tnt:tnt_top",
|
||||
"@aurailus:tnt:tnt_bottom",
|
||||
"@aurailus:tnt:tnt_side"
|
||||
},
|
||||
toughness = {
|
||||
hand = 3,
|
||||
shovel = 1,
|
||||
pick = 2
|
||||
},
|
||||
drop = "@aurailus:tnt:tnt",
|
||||
on_break = fn(pos) {
|
||||
local amp = 20
|
||||
for i = -amp, amp {
|
||||
for j = -amp, amp {
|
||||
for k = -amp, amp {
|
||||
if (V(i, j, k):distance(V()) < amp) {
|
||||
zepha.set_block(pos + offset, "air")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
|
@ -1,31 +0,0 @@
|
|||
runfile(_PATH .. "blocks/_index")
|
||||
runfile(_PATH .. "entity/_index")
|
||||
|
||||
local chat_down = false
|
||||
zepha.register_keybind("zeus:default:open_chat", {
|
||||
description = "Open Chat",
|
||||
default = zepha.keys.t,
|
||||
on_press = () => { print "Opened chat!" }
|
||||
})
|
||||
|
||||
## Flying toggles
|
||||
local fn toggleFlying() {
|
||||
zepha.player.flying = not zepha.player.flying
|
||||
}
|
||||
|
||||
zepha.register_keybind("zeus:default:toggle_flying", {
|
||||
description = "Toggle Flying",
|
||||
default = zepha.keys.f,
|
||||
on_press = toggleFlying
|
||||
})
|
||||
|
||||
local last_press = -100
|
||||
zepha.register_keybind("zeus:default:double_jump_fly", {
|
||||
description = "Double Jump to Toggle Flying",
|
||||
default = zepha.keys.space,
|
||||
on_press = () => {
|
||||
local press = zepha.time.s();
|
||||
if (press - last_press < 0.25) { toggleFlying() }
|
||||
last_press = press;
|
||||
}
|
||||
})
|
|
@ -1 +0,0 @@
|
|||
runfile("zeus:flowers/flowers")
|
|
@ -1,2 +0,0 @@
|
|||
if (zepha.server) { runfile(_PATH .. "register") }
|
||||
if (zepha.client) { runfile(_PATH .. "menu") }
|
|
@ -1,2 +0,0 @@
|
|||
runfile("zeus:kinetic/models/axle")
|
||||
runfile("zeus:kinetic/blocks/axle")
|
|
@ -1 +0,0 @@
|
|||
runfile(_PATH .. "biomes/_index")
|
|
@ -1,6 +0,0 @@
|
|||
runfile("zeus:materials/items/stick")
|
||||
runfile("zeus:materials/items/rock")
|
||||
runfile("zeus:materials/items/flint")
|
||||
runfile("zeus:materials/items/flint_heads")
|
||||
runfile("zeus:materials/items/plant_fibre")
|
||||
runfile("zeus:materials/items/plant_twine")
|
Loading…
Reference in New Issue