add inv saving, fix bugs
This commit is contained in:
parent
4bef1a220c
commit
d5e55b54ee
5 changed files with 26 additions and 10 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
/bin/elem
|
/bin/elem
|
||||||
/bin/elem.exe
|
/bin/elem.exe
|
||||||
|
/inv.txt
|
|
@ -26,7 +26,7 @@ int load_elements(hashmap *m, char *table, int use_inv) {
|
||||||
did_something = 1;
|
did_something = 1;
|
||||||
|
|
||||||
if (use_inv) {
|
if (use_inv) {
|
||||||
hashmap_set(m, str, strlen(str) - 2, (uintptr_t)1);
|
hashmap_set(m, str, strlen(str) - 1, (uintptr_t)1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,13 +37,12 @@ int load_elements(hashmap *m, char *table, int use_inv) {
|
||||||
hashmap_set(m, combo, strlen(combo) - 1, (uintptr_t)str);
|
hashmap_set(m, combo, strlen(combo) - 1, (uintptr_t)str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
printf("%i\n",did_something);
|
|
||||||
|
|
||||||
if (!did_something) {
|
if (!did_something) {
|
||||||
free(str);
|
free(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fclose(fptr);
|
||||||
|
|
||||||
return did_something;
|
return did_something;
|
||||||
|
|
||||||
// todo: properly free this
|
// todo: properly free this
|
||||||
|
|
26
src/main.c
26
src/main.c
|
@ -5,6 +5,10 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#define inv_file "inv.txt"
|
||||||
|
#define inv_base_file "inv_base.txt"
|
||||||
|
#define combo_file "combos.txt"
|
||||||
|
|
||||||
#define MAX_BUF_LENGTH 1024
|
#define MAX_BUF_LENGTH 1024
|
||||||
#define MAX_COMBO_LENGTH 1024
|
#define MAX_COMBO_LENGTH 1024
|
||||||
|
|
||||||
|
@ -16,9 +20,12 @@ int main(int argc, char *argv[]) {
|
||||||
char *command_re = calloc(MAX_BUF_LENGTH, sizeof(char));
|
char *command_re = calloc(MAX_BUF_LENGTH, sizeof(char));
|
||||||
char **sort_tmp = calloc(MAX_COMBO_LENGTH, sizeof(char **));
|
char **sort_tmp = calloc(MAX_COMBO_LENGTH, sizeof(char **));
|
||||||
|
|
||||||
load_elements(elements, "combos.txt", 0) ||
|
load_elements(elements, combo_file, 0) ||
|
||||||
load_elements(elements, "bin/combos.txt", 0);
|
load_elements(elements, "bin/" combo_file, 0);
|
||||||
load_elements(inv, "inv.txt", 1) || load_elements(inv, "bin/inv.txt", 1);
|
load_elements(inv, inv_base_file, 1) ||
|
||||||
|
load_elements(inv, "bin/" inv_base_file, 1);
|
||||||
|
|
||||||
|
load_elements(inv, inv_file, 1);
|
||||||
|
|
||||||
printf("Welcome to Elemental on Command Line!\n");
|
printf("Welcome to Elemental on Command Line!\n");
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -35,7 +42,7 @@ int main(int argc, char *argv[]) {
|
||||||
int failed = 0;
|
int failed = 0;
|
||||||
for (int i = 0; i < combos; i++) {
|
for (int i = 0; i < combos; i++) {
|
||||||
uintptr_t result;
|
uintptr_t result;
|
||||||
hashmap_get(inv, sort_tmp[i], strlen(sort_tmp[i]) - 1, &result);
|
hashmap_get(inv, sort_tmp[i], strlen(sort_tmp[i]), &result);
|
||||||
if (result != 1) {
|
if (result != 1) {
|
||||||
printf("You don't have %s.\n", sort_tmp[i]);
|
printf("You don't have %s.\n", sort_tmp[i]);
|
||||||
failed = 1;
|
failed = 1;
|
||||||
|
@ -56,8 +63,17 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
char *res_str = (char *)result;
|
char *res_str = (char *)result;
|
||||||
|
|
||||||
hashmap_set(inv, res_str, strlen(res_str) - 1, (uintptr_t)1);
|
hashmap_set(inv, res_str, strlen(res_str), (uintptr_t)1);
|
||||||
printf("You made %s!\n", res_str);
|
printf("You made %s!\n", res_str);
|
||||||
|
|
||||||
|
FILE *fptr;
|
||||||
|
|
||||||
|
fptr = fopen(inv_file, "a");
|
||||||
|
if (fptr == NULL)
|
||||||
|
continue;
|
||||||
|
fwrite("\n",sizeof(char),1,fptr);
|
||||||
|
fwrite(res_str, sizeof(char), strlen(res_str), fptr);
|
||||||
|
fclose(fptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// free(command);
|
// free(command);
|
||||||
|
|
0
src/writer.c
Normal file
0
src/writer.c
Normal file
Loading…
Reference in a new issue