Code Editor WIP
This commit is contained in:
44
ascii.cpp
44
ascii.cpp
@@ -46,23 +46,21 @@ int pitch;
|
||||
uint32_t palette[16] = { 0x00000000, 0x000000AA, 0x0000AA00, 0x0000AAAA, 0x00AA0000, 0x00AA00AA, 0x00AA5500, 0x00AAAAAA,
|
||||
0x00555555, 0x005555FF, 0x0055FF55, 0x0055FFFF, 0x00FF5555, 0x00FF55FF, 0x00FFFF55, 0x00FFFFFF };
|
||||
|
||||
//[TODEL]#define debug_line_size 80
|
||||
//#define debug_num_lines 30
|
||||
//#define debug_total_size 2400 //debug_line_size*debug_num_lines
|
||||
//char debug_text[debug_total_size];
|
||||
//int debug_cursor = 0;
|
||||
int debug_prompt = -1;
|
||||
int debug_cursor_blink = 30;
|
||||
std::vector<std::string> cmd_list;
|
||||
bool should_reset = false;
|
||||
|
||||
//Uint8 keymapping[6] = { SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_Z, SDL_SCANCODE_X };
|
||||
const Uint8 *keys;
|
||||
Uint8 key_just_pressed = 0;
|
||||
|
||||
int mouse_x, mouse_y, mouse_wheel;
|
||||
Uint32 mouse_buttons;
|
||||
|
||||
const char* get_filename() {
|
||||
return lua_filename;
|
||||
}
|
||||
|
||||
void reinit() {
|
||||
if (mini_bak != NULL) SDL_DestroyTexture(mini_bak);
|
||||
switch (current_mode) {
|
||||
@@ -102,6 +100,18 @@ void reinit() {
|
||||
//SDL_RenderSetLogicalSize(mini_ren, 160, 120);
|
||||
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 160, 120);
|
||||
break;
|
||||
case 3: // SUPERSECRET MODE FOR THE EDITOR!!!
|
||||
screen_width = 80;
|
||||
screen_height = 30;
|
||||
current_color = 0x1f;
|
||||
current_border = 9;
|
||||
cursor_x = 0;
|
||||
cursor_y = 0;
|
||||
char_screen = &mem[0];
|
||||
color_screen = &mem[0x1200];
|
||||
//SDL_RenderSetLogicalSize(mini_ren, 640, 480);
|
||||
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 640, 240);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,11 +208,11 @@ int main(int argc,char*argv[]) {
|
||||
//setmode(0);
|
||||
} else {
|
||||
//setmode(old_mode);
|
||||
//lua_resume();
|
||||
lua_quit();
|
||||
reinit();
|
||||
lua_init(lua_filename);
|
||||
lua_call_init();
|
||||
lua_resume();
|
||||
//lua_quit();
|
||||
//reinit();
|
||||
//lua_init(lua_filename);
|
||||
//lua_call_init();
|
||||
}
|
||||
} else if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F5) {
|
||||
lua_quit();
|
||||
@@ -259,6 +269,7 @@ int main(int argc,char*argv[]) {
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
for (int y=0; y<screen_height; ++y) {
|
||||
for (int x=0; x<screen_width; ++x) {
|
||||
const uint8_t chr_color = COLSCR(x,y);
|
||||
@@ -467,6 +478,8 @@ void debugchr(const uint8_t chr) {
|
||||
char_screen[pos++] = 32;
|
||||
char_screen[pos] = 32;
|
||||
cursor_x--;
|
||||
} else {
|
||||
play("c");
|
||||
}
|
||||
} else {
|
||||
char_screen[pos] = chr;
|
||||
@@ -523,6 +536,8 @@ void debug_get_cmd() {
|
||||
reinit();
|
||||
lua_init(lua_filename);
|
||||
lua_call_init();
|
||||
} else if (cmd[0]=='c' && cmd[1]=='o' && cmd[2]=='n' && cmd[3]=='t' && cmd[4]=='\0') {
|
||||
lua_resume();
|
||||
} else {
|
||||
lua_call_cmd(cmd);
|
||||
debug_set_prompt();
|
||||
@@ -530,7 +545,8 @@ void debug_get_cmd() {
|
||||
}
|
||||
|
||||
void get_cmd_by_index() {
|
||||
const char* cmd = cmd_list[cmd_list.size()-cmd_index].c_str();
|
||||
if (cmd_list.size() == 0) return;
|
||||
const char* cmd = cmd_list[cmd_list.size()-cmd_index-1].c_str();
|
||||
int pos = cursor_x+cursor_y*screen_width;
|
||||
for (int i=debug_prompt;i<=pos;++i) char_screen[i] = 32;
|
||||
SDL_memcpy(&char_screen[debug_prompt], cmd, strlen(cmd));
|
||||
@@ -539,12 +555,12 @@ void get_cmd_by_index() {
|
||||
cursor_y = pos/screen_width;
|
||||
}
|
||||
void next_cmd() {
|
||||
if (cmd_index < cmd_list.size()) cmd_index++;
|
||||
if (cmd_index < cmd_list.size()-1) cmd_index++; else play("c");
|
||||
get_cmd_by_index();
|
||||
}
|
||||
|
||||
void prev_cmd() {
|
||||
if (cmd_index > 0) cmd_index--;
|
||||
if (cmd_index > 0) cmd_index--; else play("c");
|
||||
get_cmd_by_index();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user