Skip to content

Commit

Permalink
10.1.0: game state binaries & general improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
catriverr committed Nov 2, 2024
1 parent f110dd9 commit 8fce6e3
Show file tree
Hide file tree
Showing 12 changed files with 908 additions and 16 deletions.
26 changes: 26 additions & 0 deletions envs/models/02_gift.gt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name=02_gift,width=6,height=4,collision=false
__gtransparent_unit__
4 false 0 X
__gtransparent_unit__
__gtransparent_unit__
4 false 0 X
__gtransparent_unit__
6 false 0 X
6 false 0 X
4 false 0 X
4 false 0 X
6 false 0 X
6 false 0 X
4 false 0 X
4 false 0 X
4 false 0 X
4 false 0 X
4 false 0 X
4 false 0 X
6 false 0 X
6 false 0 X
4 false 0 X
4 false 0 X
6 false 0 X
6 false 0 X
; %tsgmeng::builder.texture4_0() -> auto_generated Sat Nov 02 2024
62 changes: 62 additions & 0 deletions envs/models/03_table.gt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name=03_table,width=12,height=5,collision=false
5 false 0 X
5 false 0 X
5 false 0 X
5 false 0 X
5 false 0 X
5 false 0 X
5 false 0 X
5 false 0 X
5 false 0 X
5 false 0 X
5 false 0 X
5 false 0 X
5 false 0 X
0 false 1 X
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
0 false 1 X
5 false 0 X
__gtransparent_unit__
0 false 1 X
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
0 false 1 X
__gtransparent_unit__
__gtransparent_unit__
0 false 1 X
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
0 false 1 X
__gtransparent_unit__
__gtransparent_unit__
0 false 1 X
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
__gtransparent_unit__
0 false 1 X
__gtransparent_unit__
; %tsgmeng::builder.texture4_0() -> auto_generated Sat Nov 02 2024
18 changes: 18 additions & 0 deletions envs/models/smol_player.gt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name=smol_player,width=4,height=4,collision=true
4 false 0 X
4 false 0 X
4 false 0 X
__gtransparent_unit__
0 false 0 X
0 false 0 X
4 false 0 X
4 false 0 X
4 false 0 X
4 false 0 X
4 false 0 X
4 false 0 X
4 false 0 X
__gtransparent_unit__
4 false 0 X
__gtransparent_unit__
; %tsgmeng::builder.texture4_0() -> auto_generated Sat Oct 26 2024
199 changes: 199 additions & 0 deletions lib/bin/cli/commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,45 @@
#include <stdexcept>
#include <string>

#include "../gmeng.h"

#include "index.h"

using string = std::string;


class inspect_texture_command_t : public Gmeng_Commandline::Subcommand {
public:
inline void run(vector<string> args) override {
if (args.size() < 1) {
LOG("~r~ERROR!~n~ please provide a texture file name.");
LOG("~g~Usage:~n~ ~y~" + Gmeng::global.executable + "~n~ preview ~b~file.tx~n~");
return;
};
LOG("Checking for texture atlas in ~g~"+args.at(0)+"~n~...");
if (!filesystem::exists(args.at(0))) {
LOG("~r~ERROR!~n~ file ~b~" + args.at(0) + "~n~ does not exist.");
return;
}
Gmeng::texture txt = Gmeng::LoadTexture(args.at(0));
std::string render = Gmeng::Util::draw_texture_string(txt);
MSG("~r~Gmeng~n~ TEXTURE PREVIEW:\n");
MSG("~_~file: `" + args.at(0) + "`~n~\n");
std::cout << render << std::endl;
};

inspect_texture_command_t(string _name, string _description) : Subcommand(_name, _description) {
this->info = { _name, _description };
};
};

static inspect_texture_command_t inspect_command("preview", "Displays a preview of a texture file");

static Gmeng_Commandline::InterfaceRegistrar
register_inspect_command(
std::make_unique<inspect_texture_command_t>( ( inspect_command ) )
);

class test_command_t : public Gmeng_Commandline::Subcommand {
public:
inline void run(vector<string>) override {
Expand Down Expand Up @@ -66,3 +101,167 @@ static Gmeng_Commandline::InterfaceRegistrar
register_editor_command(
std::make_unique<editor_command_t> ( ( editor_command ) )
);


#include <ncurses.h>
#include <fstream>
#include <unordered_map>
#include <string>
#include <iostream>
#include <cstdlib>

void modify_properties(gmeng_properties_t& properties);

using namespace Gmeng;

class gamestate_editor_t : public Gmeng_Commandline::Subcommand {
public:
inline void run(vector<string> args) override {
if (args.size() < 1) {
LOG("~r~ERROR!~n~ provide a file name.");
MSG("~g~Usage:~n~ ~y~"+Gmeng::global.executable+" ~b~gamestate~n~ <filename>\n");
return;
};

std::string filename = args.at(0);

if (!filesystem::exists(filename)) {
LOG("~r~ERROR!~n~ the file `"+filename+"` does not exist.");
MSG("~g~Usage:~n~ ~y~"+Gmeng::global.executable+" ~b~gamestate~n~ <filename>\n");
return;
};

gmeng_properties_t properties = read_properties(filename);

initscr();
cbreak();
noecho();
keypad(stdscr, TRUE);

modify_properties(properties);
writeout_properties(filename, properties);

endwin();
};

gamestate_editor_t(string _name, string _description) : Subcommand(_name, _description) {
this->info = {
.name = _name,
.description = _description
};
};
};

static gamestate_editor_t gamestate_editor_command("gamestate", "Modifies or views a gamestate binary file");

static Gmeng_Commandline::InterfaceRegistrar
register_gamestate_command(
std::make_unique<gamestate_editor_t>( gamestate_editor_command )
);

void modify_properties(gmeng_properties_t& properties) {
int highlight = 0;
int mode = 0; // 0 = Main properties, 1 = Model positions
const int num_main_fields = 6;
bool exit_program = false;

while (!exit_program) {
clear();

// Display section based on mode
if (mode == 0) {
mvprintw(0, 0, "Modify Main Properties (Press ENTER to edit, UP/DOWN to navigate, 'm' for model positions, 'q' to quit)");
mvprintw(2, 0, "1. DEF_DELTAX: %d", properties.DEF_DELTAX);
mvprintw(3, 0, "2. DEF_DELTAY: %d", properties.DEF_DELTAY);
mvprintw(4, 0, "3. SKY_WIDTH: %d", properties.SKY_WIDTH);
mvprintw(5, 0, "4. SKY_HEIGHT: %d", properties.SKY_HEIGHT);
mvprintw(6, 0, "5. SKY_COLOR: %d", properties.SKY_COLOR);
mvprintw(7, 0, "6. A00_CAKE_INTERACT_LOOPC: %d", properties.A00_CAKE_INTERACT_LOOPC);
mvchgat(2 + highlight, 0, -1, A_REVERSE, 0, NULL);
} else {
int pos_index = 0;
mvprintw(0, 0, "Modify Model Positions (Press ENTER to edit, 'a' to add, 'd' to delete, 'm' to go back, 'q' to quit)");
for (const auto& [key, point] : properties.model_positions) {
mvprintw(2 + pos_index, 0, "%d. %s: (%d, %d)", pos_index + 1, key.c_str(), point.x, point.y);
if (pos_index == highlight) {
mvchgat(2 + pos_index, 0, -1, A_REVERSE, 0, NULL);
}
pos_index++;
}
}

int ch = getch();
switch (ch) {
case KEY_UP:
highlight = (highlight - 1 + (mode == 0 ? num_main_fields : properties.model_positions.size())) %
(mode == 0 ? num_main_fields : properties.model_positions.size());
break;
case KEY_DOWN:
highlight = (highlight + 1) % (mode == 0 ? num_main_fields : properties.model_positions.size());
break;
case '\n': {
if (mode == 0) {
int new_value;
echo();
mvprintw(10, 0, "Enter new value: ");
scanw("%d", &new_value);
noecho();

switch (highlight) {
case 0: properties.DEF_DELTAX = new_value; break;
case 1: properties.DEF_DELTAY = new_value; break;
case 2: properties.SKY_WIDTH = new_value; break;
case 3: properties.SKY_HEIGHT = new_value; break;
case 4: properties.SKY_COLOR = (color_t)new_value; break;
case 5: properties.A00_CAKE_INTERACT_LOOPC = new_value; break;
}
} else if (!properties.model_positions.empty()) {
auto it = properties.model_positions.begin();
std::advance(it, highlight);
echo();
int new_x, new_y;
mvprintw(10, 0, "Enter new x value: ");
scanw("%d", &new_x);
mvprintw(11, 0, "Enter new y value: ");
scanw("%d", &new_y);
noecho();

it->second.x = new_x;
it->second.y = new_y;
}
break;
}
case 'm':
mode = 1 - mode; // Toggle between main properties and model positions
highlight = 0;
break;
case 'a':
if (mode == 1) {
char new_key[64];
int new_x, new_y;
echo();
mvprintw(10, 0, "Enter new key: ");
getstr(new_key);
mvprintw(11, 0, "Enter x value: ");
scanw("%d", &new_x);
mvprintw(12, 0, "Enter y value: ");
scanw("%d", &new_y);
noecho();

properties.model_positions[std::string(new_key)] = {new_x, new_y};
}
break;
case 'd':
if (mode == 1 && !properties.model_positions.empty()) {
auto it = properties.model_positions.begin();
std::advance(it, highlight);
properties.model_positions.erase(it);
highlight = std::min(highlight, static_cast<int>(properties.model_positions.size()) - 1);
}
break;
case 'q':
exit_program = true;
break;
}
}
};
14 changes: 7 additions & 7 deletions lib/bin/gmeng.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ namespace Gmeng {
/// "-d" suffix means the version is a developer version, high unstability level
/// "-b" suffix means the version is a beta version, low unstability level but unpolished
/// "-c" suffix means the version is a coroded version, low to medium unstability level but specific methods will not perform as expected
static std::string version = "10.1.0-d";
static std::string version = "10.1.0";
enum color_t {
WHITE = 0,
BLUE = 1,
Expand Down Expand Up @@ -739,7 +739,7 @@ static void init_logc(int ms = 250) {
return;
#endif
__gmeng_write_log__("gmeng.log", "-- cleared previous log --\n", false);
__gmeng_write_log__("gmeng.log", "Gmeng: Go-To Console Game Engine.\nSPAWN(1) = v_success / at " + get_curtime() + "/" + get_curdate() + "\ncontroller_t of termui/_udisplay_of(GMENG, window) handed over to: controller_t(gmeng::threads::get(0))\n");
__gmeng_write_log__("gmeng.log", "Gmeng "+Gmeng::version+" (build " + GMENG_BUILD_NO + ").\n\nDocumentation available in https://gmeng.org.\nGmeng is an open source project. https://gmeng.org/git.\nPlease report bugs or unexpected behaviour at https://gmeng.org/report.\n\nGmeng: Go-To Console Game Engine.\n\nSPAWN(1) = v_success / at " + get_curtime() + "/" + get_curdate() + "\ncontroller_t of termui/_udisplay_of(GMENG, window) handed over to: controller_t(gmeng::threads::get(0))\n");
__gmeng_write_log__("gmeng.log", "----------------------------------\nExecutable Name: " + Gmeng::global.executable + "\nCurrent Working Directory: " + Gmeng::global.pwd + "\nCurrent User: " + Gmeng::global.user + "\n----------------------------------\n", true);
__gmeng_write_log__("gmeng.log", "Global Variables\n\t- devmode: " + boolstr(Gmeng::global.dev_mode) + "\n\t- debugger: " + boolstr(Gmeng::global.debugger) + "\n\t- silenced: " + boolstr(Gmeng::global.shush) + "\n\t- dont_hold_back: " + boolstr(Gmeng::global.dont_hold_back) + "\n----------------------------------\n", true);

Expand Down Expand Up @@ -843,22 +843,22 @@ static std::string ws2s(const std::wstring& wstr) {

///// __controller_satisfy__
///// OS Check for windows
static void __explain_why_i_cannot_run_to_dumbass_using_windows() {
__annot__(__explain_why_i_cannot_run_to_dumbass_using_windows, "explains to a user using windows why windows cannot run gmeng.");
__functree_call__(__explain_why_i_cannot_run_to_dumbass_using_windows);
static void print_windows_error_message() {
__annot__(print_windows_error_message, "explains to a user using windows why windows cannot run gmeng.");
__functree_call__(print_windows_error_message);
std::cout << Gmeng::colors[4] << "libgmeng-abi: __excuse__" << std::endl;
std::cout << "INTERNAL: __gmeng_platform__, __gmeng_threading__, __stdlib__, __libc++-abi__, __std_com_apple_main_pthread__" << std::endl;
std::cout << "Gmeng is not available in a core-platform other than darwin ( apple_kernel )." << std::endl;
std::cout << "current_platform: win32 ( WINDOWS_NT )" << std::endl;
std::cout << "__gmeng_halt_execution__( CAUSE( gmeng::global.v_exceptions->__find__( \"controller.platform\" ) ) && CAUSE( \"__environment_not_suitable__\" ) )" << std::endl;
std::cout << "__gmeng_halt_execution__( CAUSE( gmeng::global.v_exceptions->__find__( \"controller.platform\" ) ) && CAUSE( \"__environment_not_suitable__\" ) )" << Gmeng::resetcolor << std::endl;
exit(1);
};

static void patch_argv_global(int argc, char* argv[]) {
__annot__(patch_argv_global, "patches the Gmeng::global variable with the command-line arguments.");
__functree_call__(patch_argv_global);
#if _WIN32
__explain_why_i_cannot_run_to_dumbass_using_windows();
print_windows_error_message();
return;
#endif
Gmeng::global.pwd = get_cwd();
Expand Down
Loading

0 comments on commit 8fce6e3

Please sign in to comment.