Toying with raylib automation

This commit is contained in:
Krzosa Karol
2024-06-28 18:04:39 +02:00
parent 8528bfefc1
commit 2807573012
2 changed files with 87 additions and 17 deletions

View File

@@ -126,6 +126,68 @@ void Dbg_Draw() {
}
}
bool EventRecording = false;
bool EventPlaying = false;
AutomationEventList EventList;
void InitEventRecording() {
EventList = LoadAutomationEventList(0);
SetAutomationEventList(&EventList);
EventList = LoadAutomationEventList("automation.rae");
EventPlaying = true;
}
int ModifiedGetCharPressed() {
static int i;
int result = GetCharPressed();
if (EventPlaying && (i % 2) == 0) {
result = 'a';
}
i += 1;
return result;
}
void UpdateEventRecording() {
static unsigned int frameCounter;
static unsigned int playFrameCounter;
static unsigned int currentPlayFrame;
if (IsKeyPressed(KEY_F5)) {
if (EventRecording) {
StopAutomationEventRecording();
ExportAutomationEventList(EventList, "automation.rae");
EventRecording = false;
} else {
SetAutomationEventBaseFrame(0);
StartAutomationEventRecording();
EventRecording = true;
}
}
if (EventPlaying) {
// NOTE: Multiple events could be executed in a single frame
while (playFrameCounter == EventList.events[currentPlayFrame].frame) {
TraceLog(LOG_INFO, "PLAYING: PlayFrameCount: %i | currentPlayFrame: %i | Event Frame: %i, param: %i",
playFrameCounter, currentPlayFrame, EventList.events[currentPlayFrame].frame, EventList.events[currentPlayFrame].params[0]);
PlayAutomationEvent(EventList.events[currentPlayFrame]);
currentPlayFrame++;
if (currentPlayFrame == EventList.count) {
EventPlaying = false;
currentPlayFrame = 0;
playFrameCounter = 0;
TraceLog(LOG_INFO, "FINISH PLAYING!");
break;
}
}
playFrameCounter++;
}
}
int main() {
InitScratch();
InitWindow(800, 600, "Hello");
@@ -135,10 +197,8 @@ int main() {
InitArena(&PermArena);
float font_size = 64;
float font_spacing = 1;
Font font = LoadFontEx("C:/Windows/Fonts/times.ttf", (int)font_size, NULL, 250);
Font font = LoadFontEx("C:/Windows/Fonts/consola.ttf", (int)font_size, NULL, 250);
float title_bar_font_size = 15;
Font title_bar_font = LoadFontEx("C:/Windows/Fonts/times.ttf", (int)title_bar_font_size, NULL, 250);
if (0) font = LoadFontEx("C:/Windows/Fonts/consola.ttf", (int)font_size, NULL, 250);
Array<Window> windows = {};
@@ -152,14 +212,14 @@ int main() {
InitBuffer(&window.buffer);
if (1) {
Array<Edit> edits = {FrameArena};
AddEdit(&edits, GetEnd(window.buffer), Format(FrameArena, "line number: 1"));
ApplyEdits(&window.buffer, edits);
// for (int i = 0; i < 5; i += 1) {
// Array<Edit> edits = {FrameArena};
// AddEdit(&edits, GetEnd(window.buffer), Format(FrameArena, "line number: %d\n", i));
// ApplyEdits(&window.buffer, edits);
// }
// Array<Edit> edits = {FrameArena};
// AddEdit(&edits, GetEnd(window.buffer), Format(FrameArena, "line number: 1"));
// ApplyEdits(&window.buffer, edits);
for (int i = 0; i < 5; i += 1) {
Array<Edit> edits = {FrameArena};
AddEdit(&edits, GetEnd(window.buffer), Format(FrameArena, "line number: %d\n", i));
ApplyEdits(&window.buffer, edits);
}
}
window.cursors.add({});
@@ -168,6 +228,7 @@ int main() {
windows.add(window);
}
InitEventRecording();
// @todo: multiple ui elements, add focus
// @todo: immediate mode interface for all this
Vec2 camera_offset_world_to_render_units = {};
@@ -176,6 +237,9 @@ int main() {
Assert(it.cursors.len);
it.main_cursor_begin_frame = it.cursors[0];
}
UpdateEventRecording();
{
Window *focused_window = &windows[0];
@@ -247,10 +311,14 @@ int main() {
}
if (IsKeyPressed(KEY_DOWN) || IsKeyPressedRepeat(KEY_DOWN)) {
if (IsKeyDown(KEY_LEFT_SHIFT) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Ctrl + Alt + down
Array<Cursor> cursors_to_add = {FrameArena};
For(focused_window->cursors) {
int64_t front = GetFront(it);
front = MoveDown(focused_window->buffer, front);
focused_window->cursors.add({front, front});
cursors_to_add.add({front, front});
}
For(cursors_to_add) {
focused_window->cursors.add(it);
}
} else if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Shift + Alt + down
BeforeEdit(focused_window);
@@ -281,11 +349,13 @@ int main() {
if (IsKeyPressed(KEY_UP) || IsKeyPressedRepeat(KEY_UP)) {
if (IsKeyDown(KEY_LEFT_SHIFT) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Ctrl + Alt + up
Array<Cursor> cursors_to_add = {FrameArena};
For(focused_window->cursors) {
int64_t front = GetFront(it);
front = MoveUp(focused_window->buffer, front);
focused_window->cursors.add({front, front});
cursors_to_add.add({front, front});
}
For(cursors_to_add) focused_window->cursors.add(it);
} else if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Shift + Alt + up
BeforeEdit(focused_window);
Array<Edit> edits = {FrameArena};
@@ -423,7 +493,7 @@ int main() {
// Handle user input
for (;;) {
int c = GetCharPressed();
int c = ModifiedGetCharPressed();
if (!c) break;
String string = "?";