164 lines
5.7 KiB
C++
164 lines
5.7 KiB
C++
#pragma once
|
|
|
|
#include "classes.h"
|
|
#include <array>
|
|
#include <compare>
|
|
#include <cstdint>
|
|
#include <deque>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
// The console's colors as 0xAARRGGBB. REPENTOGON's Console::Color names white and the warning yellow.
|
|
constexpr uint32_t CONSOLE_WHITE = 0xffd3d3d3;
|
|
constexpr uint32_t CONSOLE_WARNING = 0xfffcca03;
|
|
constexpr uint32_t CONSOLE_ERROR = 0xfff08080;
|
|
constexpr uint32_t CONSOLE_ECHO = 0xff808080;
|
|
// How many frames a printed line stays on the faded display.
|
|
constexpr int CONSOLE_FADE_FRAMES = 150;
|
|
constexpr int CONSOLE_SUGGESTION_COUNT = 6;
|
|
constexpr int DELIRIOUS_BOSS_COUNT = 59;
|
|
|
|
// Where the console is in sliding open and closed. Nothing known sets CONSOLE_REOPEN, which snaps back to open.
|
|
enum ConsoleState : int
|
|
{
|
|
CONSOLE_CLOSED,
|
|
CONSOLE_OPENING,
|
|
CONSOLE_OPEN,
|
|
CONSOLE_REOPEN,
|
|
CONSOLE_CLOSING
|
|
};
|
|
|
|
// Whether a line wraps again from its start, or only its last row after text was appended to it.
|
|
enum LineWrap
|
|
{
|
|
WRAP_APPENDED,
|
|
WRAP_ALL
|
|
};
|
|
|
|
// Whether the output is drawn at full strength, or faded by age and by distance from the newest row.
|
|
enum HistoryFade
|
|
{
|
|
HISTORY_SOLID,
|
|
HISTORY_FADED
|
|
};
|
|
|
|
// A boss Delirious and the delirious command spawn as a friend, as Entity_Player::console_spawn reads it: its health
|
|
// and how many come.
|
|
struct DeliriousBoss
|
|
{
|
|
int type = 0;
|
|
int variant = 0;
|
|
float health = 0;
|
|
int count = 1;
|
|
};
|
|
|
|
// The bosses Delirious picks from (0x00c33d80).
|
|
inline constexpr DeliriousBoss DELIRIOUS_BOSSES[DELIRIOUS_BOSS_COUNT] = {
|
|
{268, 0, 100, 1}, {74, 0, 40, 1}, {411, 0, 100, 1}, {79, 2, 100, 1}, {68, 1, 100, 1}, {402, 0, 100, 1},
|
|
{265, 0, 100, 1}, {28, 2, 100, 3}, {28, 1, 100, 3}, {28, 0, 100, 3}, {65, 1, 100, 1}, {101, 0, 100, 1},
|
|
{261, 1, 100, 1}, {267, 0, 100, 1}, {66, 0, 100, 1}, {261, 0, 100, 1}, {67, 0, 100, 1}, {81, 0, 100, 1},
|
|
{63, 0, 100, 1}, {71, 0, 25, 1}, {403, 0, 100, 1}, {62, 2, 100, 1}, {79, 0, 100, 1}, {43, 1, 100, 1},
|
|
{36, 0, 100, 1}, {99, 0, 100, 1}, {237, 1, 100, 1}, {82, 0, 100, 1}, {19, 1, 100, 3}, {407, 0, 180, 1},
|
|
{67, 1, 100, 1}, {19, 0, 100, 3}, {404, 0, 100, 1}, {69, 0, 100, 1}, {69, 1, 100, 1}, {97, 0, 100, 1},
|
|
{264, 0, 100, 1}, {262, 0, 100, 1}, {20, 0, 100, 1}, {43, 0, 100, 1}, {270, 0, 100, 1}, {68, 0, 100, 1},
|
|
{64, 0, 100, 1}, {62, 0, 100, 1}, {269, 0, 100, 1}, {405, 0, 100, 1}, {409, 0, 100, 1}, {62, 1, 100, 1},
|
|
{410, 0, 100, 1}, {401, 0, 100, 1}, {79, 1, 100, 1}, {71, 1, 25, 1}, {263, 0, 100, 1}, {260, 0, 100, 1},
|
|
{101, 1, 100, 1}, {237, 2, 100, 1}, {65, 0, 100, 1}, {100, 0, 100, 1}, {100, 1, 100, 1}};
|
|
|
|
// The collectible the metro command makes the Metronome become, 0 for a random one (0x00c7166c).
|
|
extern int g_metronomeItem;
|
|
|
|
// The console's font for the ConsoleFont option, with its row height and how far its glyphs sit from their row.
|
|
struct ConsoleText
|
|
{
|
|
Font* font = nullptr;
|
|
float lineHeight = 0;
|
|
float offsetY = 0;
|
|
};
|
|
|
|
// A place in the output: a line, newest first, and a row of that line counted up from its last.
|
|
struct ConsoleScroll
|
|
{
|
|
int line = 0;
|
|
int row = 0;
|
|
|
|
auto operator<=>(const ConsoleScroll&) const = default;
|
|
};
|
|
|
|
// A line of output: its text, where it wraps on screen (each row's start after the first), its color (alpha unused)
|
|
// and the frames it has left on the faded display.
|
|
struct ConsoleLine
|
|
{
|
|
std::string text;
|
|
std::vector<size_t> breaks;
|
|
uint32_t color = CONSOLE_WHITE;
|
|
int fadeFrames = CONSOLE_FADE_FRAMES;
|
|
|
|
// The rows the line takes on screen.
|
|
int row_count() { return (int)breaks.size() + 1; }
|
|
std::string_view row_get(int row);
|
|
void wrap(LineWrap mode);
|
|
};
|
|
|
|
// The debug console (Game's _console): the output, newest line first, the typed input with its cursor and suggestions,
|
|
// the commands run before, and the panel sliding down over the game.
|
|
// Destruction (00685fc0) is the default, and so are the std::deque and std::string helpers only the console used
|
|
// (006935c0, 00693be0, 006938e0, 00693ac0, 00693d20).
|
|
struct Console
|
|
{
|
|
std::array<std::string, CONSOLE_SUGGESTION_COUNT> suggestions;
|
|
std::deque<ConsoleLine> history;
|
|
std::deque<std::string> commandHistory;
|
|
std::vector<size_t> inputBreaks;
|
|
std::string input;
|
|
std::string* capture = nullptr;
|
|
ConsoleScroll scroll;
|
|
ConsoleState state = CONSOLE_CLOSED;
|
|
float height = 0;
|
|
size_t cursor = 0;
|
|
int animationFrame = 0;
|
|
int blinkFrame = 0;
|
|
int commandCursor = 0;
|
|
int repeatFrames = 0;
|
|
int repeatKey = 0;
|
|
|
|
void reset();
|
|
void history_clear();
|
|
void LoadCommandHistory();
|
|
void history_push(std::string line);
|
|
|
|
void Print(std::string_view text, uint32_t color = CONSOLE_WHITE, int fadeFrames = CONSOLE_FADE_FRAMES);
|
|
void PrintError(std::string_view error);
|
|
void print_format(uint32_t color, const char* format, ...) __attribute__((format(printf, 3, 4)));
|
|
void RunCommand(std::string_view command, std::string* output = nullptr, Entity_Player* player = nullptr);
|
|
|
|
bool update_state();
|
|
void Update();
|
|
void Close();
|
|
void FillOmnicomplete();
|
|
|
|
void Render();
|
|
void RenderHistory(ConsoleText& text, Vector position, float alpha, HistoryFade fade);
|
|
|
|
ConsoleScroll scroll_min_get();
|
|
ConsoleScroll scroll_max_get();
|
|
void lines_wrap();
|
|
void input_wrap();
|
|
|
|
private:
|
|
void line_begin();
|
|
void line_append(std::string_view text, uint32_t color, int fadeFrames);
|
|
void scroll_row_clamp();
|
|
bool is_key_repeated(int key);
|
|
void control_update();
|
|
void input_update();
|
|
void input_erase(size_t position);
|
|
bool is_input_pasted();
|
|
void input_submit();
|
|
};
|
|
|
|
ConsoleText console_text_get();
|
|
std::vector<std::string> text_split(std::string_view text, char delimiter);
|
|
std::string lua_code_run(std::string_view code);
|