-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
511e695
commit 8304df7
Showing
21 changed files
with
501 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"paths": { | ||
"texturepack": "assets", | ||
"worlds": "saves" | ||
}, | ||
"input": { | ||
"player_forward": [0, 200], | ||
"player_backward": [1, 201], | ||
"player_left": [2, 202], | ||
"player_right": [3, 203], | ||
"player_jump": [5, 205], | ||
"player_sneak": [204], | ||
"item_action_left": [6, 100, 210], | ||
"item_action_right": [7, 101, 211], | ||
"scroll_left": [9, 208], | ||
"scroll_right": [8, 209], | ||
"inventory": [4, 206], | ||
"open_menu": [10, 214] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"paths": { | ||
"texturepack": "assets", | ||
"worlds": "saves" | ||
}, | ||
"input": { | ||
"player_forward": [87], | ||
"player_backward": [83], | ||
"player_left": [65], | ||
"player_right": [68], | ||
"player_jump": [32], | ||
"player_sneak": [340], | ||
"item_action_left": [1000], | ||
"item_action_right": [1001], | ||
"scroll_left": [], | ||
"scroll_right": [], | ||
"inventory": [69], | ||
"open_menu": [257] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <assert.h> | ||
|
||
#include "config.h" | ||
|
||
bool config_create(struct config* c, const char* filename) { | ||
assert(c && filename); | ||
c->root = json_parse_file(filename); | ||
|
||
if(!c->root) | ||
return false; | ||
|
||
if(json_value_get_type(c->root) != JSONObject) { | ||
config_destroy(c); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
const char* config_read_string(struct config* c, const char* key, | ||
const char* fallback) { | ||
assert(c && key); | ||
// TODO: only give out copy | ||
const char* res = json_object_dotget_string(json_object(c->root), key); | ||
return res ? res : fallback; | ||
} | ||
|
||
bool config_read_int_array(struct config* c, const char* key, int* dest, | ||
size_t* length) { | ||
assert(c && key && dest); | ||
|
||
JSON_Array* entry = json_object_dotget_array(json_object(c->root), key); | ||
|
||
if(!entry) | ||
return false; | ||
|
||
*length = *length < json_array_get_count(entry) ? | ||
*length : | ||
json_array_get_count(entry); | ||
|
||
for(size_t k = 0; k < *length; k++) | ||
dest[k] = json_array_get_number(entry, k); | ||
|
||
return true; | ||
} | ||
|
||
void config_destroy(struct config* c) { | ||
assert(c && c->root); | ||
json_value_free(c->root); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef CONFIG_H | ||
#define CONFIG_H | ||
|
||
#include <stdbool.h> | ||
|
||
#include "parson/parson.h" | ||
|
||
struct config { | ||
JSON_Value* root; | ||
}; | ||
|
||
bool config_create(struct config* c, const char* filename); | ||
const char* config_read_string(struct config* c, const char* key, | ||
const char* fallback); | ||
bool config_read_int_array(struct config* c, const char* key, int* dest, | ||
size_t* length); | ||
void config_destroy(struct config* c); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.