Mode switching via console

This commit is contained in:
KP 2024-07-24 03:56:45 -05:00
parent fcc0bb51cc
commit 7402494e92
2 changed files with 22 additions and 8 deletions

View file

@ -1,14 +1,16 @@
[03:16:52 AM] Info: Starting... [03:52:19 AM] Info: Starting...
KP3D version 2 KP3D version 2
=============================== ===============================
Copyright (C) kpworld.xyz 2018-2024 Copyright (C) kpworld.xyz 2018-2024
Contact me! @kp_cftsz Contact me! @kp_cftsz
[03:16:52 AM] Info: Initializing SDL [03:52:19 AM] Info: Initializing SDL
[03:16:52 AM] Info: Initializing OpenGL [03:52:19 AM] Info: Initializing OpenGL
[03:16:52 AM] Info: OpenGL version: 4.6.0 NVIDIA 536.23 [03:52:19 AM] Info: OpenGL version: 4.6.0 NVIDIA 536.23
[03:16:52 AM] Info: Initializing GLEW [03:52:19 AM] Info: Initializing GLEW
[03:16:52 AM] Info: Initializing SDL_mixer [03:52:19 AM] Info: Initializing SDL_mixer
[03:16:52 AM] Info: Reticulating splines... [03:52:19 AM] Info: Reticulating splines...
[03:16:52 AM] Info: Ready! [03:52:20 AM] Info: Ready!
[03:53:11 AM] Info: $ set-mode edit
[03:53:11 AM] Info: $

View file

@ -7,6 +7,7 @@
#include <KP3D_Renderer2D.h> #include <KP3D_Renderer2D.h>
#include <KP3D_Renderer3D.h> #include <KP3D_Renderer3D.h>
#include <KP3D_Console.h> #include <KP3D_Console.h>
#include <KP3D_StringUtils.h>
static kp3d::Texture tex; static kp3d::Texture tex;
static std::vector<kp3d::XYf> points; static std::vector<kp3d::XYf> points;
@ -25,6 +26,17 @@ Sandbox::Sandbox(const std::string& path):
points.push_back({x, y}); points.push_back({x, y});
return {CELL_VOID}; return {CELL_VOID};
}}); }});
kp3d::console::environment.Set("edit", {CELL_NUMBER, MODE_EDIT});
kp3d::console::environment.Set("game", {CELL_NUMBER, MODE_GAME});
kp3d::console::environment.Set("edit", {CELL_NUMBER, MODE_MENU});
kp3d::console::environment.Set("set-mode", {CELL_FUNCTION_CPP, [&](std::list<Cell> args) -> Cell {
if (args.empty()) return {CELL_VOID};
int mode = (int) FromCell<float>(args.back());
m_mode = mode;
kp3d::console::open = false;
SetMouseLockEnabled(true);
return {CELL_VOID};
}});
m_mode = MODE_MENU; m_mode = MODE_MENU;
} }