|
|
@ -6,10 +6,12 @@ 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
|
|
|
@ -30,9 +32,9 @@ 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -291,18 +261,20 @@ void calculatePB()
|
|
|
|
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()) {
|