most config fixed, still need to do a bunch more testing

This commit is contained in:
herbglitch 2023-01-20 22:38:29 -07:00
parent 2b2e40921d
commit 5e6ee54473
7 changed files with 730 additions and 424 deletions

View file

@ -19,28 +19,28 @@
SDL_Renderer *global_renderer;
int32_t ARC_Point_Read (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
int32_t ARC_Rect_Read (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
int32_t ARC_RectArray_Read (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
int32_t ARC_SDL_Texture_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
int32_t ARC_Spritesheet_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
int32_t ARC_Sprite_Read (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
uint8_t ARC_Point_Read (ARC_Config *config, ARC_String *string, void **value);
uint8_t ARC_Rect_Read (ARC_Config *config, ARC_String *string, void **value);
uint8_t ARC_RectArray_Read (ARC_Config *config, ARC_String *string, void **value);
uint8_t ARC_SDL_Texture_Read(ARC_Config *config, ARC_String *string, void **value);
uint8_t ARC_Spritesheet_Read(ARC_Config *config, ARC_String *string, void **value);
uint8_t ARC_Sprite_Read (ARC_Config *config, ARC_String *string, void **value);
int32_t ARC_Point_Delete (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
int32_t ARC_Rect_Delete (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
int32_t ARC_RectArray_Delete (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
int32_t ARC_SDL_Texture_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
int32_t ARC_Spritesheet_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
int32_t ARC_Sprite_Delete (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
void ARC_Point_Delete (ARC_Config *config, ARC_String *string, void *value);
void ARC_Rect_Delete (ARC_Config *config, ARC_String *string, void *value);
void ARC_RectArray_Delete (ARC_Config *config, ARC_String *string, void *value);
void ARC_SDL_Texture_Delete(ARC_Config *config, ARC_String *string, void *value);
void ARC_Spritesheet_Delete(ARC_Config *config, ARC_String *string, void *value);
void ARC_Sprite_Delete (ARC_Config *config, ARC_String *string, void *value);
void ARC_GraphicsConfig_Init(ARC_Config *config, ARC_Renderer *renderer){
global_renderer = renderer->renderer;
ARC_ConfigKey_Add(config, (char *)"ARC_Point" , (ARC_ConfigKeyRead) ARC_Point_Read , (ARC_ConfigKeyDelete) ARC_Point_Delete );
ARC_ConfigKey_Add(config, (char *)"ARC_Rect" , (ARC_ConfigKeyRead) ARC_Rect_Read , (ARC_ConfigKeyDelete) ARC_Rect_Delete );
ARC_ConfigKey_Add(config, (char *)"ARC_Rect[]" , (ARC_ConfigKeyRead) ARC_RectArray_Read , (ARC_ConfigKeyDelete) ARC_RectArray_Delete );
ARC_ConfigKey_Add(config, (char *)"SDL_Texture" , (ARC_ConfigKeyRead) ARC_SDL_Texture_Read, (ARC_ConfigKeyDelete) ARC_SDL_Texture_Delete);
ARC_ConfigKey_Add(config, (char *)"ARC_Spritesheet", (ARC_ConfigKeyRead) ARC_Spritesheet_Read, (ARC_ConfigKeyDelete) ARC_Spritesheet_Delete);
ARC_ConfigKey_Add(config, (char *)"ARC_Sprite" , (ARC_ConfigKeyRead) ARC_Sprite_Read , (ARC_ConfigKeyDelete) ARC_Sprite_Delete );
ARC_Config_AddKeyCString(config, (char *)"ARC_Point" , 9, ARC_Point_Read , ARC_Point_Delete );
ARC_Config_AddKeyCString(config, (char *)"ARC_Rect" , 8, ARC_Rect_Read , ARC_Rect_Delete );
ARC_Config_AddKeyCString(config, (char *)"ARC_Rect[]" , 10, ARC_RectArray_Read , ARC_RectArray_Delete );
ARC_Config_AddKeyCString(config, (char *)"SDL_Texture" , 11, ARC_SDL_Texture_Read, ARC_SDL_Texture_Delete);
ARC_Config_AddKeyCString(config, (char *)"ARC_Spritesheet", 15, ARC_Spritesheet_Read, ARC_Spritesheet_Delete);
ARC_Config_AddKeyCString(config, (char *)"ARC_Sprite" , 10, ARC_Sprite_Read , ARC_Sprite_Delete );
}
int32_t ARC_SDL_Texture_Load(const char *path, SDL_Texture **texture){
@ -59,100 +59,209 @@ int32_t ARC_SDL_Texture_Load(const char *path, SDL_Texture **texture){
return 0;
}
int32_t ARC_Point_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value){
ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata);
if(data[subdata->index] != '{' || data[subdata->index + subdata->length - 1] != '}'){ return ARC_ERRNO_DATA; }
subdata->index++;
subdata->length -= 2;
uint64_t getIndexAndErrorCheck(ARC_String *string, char *search, uint64_t searchLength){
uint64_t separator = ARC_String_FindCString(string, ",", 1);
uint64_t split;
*value = malloc(sizeof(ARC_Rect));
if(separator == ~(uint64_t)0){
arc_errno = ARC_ERRNO_DATA;
}
//x
int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split);
if(err){ return err; }
if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; }
ARC_StringSubstr temp = { subdata->index, split };
((SDL_Point *) *value)->x = (int)ARC_String_ToUint64_t(data, &temp);
return separator;
}
//y
temp = (ARC_StringSubstr){ temp.index + split + 1, subdata->length - split - 1 };
((SDL_Point *) *value)->y = (int)ARC_String_ToUint64_t(data, &temp);
uint8_t ARC_Point_Read(ARC_Config *config, ARC_String *string, void **value){
ARC_Config_Get(config, string, value);
if(*value){
return 1;
}
if(string->data[0] != '{' || string->data[string->length - 1] != '}'){
arc_errno = ARC_ERRNO_DATA;
return 0;
}
uint64_t separator = getIndexAndErrorCheck(string, ",", 1);
if(arc_errno){
return 0;
}
ARC_String *xString, *yString;
ARC_String_CopySubstring(&xString, string, 1 , separator - 1 );
ARC_String_CopySubstring(&yString, string, separator + 1, string->length - (separator + 2));
SDL_Point *point = (SDL_Point *)malloc(sizeof(SDL_Point));
point->x = (int32_t)ARC_String_ToInt64_t(xString);
point->y = (int32_t)ARC_String_ToInt64_t(yString);
ARC_String_Destroy(xString);
ARC_String_Destroy(yString);
*value = point;
return 0;
}
int32_t ARC_Rect_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value){
ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata);
if(data[subdata->index] != '{' || data[subdata->index + subdata->length - 1] != '}'){ return ARC_ERRNO_DATA; }
subdata->index++;
subdata->length -= 2;
uint8_t ARC_Rect_Read(ARC_Config *config, ARC_String *string, void **value){
ARC_Config_Get(config, string, value);
if(*value){
return 1;
}
uint64_t split;
*value = malloc(sizeof(ARC_Rect));
if(string->data[0] != '{' || string->data[string->length - 1] != '}'){
arc_errno = ARC_ERRNO_DATA;
return 0;
}
ARC_String *current;
ARC_String_CopySubstring(&current, string, 1, string->length - 2);
ARC_String *temp, *tempStripped;
int32_t x, y, w, h;
int64_t separator;
//x
int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split);
if(err){ return err; }
if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; }
ARC_StringSubstr temp = { subdata->index, split };
((ARC_Rect *) *value)->x = (int)ARC_String_ToUint64_t(data, &temp);
int32_t ttt = ((ARC_Rect *) *value)->x;
separator = getIndexAndErrorCheck(current, ",", 1);
if(arc_errno){
return 0;
}
ARC_String_CopySubstring(&temp, current, 0, separator - 1);
ARC_String_StripEndsWhitespace(temp, &tempStripped);
x = ARC_String_ToInt64_t(tempStripped);
ARC_String_Destroy(temp);
ARC_String_Destroy(tempStripped);
temp = current;
ARC_String_CopySubstring(&current, temp, separator + 1, temp->length - (separator + 1));
ARC_String_Destroy(temp);
//y
temp.index = subdata->index + split + 1;
err = ARC_String_Find(((char *)data) + temp.index, (char *)",", &split);
if(err){ return err; }
if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; }
temp.length = split;
((ARC_Rect *) *value)->y = (int)ARC_String_ToUint64_t(data, &temp);
ttt = ((ARC_Rect *) *value)->y;
separator = getIndexAndErrorCheck(current, ",", 1);
if(arc_errno){
return 0;
}
ARC_String_CopySubstring(&temp, current, 0, separator - 1);
ARC_String_StripEndsWhitespace(temp, &tempStripped);
y = ARC_String_ToInt64_t(tempStripped);
ARC_String_Destroy(temp);
ARC_String_Destroy(tempStripped);
temp = current;
ARC_String_CopySubstring(&current, temp, separator + 1, temp->length - (separator + 1));
ARC_String_Destroy(temp);
//w
temp.index = temp.index + split + 1;
err = ARC_String_Find(((char *)data) + temp.index, (char *)",", &split);
if(err){ return err; }
if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; }
temp.length = split;
((ARC_Rect *) *value)->w = (int)ARC_String_ToUint64_t(data, &temp);
ttt = ((ARC_Rect *) *value)->w;
separator = getIndexAndErrorCheck(current, ",", 1);
if(arc_errno){
return 0;
}
ARC_String_CopySubstring(&temp, current, 0, separator - 1);
ARC_String_StripEndsWhitespace(temp, &tempStripped);
w = ARC_String_ToInt64_t(tempStripped);
ARC_String_Destroy(temp);
ARC_String_Destroy(tempStripped);
temp = current;
ARC_String_CopySubstring(&current, temp, separator + 1, temp->length - (separator + 1));
ARC_String_Destroy(temp);
//h
temp = (ARC_StringSubstr){ temp.index + split + 1, subdata->length - split - 1 };
((ARC_Rect *) *value)->h = (int)ARC_String_ToUint64_t(data, &temp);
ttt = ((ARC_Rect *) *value)->h;
separator = current->length;
if(arc_errno){
return 0;
}
ARC_String_CopySubstring(&temp, current, 0, separator);
ARC_String_StripEndsWhitespace(temp, &tempStripped);
h = ARC_String_ToInt64_t(tempStripped);
ARC_String_Destroy(temp);
ARC_String_Destroy(tempStripped);
ARC_String_Destroy(current);
*value = malloc(sizeof(ARC_Rect));
((ARC_Rect *) *value)->x = x;
((ARC_Rect *) *value)->y = y;
((ARC_Rect *) *value)->w = w;
((ARC_Rect *) *value)->h = h;
return 0;
}
int32_t ARC_RectArray_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value){
ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata);
if(data[subdata->index] != '{' || data[subdata->index + subdata->length - 1] != '}'){ return ARC_ERRNO_DATA; }
subdata->index++;
subdata->length -= 2;
void ARC_RectArray_ReadRect(ARC_Config* config, ARC_String *stripped, uint64_t index, uint64_t length, uint64_t *arrayIndex, void **value){
ARC_String *substr, *temp;
ARC_String_CopySubstring(&temp, stripped, index, length);
ARC_String_StripEndsWhitespace(temp, &substr);
ARC_String_Destroy(temp);
uint32_t arraySize = 1;
int32_t encapsulated = 0;
for(uint32_t i = subdata->index; i < subdata->index + subdata->length; i++){
if(data[i] == '{'){
// reading in reference
ARC_Rect *tempRect;
ARC_Config_Get(config, substr, (void **) &tempRect);
if(tempRect){
ARC_String_Destroy(substr);
((ARC_Rect *)((ARC_Array *) *value)->data)[*arrayIndex] = *tempRect;
++*arrayIndex;
return;
}
//reading in value
ARC_Rect_Read(config, substr, (void **) &tempRect);
if(arc_errno){
ARC_String_Destroy(substr);
ARC_String_Destroy(stripped);
return;
}
((ARC_Rect *)((ARC_Array *) *value)->data)[*arrayIndex] = *tempRect;
++*arrayIndex;
ARC_Rect_Delete(config, substr, (void *)tempRect);
ARC_String_Destroy(substr);
if(arc_errno){
return;
}
}
uint8_t ARC_RectArray_Read(ARC_Config* config, ARC_String *string, void **value){
ARC_Config_Get(config, string, value);
if(*value){
return 1;
}
if(string->data[0] != '{' || string->data[string->length - 1] != '}'){
arc_errno = ARC_ERRNO_DATA;
return 0;
}
ARC_String *temp, *stripped;
ARC_String_CopySubstring(&temp, string, 1, string->length - 2);
ARC_String_StripEndsWhitespace(temp, &stripped);
ARC_String_Destroy(temp);
uint64_t arraySize = 1;
int64_t encapsulated = 0;
for(uint64_t i = 0; i < stripped->length; i++){
if(stripped->data[i] == '{'){
encapsulated++;
continue;
}
if(data[i] == '}'){
if(stripped->data[i] == '}'){
encapsulated--;
continue;
}
if(!encapsulated && data[i] == ','){
if(!encapsulated && stripped->data[i] == ','){
arraySize++;
}
}
if(encapsulated){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG(arc_errno, "in ARC_RectArray_Read(config, data, subdata, value); after looping encapsulated was %d", encapsulated);
return arc_errno;
ARC_DEBUG_LOG(arc_errno, "in ARC_RectArray_Read(config, data, subdata, value); after looping encapsulated was %ld", encapsulated);
ARC_String_Destroy(stripped);
return 0;
}
*value = malloc(sizeof(ARC_Array));
@ -160,286 +269,285 @@ int32_t ARC_RectArray_Read(ARC_Config* config, const char *data, ARC_StringSubst
((ARC_Array *) *value)->size = malloc(sizeof(uint32_t));
*((ARC_Array *) *value)->size = arraySize;
ARC_StringSubstr temp = { subdata->index, 0 };
uint64_t index = 0;
arraySize = 0;
encapsulated = 0;
for(uint64_t i = subdata->index; i < subdata->index + subdata->length; i++){
if(data[i] == '{'){
for(uint64_t i = 0; i < stripped->length; i++){
if(stripped->data[i] == '{'){
encapsulated++;
continue;
}
if(data[i] == '}'){
if(stripped->data[i] == '}'){
encapsulated--;
continue;
}
if(!encapsulated && data[i] == ','){
temp.length = i - temp.index;
ARC_Rect *tempRect = (ARC_Rect *)ARC_Config_GetReference(config, (char *)data, &temp);
if(!tempRect){
ARC_Rect_Read(config, data, &temp, (void **) &tempRect);
if(arc_errno){
return arc_errno;
}
}
((ARC_Rect *)((ARC_Array *) *value)->data)[arraySize] = *tempRect;
ARC_Rect_Delete(config, data, &temp, (void *)tempRect);
if(!encapsulated && stripped->data[i] == ','){
ARC_RectArray_ReadRect(config, stripped, index, i - index, &arraySize, value);
if(arc_errno){
return arc_errno;
return 0;
}
arraySize++;
temp = (ARC_StringSubstr){ i + 1, 0 };
index = i;
if(arraySize == *((ARC_Array *) *value)->size){
break;
}
}
}
temp.length = (subdata->index + subdata->length) - temp.index;
ARC_Rect *tempRect = (ARC_Rect *)ARC_Config_GetReference(config, (char *)data, &temp);
if(!tempRect){
int32_t ttt = ARC_Rect_Read(config, data, &temp, (void **) &tempRect);
if(arc_errno){
return arc_errno;
}
}
((ARC_Rect *)((ARC_Array *) *value)->data)[arraySize] = *tempRect;
ARC_Rect ttt = ((ARC_Rect *)((ARC_Array *) *value)->data)[arraySize];
ARC_Rect_Delete(config, data, &temp, (void *)tempRect);
if(arc_errno){
return arc_errno;
}
ARC_RectArray_ReadRect(config, stripped, index, stripped->length - index, &arraySize, value);
ARC_String_Destroy(stripped);
return 0;
}
int32_t ARC_SDL_Texture_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value){
ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata);
ARC_StringSubstr_StripEnds((char *)data, (char *)"\"", subdata);
char path[subdata->length + 1];
strncpy(path, data + subdata->index, subdata->length);
path[subdata->length] = 0;
uint8_t ARC_SDL_Texture_Read(ARC_Config* config, ARC_String *string, void **value){
ARC_Config_Get(config, string, value);
if(*value){
return 1;
}
return ARC_SDL_Texture_Load(path, (SDL_Texture **)value);
ARC_String *tempStr, *textureStr;
ARC_String_StripEndsWhitespace(string, &tempStr);
ARC_String_CopySubstring(&textureStr, tempStr, 1, tempStr->length - 2);
ARC_String_Destroy(tempStr);
ARC_SDL_Texture_Load(textureStr->data, (SDL_Texture **)value);
ARC_String_Destroy(textureStr);
return 0;
}
int32_t ARC_Spritesheet_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value){
ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata);
if(data[subdata->index] != '{'){
SDL_Texture *texture = (SDL_Texture *)ARC_Config_GetReference(config, (char *)data, subdata);
if(!texture && data[subdata->index] != '"'){ return ARC_ERRNO_DATA; }
void ARC_Spritesheet_ReadTexture(ARC_Config *config, ARC_String *string, uint32_t *size, void **value){
SDL_Texture *texture;
if(!texture){
int32_t err = ARC_SDL_Texture_Read(config, data, subdata, (void **)&texture);
if(err){ return ARC_ERRNO_DATA; }
}
ARC_String *tempStr, *textureStr;
ARC_String_StripEndsWhitespace(string, &tempStr);
*value = malloc(sizeof(ARC_Spritesheet));
((ARC_Spritesheet *) *value)->texture = texture;
((ARC_Spritesheet *) *value)->size = NULL;
return 0;
//check for reference
ARC_Config_Get(config, tempStr, (void **)&texture);
if(!texture && (tempStr->data[0] != '"' || tempStr->data[string->length - 1] != '"')){
arc_errno = ARC_ERRNO_DATA;
}
if(data[subdata->index + subdata->length - 1] != '}'){ return ARC_ERRNO_DATA; }
subdata->index++;
subdata->length -= 2; //remove the starting { and ending }
//Texture
uint64_t split;
int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split);
if(err){ return err; }
if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; }
ARC_StringSubstr temp = { subdata->index, split };
ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp);
SDL_Texture *texture = (SDL_Texture *)ARC_Config_GetReference(config, (char *)data, &temp);
if(!texture && data[temp.index] != '"'){ return ARC_ERRNO_DATA; }
ARC_String_CopySubstring(&textureStr, tempStr, 1, tempStr->length - 2);
ARC_String_Destroy(tempStr);
//try reading in the texture
if(!texture){
err = ARC_SDL_Texture_Read(config, data, &temp, (void **)&texture);
if(err){ return ARC_ERRNO_DATA; }
ARC_SDL_Texture_Read(config, string, (void **)&texture);
if(arc_errno){
*value = NULL;
}
}
//uint32_t size
temp = (ARC_StringSubstr){ subdata->index + split + 1, subdata->length - split - 1 };
ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp);
uint32_t *size = (uint32_t *)ARC_Config_GetReference(config, (char *)data, &temp);
if(!size){
ARC_ConfigKey_Read_Uint64_t(config, data, &temp, (void **)&size);
if(err){ return ARC_ERRNO_DATA; }
}
ARC_String_Destroy(textureStr);
*value = malloc(sizeof(ARC_Spritesheet));
((ARC_Spritesheet *) *value)->texture = texture;
((ARC_Spritesheet *) *value)->size = size;
}
uint8_t ARC_Spritesheet_Read(ARC_Config* config, ARC_String *string, void **value){
if(string->data[0] != '{' || string->data[string->length - 1] != '}'){
ARC_Spritesheet_ReadTexture(config, string, NULL, value);
return 0;
}
uint64_t split = getIndexAndErrorCheck(string, ",", 1);
if(arc_errno){
return 0;
}
ARC_String *temp, *textureStr, *sizeStr;
ARC_String_CopySubstring(&temp, string, 1, split - 1);
ARC_String_StripEndsWhitespace(temp, &textureStr);
ARC_String_Destroy(temp);
ARC_String_CopySubstring(&temp, string, split + 1, string->length - (split + 1));
ARC_String_StripEndsWhitespace(temp, &sizeStr);
ARC_String_Destroy(temp);
uint32_t *size;
ARC_Config_Get(config, string, (void **)&size);
if(!size){
ARC_ConfigKey_Read_Uint32_t(config, sizeStr, (void **)&size);
if(arc_errno){
ARC_String_Destroy(sizeStr);
ARC_String_Destroy(textureStr);
return ARC_ERRNO_DATA;
}
}
ARC_Spritesheet_ReadTexture(config, textureStr, size, value);
ARC_String_Destroy(sizeStr);
ARC_String_Destroy(textureStr);
return 0;
}
int32_t ARC_Sprite_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value){
ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata);
if(data[subdata->index] != '{' || data[subdata->index + subdata->length - 1] != '}'){ return ARC_ERRNO_DATA; }
subdata->index++;
subdata->length -= 2; //remove the starting { and ending }
uint8_t ARC_Sprite_Read(ARC_Config* config, ARC_String *string, void **value){
ARC_Config_Get(config, string, value);
if(*value){
return 1;
}
uint64_t split;
int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split);
if(err){ return err; }
if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; }
if(string->data[0] != '{' || string->data[string->length - 1] != '}'){
ARC_Spritesheet_ReadTexture(config, string, NULL, value);
return 0;
}
uint64_t split = getIndexAndErrorCheck(string, ",", 1);
if(arc_errno){
return 0;
}
ARC_String *temp, *spritesheetStr, *framesStr;
ARC_String_CopySubstring(&temp, string, 1, split - 2);
ARC_String_StripEndsWhitespace(temp, &spritesheetStr);
ARC_String_Destroy(temp);
ARC_String_CopySubstring(&temp, string, split + 1, string->length - (split + 2));
ARC_String_StripEndsWhitespace(temp, &framesStr);
ARC_String_Destroy(temp);
//spritesheet
ARC_StringSubstr temp = { subdata->index, split };
ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp);
ARC_Spritesheet *spritesheet = (ARC_Spritesheet *)ARC_Config_GetReference(config, (char *)data, &temp);
ARC_Spritesheet *spritesheet;
ARC_Config_Get(config, spritesheetStr, (void **)&spritesheet);
if(!spritesheet){
err = ARC_Spritesheet_Read(config, data, &temp, (void **)&spritesheet);
if(err){ return ARC_ERRNO_DATA; }
}
//bounds
uint8_t isRectArray = 0;
temp = (ARC_StringSubstr){ subdata->index + split + 1, subdata->length - split - 1 };
ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp);
ARC_Array *bounds = (ARC_Array *)ARC_Config_GetReference(config, (char *)data, &temp);
if(!bounds){
err = ARC_RectArray_Read(config, data, &temp, (void **)&bounds);
if(err){ return ARC_ERRNO_DATA; }
isRectArray = 1;
}
//scale bounds on spritesheet size
// TODO: possible bug for sheets that use the same bounds
if(spritesheet->size){
for(uint32_t i = 0; i < *bounds->size; i++){
((ARC_Rect *)bounds->data)[i].x *= *spritesheet->size;
((ARC_Rect *)bounds->data)[i].y *= *spritesheet->size;
((ARC_Rect *)bounds->data)[i].w *= *spritesheet->size;
((ARC_Rect *)bounds->data)[i].h *= *spritesheet->size;
ARC_Spritesheet_Read(config, spritesheetStr, (void **)&spritesheet);
if(arc_errno){
ARC_String_Destroy(spritesheetStr);
ARC_String_Destroy(framesStr );
return 0;
}
}
//bounds
ARC_Array *frames;
ARC_Config_Get(config, framesStr, (void **)&frames);
if(!frames){
ARC_RectArray_Read(config, framesStr, (void **)&frames);
if(arc_errno){
ARC_String_Destroy(spritesheetStr);
ARC_String_Destroy(framesStr );
return 0;
}
}
ARC_String_Destroy(spritesheetStr);
ARC_String_Destroy(framesStr );
//sprite
*value = malloc(sizeof(ARC_Sprite));
((ARC_Sprite *) *value)->frameIndex = malloc(sizeof(uint32_t));
((ARC_Sprite *) *value)->spritesheet = spritesheet;
((ARC_Sprite *) *value)->frames = bounds;
((ARC_Sprite *) *value)->frames = frames;
*((ARC_Sprite *) *value)->frameIndex = 0;
ARC_Rect *ttt = (ARC_Rect *)bounds->data;
ARC_Rect ttf = ttt[0];
if(isRectArray){
free(bounds);
return 0;
}
void ARC_Point_Delete(ARC_Config* config, ARC_String *string, void *value){
free((ARC_Point *)value);
}
void ARC_Rect_Delete(ARC_Config* config, ARC_String *string, void *value){
free((ARC_Rect *)value);
}
void ARC_RectArray_Delete(ARC_Config* config, ARC_String *string, void *value){
free((ARC_Array *)value);
}
void ARC_SDL_Texture_Delete(ARC_Config* config, ARC_String *string, void *value){
SDL_DestroyTexture((SDL_Texture *) value);
}
void ARC_Spritesheet_Delete(ARC_Config* config, ARC_String *string, void *value){
ARC_Spritesheet *sheetValue = (ARC_Spritesheet *)value;
//check if read in as a Textrue reference
void *temp;
ARC_Config_Get(config, string, &temp);
if(temp){
free(sheetValue);
return;
}
return 0;
}
int32_t ARC_Point_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){
if((ARC_Point *)value){ free((ARC_Point *)value); }
return 0;
}
int32_t ARC_Rect_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){
if((ARC_Rect *)value){ free((ARC_Rect *)value); }
return 0;
}
int32_t ARC_RectArray_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){
if((ARC_Array *)value){ free((ARC_Array *)value); }
return 0;
}
int32_t ARC_SDL_Texture_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){
//if((SDL_Texture *) value){ SDL_DestroyTexture((SDL_Texture *) value); }
return 0;
}
int32_t ARC_Spritesheet_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){
ARC_Spritesheet *spritesheet = (ARC_Spritesheet *) value;
if(!data){ //there is no data, kill everything, most likely was called by a data type being destroyed
free(spritesheet);
return 0;
uint64_t split = getIndexAndErrorCheck(string, ",", 1);
if(arc_errno){
free(sheetValue);
return;
}
ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata);
if(data[subdata->index] != '{'){
SDL_Texture *texture = (SDL_Texture *)ARC_Config_GetReference(config, (char *)data, subdata);
if(!texture){
ARC_SDL_Texture_Delete(config, data, subdata, (void *)spritesheet->texture);
}
//check if texture and size are references
ARC_String *tempStr, *textureStr, *sizeStr;
ARC_String_CopySubstring(&tempStr, string, 1, split - 1);
ARC_String_StripEndsWhitespace(tempStr, &textureStr);
ARC_String_Destroy(tempStr);
// if(spritesheet){
// free(spritesheet);
// }
ARC_String_CopySubstring(&tempStr, string, split + 1, string->length - (split + 1));
ARC_String_StripEndsWhitespace(tempStr, &sizeStr);
ARC_String_Destroy(tempStr);
return 0;
ARC_Config_Get(config, sizeStr, (void **)&temp);
ARC_String_Destroy(sizeStr);
if(temp){
free(sheetValue->size);
}
uint64_t split;
int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split);
if(err){ return err; }
if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; }
ARC_Config_Get(config, textureStr, (void **)&temp);
ARC_String_Destroy(textureStr);
if(temp){
free(sheetValue->size);
}
ARC_StringSubstr temp = { subdata->index, split };
ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp);
SDL_Texture *texture = (SDL_Texture *)ARC_Config_GetReference(config, (char *)data, &temp);
if(!texture){ ARC_SDL_Texture_Delete(config, data, &temp, (void *)spritesheet->texture); }
temp = (ARC_StringSubstr){ subdata->index + split + 1, subdata->length - split - 1 };
ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp);
uint32_t *size = (uint32_t *)ARC_Config_GetReference(config, (char *)data, &temp);
if(!size){ ARC_ConfigKey_Delete_Uint64_t(config, data, &temp, (void *)spritesheet->size); }
free(spritesheet);
return 0;
free(sheetValue);
}
int32_t ARC_Sprite_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){
ARC_Sprite *sprite = (ARC_Sprite *) value;
if(!data){
free(sprite);
return 0;
void ARC_Sprite_Delete(ARC_Config* config, ARC_String *string, void *value){
ARC_Sprite *spriteValue = (ARC_Sprite *)value;
//check if read in as a Textrue reference
void *temp;
uint64_t split = getIndexAndErrorCheck(string, ",", 1);
if(arc_errno){
free(spriteValue);
return;
}
ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata);
if(data[subdata->index] != '{' || data[subdata->index + subdata->length - 1] != '}'){ return ARC_ERRNO_DATA; }
subdata->index++;
subdata->length -= 2; //remove the starting { and ending }
//check if texture and size are references
ARC_String *tempStr, *spritesheetStr, *framesStr;
ARC_String_CopySubstring(&tempStr, string, 1, split - 1);
ARC_String_StripEndsWhitespace(tempStr, &spritesheetStr);
ARC_String_Destroy(tempStr);
uint64_t split;
int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split);
if(err){ return err; }
if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; }
ARC_String_CopySubstring(&tempStr, string, split + 1, string->length - (split + 1));
ARC_String_StripEndsWhitespace(tempStr, &framesStr);
ARC_String_Destroy(tempStr);
//spritesheet
ARC_StringSubstr temp = { subdata->index, split };
ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp);
ARC_Spritesheet *spritesheet = (ARC_Spritesheet *)ARC_Config_GetReference(config, (char *)data, &temp);
if(!spritesheet){ ARC_Spritesheet_Delete(config, data, &temp, (void *)sprite->spritesheet); }
//bounds
temp = (ARC_StringSubstr){ subdata->index + split + 1, subdata->length - split - 1 };
ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp);
SDL_Rect *bounds = (SDL_Rect *)ARC_Config_GetReference(config, (char *)data, &temp);
if(!bounds){
free(sprite->frames);
ARC_Config_Get(config, spritesheetStr, (void **)&temp);
ARC_String_Destroy(spritesheetStr);
if(temp){
free(spriteValue->spritesheet);
}
free(sprite->frameIndex);
free(sprite);
return 0;
ARC_Config_Get(config, framesStr, (void **)&temp);
ARC_String_Destroy(framesStr);
if(temp){
free(spriteValue->frames);
}
free(spriteValue);
}
#endif //ARC_SDL