Compare commits
4 commits
4c9cafdff5
...
11e7e23962
Author | SHA1 | Date | |
---|---|---|---|
![]() |
11e7e23962 | ||
![]() |
7e44029c1d | ||
![]() |
b7063d99ee | ||
![]() |
98fd90ff4d |
12
TODO.txt
12
TODO.txt
|
@ -1,11 +1,11 @@
|
||||||
Design representation of internal state of dice tray
|
|
||||||
|
|
||||||
Buttons for adding dice to active set
|
|
||||||
|
|
||||||
Buttons for removing dice from active set
|
|
||||||
|
|
||||||
Roll modifier editor
|
Roll modifier editor
|
||||||
|
|
||||||
Button to roll the active set
|
Button to roll the active set
|
||||||
|
|
||||||
Design representation of internal state of initiative tracker
|
Design representation of internal state of initiative tracker
|
||||||
|
|
||||||
|
x Design representation of internal state of dice tray
|
||||||
|
|
||||||
|
x Buttons for adding dice to active set
|
||||||
|
|
||||||
|
x Buttons for removing dice from active set
|
||||||
|
|
19
src/dice.c
19
src/dice.c
|
@ -1,4 +1,5 @@
|
||||||
#include "dice.h"
|
#include "dice.h"
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
|
|
||||||
|
@ -10,6 +11,11 @@ int roll_die(enum die_type die) {
|
||||||
static int current_active_count = 0;
|
static int current_active_count = 0;
|
||||||
static enum die_type active_dice_set[MAX_ACTIVE_DICE];
|
static enum die_type active_dice_set[MAX_ACTIVE_DICE];
|
||||||
|
|
||||||
|
static struct roll_result_type roll_results[MAX_ACTIVE_DICE];
|
||||||
|
static struct roll_result_type roll_total = {
|
||||||
|
.roll = 0, .string_len = 0
|
||||||
|
};
|
||||||
|
|
||||||
enum die_type const *get_active_dice_set(size_t *out_length) {
|
enum die_type const *get_active_dice_set(size_t *out_length) {
|
||||||
if (out_length != nullptr) {
|
if (out_length != nullptr) {
|
||||||
*out_length = current_active_count;
|
*out_length = current_active_count;
|
||||||
|
@ -30,17 +36,12 @@ void remove_die_from_active(size_t index) {
|
||||||
--current_active_count;
|
--current_active_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct roll_result_type roll_active_dice_set(enum die_type die) {
|
void roll_active_dice_set(enum die_type die) {
|
||||||
struct roll_result_type results = {
|
|
||||||
.individual_result_count = MAX_ACTIVE_DICE,
|
|
||||||
.total = 0
|
|
||||||
};
|
|
||||||
for (size_t i = 0; i < current_active_count; ++i) {
|
for (size_t i = 0; i < current_active_count; ++i) {
|
||||||
results.individual_results[i] = roll_die(active_dice_set[i]);
|
roll_results[i].roll = roll_die(active_dice_set[i]);
|
||||||
results.total += results.individual_results[i];
|
snprintf(roll_results[i].string, MAX_ROLL_STR_LEN, "%d", roll_results[i].roll);
|
||||||
|
roll_total.roll += roll_results[i].roll;
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Clay_String die_to_str(enum die_type die) {
|
Clay_String die_to_str(enum die_type die) {
|
||||||
|
|
15
src/dice.h
15
src/dice.h
|
@ -8,6 +8,10 @@
|
||||||
#define MAX_ACTIVE_DICE 20
|
#define MAX_ACTIVE_DICE 20
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAX_ROLL_STR_LEN
|
||||||
|
#define MAX_ROLL_STR_LEN 5
|
||||||
|
#endif
|
||||||
|
|
||||||
enum die_type {
|
enum die_type {
|
||||||
COIN = 2,
|
COIN = 2,
|
||||||
D4 = 4,
|
D4 = 4,
|
||||||
|
@ -20,9 +24,9 @@ enum die_type {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct roll_result_type {
|
struct roll_result_type {
|
||||||
size_t individual_result_count;
|
int roll;
|
||||||
int individual_results[MAX_ACTIVE_DICE];
|
size_t string_len;
|
||||||
int total;
|
char string[MAX_ROLL_STR_LEN];
|
||||||
};
|
};
|
||||||
|
|
||||||
extern int roll_die(enum die_type die);
|
extern int roll_die(enum die_type die);
|
||||||
|
@ -30,7 +34,10 @@ extern int roll_die(enum die_type die);
|
||||||
extern enum die_type const *get_active_dice_set(size_t *out_length);
|
extern enum die_type const *get_active_dice_set(size_t *out_length);
|
||||||
extern size_t add_die_to_active(enum die_type die);
|
extern size_t add_die_to_active(enum die_type die);
|
||||||
extern void remove_die_from_active(size_t index);
|
extern void remove_die_from_active(size_t index);
|
||||||
extern struct roll_result_type roll_active_dice_set(enum die_type die);
|
|
||||||
|
extern struct roll_result_type *current_state(size_t *out_length);
|
||||||
|
|
||||||
|
extern void roll_active_dice_set(enum die_type die);
|
||||||
|
|
||||||
extern Clay_String die_to_str(enum die_type die);
|
extern Clay_String die_to_str(enum die_type die);
|
||||||
|
|
||||||
|
|
|
@ -114,6 +114,9 @@ void InitClay() {
|
||||||
Clay_Initialize(clayPrimaryArena, (Clay_Dimensions) { screenWidth, screenHeight }, (Clay_ErrorHandler) { HandleClayErrors });
|
Clay_Initialize(clayPrimaryArena, (Clay_Dimensions) { screenWidth, screenHeight }, (Clay_ErrorHandler) { HandleClayErrors });
|
||||||
Clay_SetMeasureTextFunction(MeasureText, fonts);
|
Clay_SetMeasureTextFunction(MeasureText, fonts);
|
||||||
Clay_SetLayoutDimensions((Clay_Dimensions) { screenWidth, screenHeight });
|
Clay_SetLayoutDimensions((Clay_Dimensions) { screenWidth, screenHeight });
|
||||||
|
float x, y;
|
||||||
|
SDL_GetMouseState(&x, &y);
|
||||||
|
Clay_SetPointerState((Clay_Vector2) { x, y }, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern Clay_RenderCommandArray RenderApplication();
|
extern Clay_RenderCommandArray RenderApplication();
|
||||||
|
@ -153,9 +156,9 @@ int main(int argc, char *argv[]) {
|
||||||
break;
|
break;
|
||||||
case SDL_EVENT_MOUSE_WHEEL:
|
case SDL_EVENT_MOUSE_WHEEL:
|
||||||
if (shiftDown) {
|
if (shiftDown) {
|
||||||
scrollMotion = (Clay_Vector2) { event.wheel.y * 2.f, event.wheel.x * 2.f };
|
scrollMotion = (Clay_Vector2) { event.wheel.y * 5.f, event.wheel.x * 5.f };
|
||||||
} else {
|
} else {
|
||||||
scrollMotion = (Clay_Vector2) { event.wheel.x * 2.f, event.wheel.y * 2.f };
|
scrollMotion = (Clay_Vector2) { event.wheel.x * 5.f, event.wheel.y * 5.f };
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_EVENT_MOUSE_MOTION:
|
case SDL_EVENT_MOUSE_MOTION:
|
||||||
|
|
Loading…
Reference in a new issue