summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c14
-rw-r--r--src/puzzles/puzzle.c50
-rw-r--r--src/puzzles/puzzle.h8
-rw-r--r--src/scenes/puzzleScene.c19
-rw-r--r--src/scenes/resultView.c5
-rw-r--r--src/ui_elements/Button.c5
-rw-r--r--src/ui_elements/UI.h3
7 files changed, 80 insertions, 24 deletions
diff --git a/src/main.c b/src/main.c
index 9ccb20e..1366f7b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,19 +6,7 @@
int main(void) {
Puzzle *puzzle = ReadPuzzleFromFile("puzzles/test.pz");
-
- // printf("Puzzle name: %s\n", puzzle->Name);
- // printf("Puzzle description: %s\n", puzzle->Description);
- // printf("Puzzle code: %s\n", puzzle->InitialCode);
- // printf("Puzzle TestC: %zu\n", puzzle->TestC);
-
- // for (int i = 0; i < puzzle->TestC; i++) {
- // Test t = puzzle->Tests[i];
- // printf("\n");
- // printf("\tTest rec: %s\n", t.RecieverName);
- // printf("\tTest sig: %s\n", t.MainMethodSignature);
- // printf("\tTest argc: %zu\n", t.argc);
- // }
+ PrintPuzzle(puzzle);
if (!ReadConfig(DEFAULT_CONFIG_LOCATION)) {
return 1;
diff --git a/src/puzzles/puzzle.c b/src/puzzles/puzzle.c
index 6d0a4a0..e14708f 100644
--- a/src/puzzles/puzzle.c
+++ b/src/puzzles/puzzle.c
@@ -5,6 +5,7 @@
#include <stdlib.h>
#include <string.h>
#include <wren.h>
+#include <stdbool.h>
static const char *USER_MODULE_NAME = "main";
@@ -37,12 +38,20 @@ Puzzle *GetTestPuzzle() {
return outp;
}
+void FreePuzzleIO(PuzzleIO *io) {
+ if (io->value != NULL)
+ free(io->value);
+}
+
void FreeTests(Test *Tests, size_t TestC) {
if (TestC == 0 || Tests == NULL) return;
for (size_t i = 0; i < TestC; i++) {
Test *t = &Tests[i];
if (t->RecieverName != NULL) free(t->RecieverName);
if (t->MainMethodSignature != NULL) free(t->MainMethodSignature);
+ for (size_t j = 0; j < t->argc; j++) {
+ FreePuzzleIO(&t->argv[j]);
+ }
if (t->argv != NULL) free(t->argv);
}
free(Tests);
@@ -362,3 +371,44 @@ void FreeSunmitionResult(SubmitionResult *res) {
if (res->stdout_sb != NULL) free(res->stdout_sb);
free(res);
}
+
+void PrintPuzzle(Puzzle *puzzle) {
+ printf("Puzzle name: %s\n", puzzle->Name);
+ printf("Puzzle description: %s\n", puzzle->Description);
+ printf("Puzzle code: %s\n", puzzle->InitialCode);
+ printf("Puzzle TestC: %zu\n", puzzle->TestC);
+
+ for (int i = 0; i < puzzle->TestC; i++) {
+ Test t = puzzle->Tests[i];
+ printf("\nTest %d:\n", i);
+ printf("\tTest rec: %s\n", t.RecieverName);
+ printf("\tTest sig: %s\n", t.MainMethodSignature);
+ printf("\tTest argc: %zu\n", t.argc);
+ printf("\tArguments:\n");
+
+ for (int j = 0; j < t.argc; j++) {
+ PuzzleIO io = t.argv[j];
+ switch (io.type) {
+ case WREN_TYPE_BOOL:
+ printf("\t\t(bool)%s\n", *(bool *)io.value ? "true" : "false");
+ break;
+ case WREN_TYPE_NUM:
+ printf("\t\t(num)%f\n", *(float *)io.value);
+ break;
+ case WREN_TYPE_LIST:
+ printf("\t\t(list)NOT SUPPORTED\n");
+ break;
+ case WREN_TYPE_MAP:
+ printf("\t\t(list)NOT SUPPORTED\n");
+ break;
+ case WREN_TYPE_NULL:
+ printf("\t\t(null)\n");
+ break;
+ case WREN_TYPE_STRING:
+ printf("\t\t(string)%s\n", (char *)io.value);
+ break;
+ default: break;
+ }
+ }
+ }
+}
diff --git a/src/puzzles/puzzle.h b/src/puzzles/puzzle.h
index 20193ca..70c6cad 100644
--- a/src/puzzles/puzzle.h
+++ b/src/puzzles/puzzle.h
@@ -56,11 +56,9 @@ typedef struct {
Test *Tests;
} Puzzle;
-Puzzle *ReadPuzzleFromFile(const char *path);
-
-void FreePuzzle(Puzzle *self);
/// A prebuilt puzzle. Used for debuging
Puzzle *GetTestPuzzle();
+Puzzle *ReadPuzzleFromFile(const char *path);
typedef struct {
char *stdout_sb;
@@ -70,6 +68,10 @@ typedef struct {
// Don't put anything in out_res, it will be overriten.
// The stdout of the VM will be there
SubmitionResult *SubmitSolution(Puzzle *self, char *script);
+
+void PrintPuzzle(Puzzle *puzzle);
+
void FreeSunmitionResult(SubmitionResult *res);
+void FreePuzzle(Puzzle *self);
#endif // PUZZLE_H
diff --git a/src/scenes/puzzleScene.c b/src/scenes/puzzleScene.c
index 67d3c86..48e1238 100644
--- a/src/scenes/puzzleScene.c
+++ b/src/scenes/puzzleScene.c
@@ -13,8 +13,9 @@ typedef struct {
const int HEADER_FONT_SIZE = 50;
const int PADDING = 10;
+const int EDITOR_PADDING = 3;
const int BORDER = 2;
-const int FOOTER_HEIGHT = 40;
+const int FOOTER_HEIGHT = 30;
void DrawPuzzleName(char *name) {
Vector2 width = MeasureTextEx(*GetMainFont(), name, 50, 1);
@@ -43,7 +44,6 @@ void DrawControls(Scene *self, Rectangle rect) {
.height = panel.height,
};
// Hacky. Should find a way to update in update()
- UpdateButton(data->submitButton, &submit_trg);
DrawButton(data->submitButton, &submit_trg);
acc -= (panel.height + PADDING);
}
@@ -104,7 +104,14 @@ bool drawPuzzleScene(void *self) {
DrawTextInRec(pane1, data->PuzzlePtr->Description,
GetMainFont(), 20, COLORSCHEME_BROWN, 3, &data->scroll);
- DrawTextArea(data->EditorInfo, pane2);
+
+ Rectangle editor_rect = {
+ .x = pane2.x + EDITOR_PADDING,
+ .y = pane2.y + EDITOR_PADDING,
+ .width = pane2.width - EDITOR_PADDING * 2,
+ .height = pane2.height - EDITOR_PADDING * 2,
+ };
+ DrawTextArea(data->EditorInfo, editor_rect);
Rectangle controls_rect = {
.x = PADDING,
@@ -134,9 +141,11 @@ bool updatePuzzleScene(void *self) {
GetPanesSplit(&pane1, &pane2, body, 0.35, 0.4);
UpdateTextArea(data->EditorInfo, pane2);
- if (IsKeyPressed(KEY_F5)) {
+ if (IsKeyPressed(KEY_F5))
SubmitPuzzle(self);
- }
+
+ if (data->submitButton != NULL)
+ UpdateButton(data->submitButton);
return true;
}
diff --git a/src/scenes/resultView.c b/src/scenes/resultView.c
index f3735ed..567cb02 100644
--- a/src/scenes/resultView.c
+++ b/src/scenes/resultView.c
@@ -1,6 +1,7 @@
#include <raylib.h>
#include <stdarg.h>
#include <stddef.h>
+#include <stdint.h>
#include <stdlib.h>
#include "scenes.h"
#include "../ui_elements/UI.h"
@@ -9,6 +10,7 @@
static const int PADDING = 20;
static const int BORDER = 2;
static const int SCROLL_SPEED = 10;
+static const uint8_t MAX_TINT = 96;
typedef struct {
SubmitionResult *value;
@@ -54,6 +56,9 @@ bool updateResultView(void *self) {
bool drawResultView(void *self) {
ResultViewData *data = ((Scene *)self)->data;
+ DrawRectangle(0, 0,
+ GetScreenWidth(), GetScreenHeight(),
+ (Color) {0, 0, 0, MAX_TINT * (1 - data->scroll_up) });
// DrawBackground();
Rectangle body = GetResultViewBodyRect(data->scroll_up);
diff --git a/src/ui_elements/Button.c b/src/ui_elements/Button.c
index f3ab8fa..e7293c8 100644
--- a/src/ui_elements/Button.c
+++ b/src/ui_elements/Button.c
@@ -1,8 +1,8 @@
#include "UI.h"
#include <raylib.h>
-void UpdateButton(Button *btn, Rectangle *location) {
- if (IsMouseInRec(*location) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
+void UpdateButton(Button *btn) {
+ if (IsMouseInRec(btn->previousFramePosition) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
btn->OnClick(btn->parent);
}
}
@@ -14,4 +14,5 @@ void DrawButton(Button *btn, Rectangle *location) {
(Vector2) { 0 , 0 },
0,
WHITE);
+ btn->previousFramePosition = *location;
}
diff --git a/src/ui_elements/UI.h b/src/ui_elements/UI.h
index c23faf7..532dd68 100644
--- a/src/ui_elements/UI.h
+++ b/src/ui_elements/UI.h
@@ -25,9 +25,10 @@ typedef struct {
void (*OnClick)(Scene *);
Texture *atlas;
Rectangle textrueLocation;
+ Rectangle previousFramePosition;
} Button;
-void UpdateButton(Button *btn, Rectangle *location);
+void UpdateButton(Button *btn);
void DrawButton(Button *btn, Rectangle *location);
// ========== TEXT EDITOR ==========