cleaned up a bit
This commit is contained in:
parent
88524eea4c
commit
ad7b81f448
4
Makefile
4
Makefile
@ -8,10 +8,10 @@ CFLAGS = -g -Wall
|
|||||||
default: $(TARGET)
|
default: $(TARGET)
|
||||||
all: default
|
all: default
|
||||||
|
|
||||||
OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
|
OBJECTS = $(patsubst src/%.c, %.o, $(wildcard src/*.c))
|
||||||
HEADERS = $(wildcard *.h)
|
HEADERS = $(wildcard *.h)
|
||||||
|
|
||||||
%.o: %.c $(HEADERS)
|
%.o: src/%.c $(HEADERS)
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
.PRECIOUS: $(TARGET) $(OBJECTS)
|
.PRECIOUS: $(TARGET) $(OBJECTS)
|
||||||
|
18
README.md
18
README.md
@ -9,3 +9,21 @@ A speedrun timer for \*nix terminals
|
|||||||
- Human readable JSON splits file
|
- Human readable JSON splits file
|
||||||
- Import splits from a Splits.io file
|
- Import splits from a Splits.io file
|
||||||
- High fps rendering
|
- High fps rendering
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Copy `examples/sample.json` somewhere, replace the sample information with
|
||||||
|
the names of your game, catagories and splits. Changing split names/number of
|
||||||
|
splits after the first use of the split file is currently unsupported.
|
||||||
|
|
||||||
|
### Default Keybinds
|
||||||
|
| Keys | Action |
|
||||||
|
| ---- | --------------------- |
|
||||||
|
| `R` | Start |
|
||||||
|
| `F` | Stop |
|
||||||
|
| `E` | Split |
|
||||||
|
| `G` | Undo split |
|
||||||
|
| `C` | Close |
|
||||||
|
| `T` | Toggle global hotkeys |
|
||||||
|
|
||||||
|
Customisable hotkeys without editing the source code coming soon!
|
||||||
|
17
examples/sample.json
Normal file
17
examples/sample.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"game": {
|
||||||
|
"name": "Game Name"
|
||||||
|
},
|
||||||
|
"category": {
|
||||||
|
"name": "Catagory Name"
|
||||||
|
},
|
||||||
|
"segments": [{
|
||||||
|
"name": "First Split"
|
||||||
|
}, {
|
||||||
|
"name": "Second Split"
|
||||||
|
}, {
|
||||||
|
"name": "Third Split"
|
||||||
|
}, {
|
||||||
|
"name": "Last Split"
|
||||||
|
}]
|
||||||
|
}
|
@ -25,6 +25,8 @@ void dispatch_proc(uiohook_event * const event) {
|
|||||||
buf = K_CLOSE;
|
buf = K_CLOSE;
|
||||||
if (event->data.keyboard.keycode == km.HOTKS)
|
if (event->data.keyboard.keycode == km.HOTKS)
|
||||||
buf = K_HOTKS;
|
buf = K_HOTKS;
|
||||||
|
if (event->data.keyboard.keycode == km.USPLT)
|
||||||
|
buf = K_USPLT;
|
||||||
write(pipefd[1], &buf, 1);
|
write(pipefd[1], &buf, 1);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -46,6 +48,8 @@ int handleInput()
|
|||||||
tpause();
|
tpause();
|
||||||
if (buf == K_HOTKS)
|
if (buf == K_HOTKS)
|
||||||
hotkeys_enabled = !hotkeys_enabled;
|
hotkeys_enabled = !hotkeys_enabled;
|
||||||
|
if (buf == K_USPLT)
|
||||||
|
unsplit();
|
||||||
if (buf == K_CLOSE)
|
if (buf == K_CLOSE)
|
||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
@ -11,6 +11,7 @@
|
|||||||
#define K_SPLIT 4
|
#define K_SPLIT 4
|
||||||
#define K_CLOSE 5
|
#define K_CLOSE 5
|
||||||
#define K_HOTKS 6
|
#define K_HOTKS 6
|
||||||
|
#define K_USPLT 7
|
||||||
|
|
||||||
struct keymap
|
struct keymap
|
||||||
{
|
{
|
||||||
@ -20,6 +21,7 @@ struct keymap
|
|||||||
uint16_t SPLIT;
|
uint16_t SPLIT;
|
||||||
uint16_t CLOSE;
|
uint16_t CLOSE;
|
||||||
uint16_t HOTKS;
|
uint16_t HOTKS;
|
||||||
|
uint16_t USPLT;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern char buf;
|
extern char buf;
|
@ -6,11 +6,13 @@ int currentMS = 0;
|
|||||||
bool timerActive;
|
bool timerActive;
|
||||||
|
|
||||||
//UI
|
//UI
|
||||||
|
struct color bg = { 47, 53, 66};
|
||||||
|
struct color fg = {247, 248, 242};
|
||||||
int h, w;
|
int h, w;
|
||||||
int deltasEnabled = 1;
|
int deltaOn = 1;
|
||||||
int sgmtdurEnabled = 1;
|
int sgmtdurOn = 1;
|
||||||
int pbEnabled = 1;
|
int pbOn = 1;
|
||||||
bool resized = false;
|
bool resized = false;
|
||||||
|
|
||||||
//Splits.io data
|
//Splits.io data
|
||||||
const char *schemaver = "v1.0.1";
|
const char *schemaver = "v1.0.1";
|
||||||
@ -21,18 +23,18 @@ const char *timerlink = "https://github.com/SilentFungus/quest";
|
|||||||
|
|
||||||
//Run data
|
//Run data
|
||||||
char *filepath;
|
char *filepath;
|
||||||
char *gameTitle = "title not loaded";
|
char *gameTitle = "title not loaded";
|
||||||
char *categoryTitle = "category not loaded";
|
char *categoryTitle = "category not loaded";
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
int bestTime = 0;
|
int bestTime = 0;
|
||||||
int bestAttempt = 0;
|
int bestAttempt = 0;
|
||||||
struct segment *segments;
|
struct segment *segments;
|
||||||
struct segment *pbrun;
|
struct segment *pbrun;
|
||||||
struct segment *wrrun;
|
struct segment *wrrun;
|
||||||
struct segment *bestsegs;
|
struct segment *bestsegs;
|
||||||
struct pastseg *runHistory;
|
struct pastseg *pastRuns;
|
||||||
int segmentCount;
|
int segCount;
|
||||||
int currentSegment = -1;
|
int currSeg = -1;
|
||||||
char currentTime[10];
|
char currentTime[10];
|
||||||
|
|
||||||
void sub_timespec(struct timespec t1, struct timespec t2, struct timespec* td)
|
void sub_timespec(struct timespec t1, struct timespec t2, struct timespec* td)
|
||||||
@ -48,32 +50,23 @@ void sub_timespec(struct timespec t1, struct timespec t2, struct timespec* td)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_timespec(struct timespec t1, struct timespec t2, struct timespec* td)
|
|
||||||
{
|
|
||||||
td->tv_nsec = t2.tv_nsec + t1.tv_nsec;
|
|
||||||
td->tv_sec = t2.tv_sec + t1.tv_sec;
|
|
||||||
if (td->tv_nsec < 0) {
|
|
||||||
td->tv_nsec += NS_PER_S;
|
|
||||||
td->tv_sec++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void reset()
|
void reset()
|
||||||
{
|
{
|
||||||
if (!timerActive)
|
if (!timerActive)
|
||||||
return;
|
return;
|
||||||
segments[currentSegment].isReset = true;
|
segments[currSeg].isReset = true;
|
||||||
stop();
|
stop();
|
||||||
|
currSeg = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void start()
|
void start()
|
||||||
{
|
{
|
||||||
if (timerActive || segmentCount == 0)
|
if (timerActive || segCount == 0)
|
||||||
return;
|
return;
|
||||||
clock_gettime(CLOCK_REALTIME, ×tart);
|
clock_gettime(CLOCK_REALTIME, ×tart);
|
||||||
timerActive = true;
|
timerActive = true;
|
||||||
resized = true;
|
resized = true;
|
||||||
currentSegment = 0;
|
currSeg = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop()
|
void stop()
|
||||||
@ -82,34 +75,36 @@ void stop()
|
|||||||
return;
|
return;
|
||||||
timerActive = false;
|
timerActive = false;
|
||||||
attempts++;
|
attempts++;
|
||||||
if (runHistory)
|
if (pastRuns)
|
||||||
runHistory = realloc(runHistory, attempts * segmentCount * sizeof(struct pastseg));
|
pastRuns = realloc(pastRuns, attempts * segCount * sizeof(struct pastseg));
|
||||||
else
|
else
|
||||||
runHistory = calloc(segmentCount, sizeof(struct pastseg));
|
pastRuns = calloc(segCount, sizeof(struct pastseg));
|
||||||
for (int i = 0; i < segmentCount; i++) {
|
for (int i = 0; i < segCount; i++) {
|
||||||
struct pastseg t;
|
struct pastseg t;
|
||||||
t.realtimeMS = segments[i].realtimeMS;
|
t.ms = segments[i].ms;
|
||||||
t.isSkipped = segments[i].isSkipped;
|
t.isSkipped = segments[i].isSkipped;
|
||||||
t.isReset = segments[i].isReset;
|
t.isReset = segments[i].isReset;
|
||||||
runHistory[((attempts-1) * segmentCount) + i] = t;
|
pastRuns[((attempts-1) * segCount) + i] = t;
|
||||||
}
|
}
|
||||||
calculatePB();
|
calculatePB();
|
||||||
saveFile();
|
saveFile();
|
||||||
if (currentSegment >= segmentCount) {
|
|
||||||
//reset();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void split()
|
void split()
|
||||||
{
|
{
|
||||||
if (!timerActive)
|
if (!timerActive)
|
||||||
return;
|
return;
|
||||||
segments[currentSegment].realtimeMS = currentMS;
|
segments[currSeg].ms = currentMS;
|
||||||
//segments[currentSegment].gametimeMS = currentMS;
|
currSeg++;
|
||||||
currentSegment++;
|
if (currSeg >= segCount)
|
||||||
if (currentSegment >= segmentCount)
|
|
||||||
stop();
|
stop();
|
||||||
resized = true;
|
}
|
||||||
|
|
||||||
|
void unsplit()
|
||||||
|
{
|
||||||
|
if (!timerActive)
|
||||||
|
return;
|
||||||
|
currSeg--;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tpause()
|
void tpause()
|
||||||
@ -125,40 +120,16 @@ void loadKeymap()
|
|||||||
km.SPLIT = VC_E;
|
km.SPLIT = VC_E;
|
||||||
km.CLOSE = VC_C;
|
km.CLOSE = VC_C;
|
||||||
km.HOTKS = VC_T;
|
km.HOTKS = VC_T;
|
||||||
//char path[256];
|
km.USPLT = VC_G;
|
||||||
//strcat(strcpy(path, getenv("HOME")), "/.config/qtimer");
|
|
||||||
//mkdir(path, 0777);
|
|
||||||
//strcat(strcpy(path, getenv("HOME")), "/.config/qtimer/keymaps");
|
|
||||||
//mkdir(path, 0777);
|
|
||||||
//strcat(strcpy(path, getenv("HOME")), "/.config/qtimer/keymaps/default");
|
|
||||||
|
|
||||||
//FILE* fp = fopen(path, "r");
|
|
||||||
|
|
||||||
//if (fp == NULL) {
|
|
||||||
//km.START = VC_R;
|
|
||||||
//km.STOP = VC_F;
|
|
||||||
//km.PAUSE = VC_D;
|
|
||||||
//km.SPLIT = VC_E;
|
|
||||||
//fp = fopen(path, "w");
|
|
||||||
//fprintf(fp, "START = R\n");
|
|
||||||
//fprintf(fp, "STOP = F\n");
|
|
||||||
//fprintf(fp, "PAUSE = D\n");
|
|
||||||
//fprintf(fp, "SPLIT = E\n");
|
|
||||||
//fclose(fp);
|
|
||||||
//} else {
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
//fclose(fp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ftime(char *timestr, bool withMS, int ms)
|
void ftime(char *timestr, bool withMS, int rms)
|
||||||
{
|
{
|
||||||
int seconds = ms / 1000;
|
int seconds = rms / 1000;
|
||||||
int minutes = seconds / 60;
|
int minutes = seconds / 60;
|
||||||
int hours = minutes / 60;
|
int hours = minutes / 60;
|
||||||
//A few better formatted variables for displaying these numbers
|
//A few better formatted variables for displaying these numbers
|
||||||
int tms = (ms % 1000) / 10;
|
int tms = (rms % 1000) / 10;
|
||||||
int oms = tms / 10;
|
int oms = tms / 10;
|
||||||
int s = seconds % 60;
|
int s = seconds % 60;
|
||||||
int m = minutes % 60;
|
int m = minutes % 60;
|
||||||
@ -184,27 +155,27 @@ void ftime(char *timestr, bool withMS, int ms)
|
|||||||
|
|
||||||
int timespecToMS(struct timespec t)
|
int timespecToMS(struct timespec t)
|
||||||
{
|
{
|
||||||
int ms = t.tv_nsec / 1000000;
|
int rms = t.tv_nsec / 1000000;
|
||||||
ms += t.tv_sec * 1000;
|
rms += t.tv_sec * 1000;
|
||||||
return ms;
|
return rms;
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawSegments()
|
void drawSegments()
|
||||||
{
|
{
|
||||||
char data[(deltasEnabled * 10) + (sgmtdurEnabled * 10) + (pbEnabled * 10) + 11];
|
char data[(deltaOn * 10) + (sgmtdurOn * 10) + (pbOn * 10) + 11];
|
||||||
char segmentTime[11];
|
char segmentTime[11];
|
||||||
char *zeroStr = "-";
|
char *zeroStr = "-";
|
||||||
char deltaTime[11];
|
char deltaTime[11];
|
||||||
char sgmtTime[11];
|
char sgmtTime[11];
|
||||||
char segTime[11];
|
char segTime[11];
|
||||||
for(int i = 0; i < segmentCount; i++) {
|
for(int i = 0; i < segCount; i++) {
|
||||||
ftime(segmentTime, false, pbrun[i].realtimeMS);
|
ftime(segmentTime, false, pbrun[i].ms);
|
||||||
if (i >= currentSegment) {
|
if (i >= currSeg) {
|
||||||
sprintf(data, "%10s%10s%10s%10s", zeroStr, zeroStr, zeroStr, segmentTime);
|
sprintf(data, "%10s%10s%10s%10s", zeroStr, zeroStr, zeroStr, segmentTime);
|
||||||
} else {
|
} else {
|
||||||
ftime(deltaTime, false, segments[i].realtimeMS - pbrun[i].realtimeMS);
|
ftime(deltaTime, false, segments[i].ms - pbrun[i].ms);
|
||||||
ftime(sgmtTime, false, segments[i].realtimeMS - segments[i - 1].realtimeMS);
|
ftime(sgmtTime, false, segments[i].ms - segments[i - 1].ms);
|
||||||
ftime(segTime, false, segments[i].realtimeMS);
|
ftime(segTime, false, segments[i].ms);
|
||||||
sprintf(data, "%10s%10s%10s%10s", deltaTime, sgmtTime, segTime, segmentTime);
|
sprintf(data, "%10s%10s%10s%10s", deltaTime, sgmtTime, segTime, segmentTime);
|
||||||
}
|
}
|
||||||
rghtPrint(6 + i, w, data);
|
rghtPrint(6 + i, w, data);
|
||||||
@ -214,32 +185,32 @@ void drawSegments()
|
|||||||
|
|
||||||
void drawCurrentSegment()
|
void drawCurrentSegment()
|
||||||
{
|
{
|
||||||
char data[(deltasEnabled * 10) + (sgmtdurEnabled * 10) + (pbEnabled * 10) + 11];
|
char data[(deltaOn * 10) + (sgmtdurOn * 10) + (pbOn * 10) + 11];
|
||||||
strcpy(data, "");
|
strcpy(data, "");
|
||||||
char pbTime[11];
|
char pbTime[11];
|
||||||
char deltaTime[11];
|
char deltaTime[11];
|
||||||
char sgmtTime[11];
|
char sgmtTime[11];
|
||||||
char segTime[11];
|
char segTime[11];
|
||||||
if (deltasEnabled) {
|
if (deltaOn) {
|
||||||
ftime(deltaTime, false, currentMS - pbrun[currentSegment].realtimeMS);
|
ftime(deltaTime, false, currentMS - pbrun[currSeg].ms);
|
||||||
strcat(data, deltaTime);
|
strcat(data, deltaTime);
|
||||||
}
|
}
|
||||||
if (sgmtdurEnabled) {
|
if (sgmtdurOn) {
|
||||||
if (currentSegment == 0)
|
if (currSeg == 0)
|
||||||
ftime(sgmtTime, false, currentMS);
|
ftime(sgmtTime, false, currentMS);
|
||||||
else
|
else
|
||||||
ftime(sgmtTime, false, currentMS - segments[currentSegment - 1].realtimeMS);
|
ftime(sgmtTime, false, currentMS - segments[currSeg - 1].ms);
|
||||||
strcat(data, sgmtTime);
|
strcat(data, sgmtTime);
|
||||||
}
|
}
|
||||||
ftime(segTime, false, currentMS);
|
ftime(segTime, false, currentMS);
|
||||||
strcat(data, segTime);
|
strcat(data, segTime);
|
||||||
if (pbEnabled) {
|
if (pbOn) {
|
||||||
ftime(pbTime, true, pbrun[currentSegment].realtimeMS);
|
ftime(pbTime, true, pbrun[currSeg].ms);
|
||||||
strcat(data, pbTime);
|
strcat(data, pbTime);
|
||||||
}
|
}
|
||||||
data[(deltasEnabled * 10) + (sgmtdurEnabled * 10) + (pbEnabled * 10) + 11] = '\0';
|
data[(deltaOn * 10) + (sgmtdurOn * 10) + (pbOn * 10) + 11] = '\0';
|
||||||
rghtPrint(6 + currentSegment, w, data);
|
rghtPrint(6 + currSeg, w, data);
|
||||||
leftPrint(6 + currentSegment, w, segments[currentSegment].name);
|
leftPrint(6 + currSeg, w, segments[currSeg].name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawDisplay()
|
void drawDisplay()
|
||||||
@ -260,16 +231,15 @@ void drawDisplay()
|
|||||||
rghtPrint(4, w, cols);
|
rghtPrint(4, w, cols);
|
||||||
drawHLine(5, w);
|
drawHLine(5, w);
|
||||||
printf("\033[5;3H[dsph]");
|
printf("\033[5;3H[dsph]");
|
||||||
//drawSegments();
|
|
||||||
if (timerActive) {
|
if (timerActive) {
|
||||||
drawCurrentSegment();
|
drawCurrentSegment();
|
||||||
struct timespec delta;
|
struct timespec delta;
|
||||||
sub_timespec(timestart, finish, &delta);
|
sub_timespec(timestart, finish, &delta);
|
||||||
currentMS = timespecToMS(delta);
|
currentMS = timespecToMS(delta);
|
||||||
}
|
}
|
||||||
drawHLine(segmentCount + 6, w);
|
drawHLine(segCount + 6, w);
|
||||||
ftime(currentTime, true, currentMS);
|
ftime(currentTime, true, currentMS);
|
||||||
rghtPrint(segmentCount + 7, w, currentTime);
|
rghtPrint(segCount + 7, w, currentTime);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,21 +258,23 @@ void calculatePB()
|
|||||||
{
|
{
|
||||||
if (attempts == 0)
|
if (attempts == 0)
|
||||||
return;
|
return;
|
||||||
int bestMS = INT_MAX;
|
int bestMS = INT_MAX;
|
||||||
int bestAttempt = 0;
|
int bestAttempt = 0;
|
||||||
for (int i = 0; i < attempts; i++) {
|
for (int i = 0; i < attempts; i++) {
|
||||||
|
int run = i * segCount;
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
for (int j = 0; j < segmentCount; j++) {
|
for (int j = 0; j < segCount; j++) {
|
||||||
if (runHistory[(i * segmentCount) + j].isSkipped == true || runHistory[(i * segmentCount) + j].isReset == true)
|
if (pastRuns[run + j].isSkipped == true ||
|
||||||
|
pastRuns[run + j].isReset == true)
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
if (valid && runHistory[(i * segmentCount) + segmentCount - 1].realtimeMS < bestMS) {
|
if (valid && pastRuns[run + segCount - 1].ms < bestMS) {
|
||||||
bestAttempt = i;
|
bestAttempt = i;
|
||||||
bestMS = runHistory[(i * segmentCount) + segmentCount - 1].realtimeMS;
|
bestMS = pastRuns[run + segCount - 1].ms;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < segmentCount; i++) {
|
for (int i = 0; i < segCount; i++) {
|
||||||
pbrun[i].realtimeMS = runHistory[(bestAttempt * segmentCount) + i].realtimeMS;
|
pbrun[i].ms = pastRuns[(bestAttempt * segCount) + i].ms;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,7 +313,7 @@ void loadFile()
|
|||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
cJSON *schema = cJSON_GetObjectItemCaseSensitive(splitfile, "_schemaVersion");
|
cJSON *schema = cJSON_GetItem(splitfile, "_schemaVersion");
|
||||||
if (schema) {
|
if (schema) {
|
||||||
importSplitsIO(splitfile);
|
importSplitsIO(splitfile);
|
||||||
return;
|
return;
|
||||||
@ -352,42 +324,42 @@ void loadFile()
|
|||||||
cJSON *atts = NULL;
|
cJSON *atts = NULL;
|
||||||
cJSON *segs = NULL;
|
cJSON *segs = NULL;
|
||||||
cJSON *runs = NULL;
|
cJSON *runs = NULL;
|
||||||
game = cJSON_GetObjectItemCaseSensitive(splitfile, "game");
|
game = cJSON_GetItem(splitfile, "game");
|
||||||
cate = cJSON_GetObjectItemCaseSensitive(splitfile, "category");
|
cate = cJSON_GetItem(splitfile, "category");
|
||||||
atts = cJSON_GetObjectItemCaseSensitive(splitfile, "attempts");
|
atts = cJSON_GetItem(splitfile, "attempts");
|
||||||
segs = cJSON_GetObjectItemCaseSensitive(splitfile, "segments");
|
segs = cJSON_GetItem(splitfile, "segments");
|
||||||
runs = cJSON_GetObjectItemCaseSensitive(splitfile, "history");
|
runs = cJSON_GetItem(splitfile, "history");
|
||||||
|
|
||||||
if (game) {
|
if (game) {
|
||||||
cJSON *title = cJSON_GetObjectItemCaseSensitive(game, "name");
|
cJSON *title = cJSON_GetItem(game, "name");
|
||||||
if (cJSON_IsString(title) && (title->valuestring != NULL)) {
|
if (cJSON_IsString(title) && (title->valuestring != NULL)) {
|
||||||
gameTitle = malloc(strlen(title->valuestring));
|
gameTitle = malloc(strlen(title->valuestring));
|
||||||
strcpy(gameTitle, title->valuestring);
|
strcpy(gameTitle, title->valuestring);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cate) {
|
if (cate) {
|
||||||
cJSON *title = cJSON_GetObjectItemCaseSensitive(cate, "name");
|
cJSON *title = cJSON_GetItem(cate, "name");
|
||||||
if (cJSON_IsString(title) && (title->valuestring != NULL)) {
|
if (cJSON_IsString(title) && (title->valuestring != NULL)) {
|
||||||
categoryTitle = malloc(strlen(title->valuestring));
|
categoryTitle = malloc(strlen(title->valuestring));
|
||||||
strcpy(categoryTitle, title->valuestring);
|
strcpy(categoryTitle, title->valuestring);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (atts) {
|
if (atts) {
|
||||||
cJSON *total = cJSON_GetObjectItemCaseSensitive(atts, "total");
|
cJSON *total = cJSON_GetItem(atts, "total");
|
||||||
if (cJSON_IsNumber(total))
|
if (cJSON_IsNumber(total))
|
||||||
attempts = total->valueint;
|
attempts = total->valueint;
|
||||||
}
|
}
|
||||||
if (segs) {
|
if (segs) {
|
||||||
segmentCount = cJSON_GetArraySize(segs);
|
segCount = cJSON_GetArraySize(segs);
|
||||||
segments = calloc(segmentCount, sizeof(struct segment));
|
segments = calloc(segCount, sizeof(struct segment));
|
||||||
pbrun = calloc(segmentCount, sizeof(struct segment));
|
pbrun = calloc(segCount, sizeof(struct segment));
|
||||||
wrrun = calloc(segmentCount, sizeof(struct segment));
|
wrrun = calloc(segCount, sizeof(struct segment));
|
||||||
bestsegs = calloc(segmentCount, sizeof(struct segment));
|
bestsegs = calloc(segCount, sizeof(struct segment));
|
||||||
int it = 0;
|
int it = 0;
|
||||||
cJSON *iterator = NULL;
|
cJSON *iterator = NULL;
|
||||||
cJSON *segname = NULL;
|
cJSON *segname = NULL;
|
||||||
cJSON_ArrayForEach(iterator, segs) {
|
cJSON_ArrayForEach(iterator, segs) {
|
||||||
segname = cJSON_GetObjectItemCaseSensitive(iterator, "name");
|
segname = cJSON_GetItem(iterator, "name");
|
||||||
if (cJSON_IsString(segname) && (segname->valuestring != NULL)) {
|
if (cJSON_IsString(segname) && (segname->valuestring != NULL)) {
|
||||||
segments[it].name = malloc(strlen(segname->valuestring));
|
segments[it].name = malloc(strlen(segname->valuestring));
|
||||||
strcpy(segments[it].name, segname->valuestring);
|
strcpy(segments[it].name, segname->valuestring);
|
||||||
@ -397,7 +369,7 @@ void loadFile()
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (runs) {
|
if (runs) {
|
||||||
runHistory = calloc(cJSON_GetArraySize(runs) * segmentCount, sizeof(struct pastseg));
|
pastRuns = calloc(cJSON_GetArraySize(runs) * segCount, sizeof(struct pastseg));
|
||||||
int oI = 0;
|
int oI = 0;
|
||||||
cJSON *oIterator = NULL;
|
cJSON *oIterator = NULL;
|
||||||
cJSON_ArrayForEach(oIterator, runs) {
|
cJSON_ArrayForEach(oIterator, runs) {
|
||||||
@ -406,11 +378,11 @@ void loadFile()
|
|||||||
cJSON_ArrayForEach(iIterator, oIterator) {
|
cJSON_ArrayForEach(iIterator, oIterator) {
|
||||||
struct pastseg t;
|
struct pastseg t;
|
||||||
|
|
||||||
cJSON *ms = cJSON_GetObjectItemCaseSensitive(iIterator, "ms");
|
cJSON *rms = cJSON_GetItem(iIterator, "rms");
|
||||||
cJSON *skp = cJSON_GetObjectItemCaseSensitive(iIterator, "skipped");
|
cJSON *skp = cJSON_GetItem(iIterator, "skipped");
|
||||||
cJSON *rst = cJSON_GetObjectItemCaseSensitive(iIterator, "reset");
|
cJSON *rst = cJSON_GetItem(iIterator, "reset");
|
||||||
|
|
||||||
t.realtimeMS = ms->valueint;
|
t.ms = rms->valueint;
|
||||||
if (cJSON_IsTrue(skp))
|
if (cJSON_IsTrue(skp))
|
||||||
t.isSkipped = true;
|
t.isSkipped = true;
|
||||||
else
|
else
|
||||||
@ -420,7 +392,7 @@ void loadFile()
|
|||||||
else
|
else
|
||||||
t.isReset = false;
|
t.isReset = false;
|
||||||
|
|
||||||
runHistory[(oI * segmentCount) + iI] = t;
|
pastRuns[(oI * segCount) + iI] = t;
|
||||||
iI++;
|
iI++;
|
||||||
}
|
}
|
||||||
oI++;
|
oI++;
|
||||||
@ -436,37 +408,37 @@ void importSplitsIO(cJSON *splitfile)
|
|||||||
cJSON *game = NULL;
|
cJSON *game = NULL;
|
||||||
cJSON *cate = NULL;
|
cJSON *cate = NULL;
|
||||||
cJSON *segs = NULL;
|
cJSON *segs = NULL;
|
||||||
game = cJSON_GetObjectItemCaseSensitive(splitfile, "game");
|
game = cJSON_GetItem(splitfile, "game");
|
||||||
cate = cJSON_GetObjectItemCaseSensitive(splitfile, "category");
|
cate = cJSON_GetItem(splitfile, "category");
|
||||||
segs = cJSON_GetObjectItemCaseSensitive(splitfile, "segments");
|
segs = cJSON_GetItem(splitfile, "segments");
|
||||||
|
|
||||||
if (game) {
|
if (game) {
|
||||||
cJSON *title = cJSON_GetObjectItemCaseSensitive(game, "longname");
|
cJSON *title = cJSON_GetItem(game, "longname");
|
||||||
if (cJSON_IsString(title) && (title->valuestring != NULL)) {
|
if (cJSON_IsString(title) && (title->valuestring != NULL)) {
|
||||||
gameTitle = malloc(strlen(title->valuestring));
|
gameTitle = malloc(strlen(title->valuestring));
|
||||||
strcpy(gameTitle, title->valuestring);
|
strcpy(gameTitle, title->valuestring);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cate) {
|
if (cate) {
|
||||||
cJSON *title = cJSON_GetObjectItemCaseSensitive(cate, "longname");
|
cJSON *title = cJSON_GetItem(cate, "longname");
|
||||||
if (cJSON_IsString(title) && (title->valuestring != NULL)) {
|
if (cJSON_IsString(title) && (title->valuestring != NULL)) {
|
||||||
categoryTitle = malloc(strlen(title->valuestring));
|
categoryTitle = malloc(strlen(title->valuestring));
|
||||||
strcpy(categoryTitle, title->valuestring);
|
strcpy(categoryTitle, title->valuestring);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (segs) {
|
if (segs) {
|
||||||
segmentCount = cJSON_GetArraySize(segs);
|
segCount = cJSON_GetArraySize(segs);
|
||||||
segments = calloc(segmentCount, sizeof(struct segment));
|
segments = calloc(segCount, sizeof(struct segment));
|
||||||
pbrun = calloc(segmentCount, sizeof(struct segment));
|
pbrun = calloc(segCount, sizeof(struct segment));
|
||||||
wrrun = calloc(segmentCount, sizeof(struct segment));
|
wrrun = calloc(segCount, sizeof(struct segment));
|
||||||
bestsegs = calloc(segmentCount, sizeof(struct segment));
|
bestsegs = calloc(segCount, sizeof(struct segment));
|
||||||
|
|
||||||
cJSON *segname = NULL;
|
cJSON *segname = NULL;
|
||||||
|
|
||||||
int it = 0;
|
int it = 0;
|
||||||
cJSON *iterator = NULL;
|
cJSON *iterator = NULL;
|
||||||
cJSON_ArrayForEach(iterator, segs) {
|
cJSON_ArrayForEach(iterator, segs) {
|
||||||
segname = cJSON_GetObjectItemCaseSensitive(iterator, "name");
|
segname = cJSON_GetItem(iterator, "name");
|
||||||
if (cJSON_IsString(segname) && (segname->valuestring != NULL)) {
|
if (cJSON_IsString(segname) && (segname->valuestring != NULL)) {
|
||||||
segments[it].name = malloc(strlen(segname->valuestring));
|
segments[it].name = malloc(strlen(segname->valuestring));
|
||||||
strcpy(segments[it].name, segname->valuestring);
|
strcpy(segments[it].name, segname->valuestring);
|
||||||
@ -477,8 +449,6 @@ void importSplitsIO(cJSON *splitfile)
|
|||||||
cJSON_Delete(splitfile);
|
cJSON_Delete(splitfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: This function should check to see if the timer is currently running,
|
|
||||||
//because it runs when the program closes and the run might still be in progress
|
|
||||||
void saveFile()
|
void saveFile()
|
||||||
{
|
{
|
||||||
if (timerActive)
|
if (timerActive)
|
||||||
@ -504,7 +474,7 @@ void saveFile()
|
|||||||
cJSON_AddItemToObject(splitfile, "category", cate);
|
cJSON_AddItemToObject(splitfile, "category", cate);
|
||||||
cJSON_AddItemToObject(splitfile, "attempts", atts);
|
cJSON_AddItemToObject(splitfile, "attempts", atts);
|
||||||
|
|
||||||
for(int i = 0; i < segmentCount; i++) {
|
for(int i = 0; i < segCount; i++) {
|
||||||
cJSON *seg = cJSON_CreateObject();
|
cJSON *seg = cJSON_CreateObject();
|
||||||
cJSON *segn = cJSON_CreateString(segments[i].name);
|
cJSON *segn = cJSON_CreateString(segments[i].name);
|
||||||
cJSON_AddItemToObject(seg, "name", segn);
|
cJSON_AddItemToObject(seg, "name", segn);
|
||||||
@ -514,15 +484,15 @@ void saveFile()
|
|||||||
|
|
||||||
for (int i = 0; i < attempts; i++) {
|
for (int i = 0; i < attempts; i++) {
|
||||||
cJSON *run = cJSON_CreateArray();
|
cJSON *run = cJSON_CreateArray();
|
||||||
for (int j = 0; j < segmentCount; j++) {
|
for (int j = 0; j < segCount; j++) {
|
||||||
struct pastseg t = runHistory[(i * segmentCount) + j];
|
struct pastseg t = pastRuns[(i * segCount) + j];
|
||||||
cJSON *seg = cJSON_CreateObject();
|
cJSON *seg = cJSON_CreateObject();
|
||||||
|
|
||||||
cJSON *tim = cJSON_CreateNumber(t.realtimeMS);
|
cJSON *tim = cJSON_CreateNumber(t.ms);
|
||||||
cJSON *skp = cJSON_CreateBool(t.isSkipped);
|
cJSON *skp = cJSON_CreateBool(t.isSkipped);
|
||||||
cJSON *rst = cJSON_CreateBool(t.isReset);
|
cJSON *rst = cJSON_CreateBool(t.isReset);
|
||||||
|
|
||||||
cJSON_AddItemToObject(seg, "ms", tim);
|
cJSON_AddItemToObject(seg, "rms", tim);
|
||||||
cJSON_AddItemToObject(seg, "skipped", skp);
|
cJSON_AddItemToObject(seg, "skipped", skp);
|
||||||
cJSON_AddItemToObject(seg, "reset", rst);
|
cJSON_AddItemToObject(seg, "reset", rst);
|
||||||
|
|
||||||
@ -568,8 +538,6 @@ int main(int argc, char **argv)
|
|||||||
close(pipefd[1]);
|
close(pipefd[1]);
|
||||||
signal(SIGWINCH, resize);
|
signal(SIGWINCH, resize);
|
||||||
resize(0);
|
resize(0);
|
||||||
struct color bg = { 47, 53, 66};
|
|
||||||
struct color fg = {247, 248, 242};
|
|
||||||
initScreen(bg, fg);
|
initScreen(bg, fg);
|
||||||
loadFile();
|
loadFile();
|
||||||
while(!handleInput()) {
|
while(!handleInput()) {
|
@ -19,20 +19,19 @@
|
|||||||
#include "cJSON.h"
|
#include "cJSON.h"
|
||||||
|
|
||||||
#define NS_PER_S 1000000000
|
#define NS_PER_S 1000000000
|
||||||
|
#define cJSON_GetItem(x, y) cJSON_GetObjectItemCaseSensitive(x, y)
|
||||||
|
|
||||||
struct segment
|
struct segment
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
int realtimeMS;
|
int ms;
|
||||||
//int gametimeMS;
|
|
||||||
bool isSkipped;
|
bool isSkipped;
|
||||||
bool isReset;
|
bool isReset;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pastseg
|
struct pastseg
|
||||||
{
|
{
|
||||||
int realtimeMS;
|
int ms;
|
||||||
//int gametimeMS;
|
|
||||||
bool isSkipped;
|
bool isSkipped;
|
||||||
bool isReset;
|
bool isReset;
|
||||||
};
|
};
|
||||||
@ -43,6 +42,7 @@ void start();
|
|||||||
void stop();
|
void stop();
|
||||||
void split();
|
void split();
|
||||||
void tpause();
|
void tpause();
|
||||||
|
void unsplit();
|
||||||
void reset();
|
void reset();
|
||||||
void loadKeymap();
|
void loadKeymap();
|
||||||
void ftime(char *timestr, bool withMS, int ms);
|
void ftime(char *timestr, bool withMS, int ms);
|
Loading…
Reference in New Issue
Block a user