working on sprite config, kinda scared I'm f***ing everything up :)

This commit is contained in:
herbglitch 2025-03-25 04:54:13 -06:00
parent da2be7780b
commit 8845cf78e0
7 changed files with 149 additions and 55 deletions

View file

@ -55,14 +55,92 @@ void ARC_ConfigType_SpritesheetCopyFn(void **type, ARC_ParserTagToken *parsedDat
}
}
void ARC_ConfigType_SpritesheetDestroyFn(void *type){
void ARC_ConfigType_SpritesheetDestroyFn(ARC_Config *config, void *type){
ARC_Spritesheet_Destroy((ARC_Spritesheet *)type);
}
void ARC_ConfigType_SpriteCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata){
//go into the <nestedValue> tag
ARC_ParserTagToken *childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 0);
if(childTagToken->id != ARC_CONFIG_NESTED_VALUE){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_SpriteCopyFn(type, parsedData, config, userdata), parsed data was not a <nestedValue>");
*type = NULL;
return;
}
//<nestedValue> -> OPEN_CURLY_BRACE <whitespace> <valueArgs> <whitespace> CLOSE_CURLY_BRACE
ARC_ParserTagToken *valueArgsTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(childTagToken->tagTokens, 2);
ARC_Sprite *sprite;
ARC_Sprite_Create(&sprite, NULL, (ARC_Array){ 0, NULL });
//really large number in case a system has 64 digit pointer addresses
char pointerCString[64];
sprintf(pointerCString, "%p", sprite);
//<valueArgs> -> <value> <whitespace> COMMA <whitespace> <valueArgs> | <value>
if(ARC_Vector_GetSize(valueArgsTagToken->tagTokens) == 1){
//TODO: error here
}
ARC_ParserTagToken *valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0);
//check if spritesheet exist
ARC_String *valueString;
ARC_String_Create(&valueString, NULL, 0);
ARC_ParserData_HelperRecurseStringAdd(&valueString, valueTagToken);
ARC_Spritesheet *spritesheet = (ARC_Spritesheet *)ARC_Config_Get(config, valueString);
if(spritesheet == NULL){
//create a name based on the type and the sprite pointer to have a unique name for cleanup on remove
ARC_String *spritesheetName;
ARC_String_CreateWithStrlen(&spritesheetName, pointerCString);
ARC_String_AppendCStringWithStrlen(&spritesheetName, "ARC_Spritesheet");
//copy the spritesheet
ARC_Spritesheet *sheet;
ARC_ConfigType_SpritesheetCopyFn((void *)&sheet, valueTagToken, config, userdata);
//add the new spritesheet type to the config
ARC_Config_AddWithCStr(config, "ARC_Spritesheet", spritesheetName->data, (void *)sheet);
//cleanup
ARC_String_Destroy(spritesheetName);
}
ARC_String_Destroy(valueString);
valueString = NULL;
//check if bounds exist
ARC_String_Create(&valueString, NULL, 0);
ARC_ParserData_HelperRecurseStringAdd(&valueString, valueTagToken);
void *bounds = ARC_Config_Get(config, valueString);
if(bounds == NULL){
//ARC_Config_AddWithCStr(config, "ARC_FRect[]", const char *name, void *value)
}
ARC_String_Destroy(valueString);
}
void ARC_ConfigType_SpriteDestroyFn(void *type){
void ARC_ConfigType_SpriteDestroyFn(ARC_Config *config, void *type){
ARC_Sprite *sprite = (ARC_Sprite *)type;
//really large number in case a system has 64 digit pointer addresses
char pointerCString[64];
sprintf(pointerCString, "%p", sprite);
//create a name based on the type and the sprite pointer to have a unique name for cleanup on remove
ARC_String *spritesheetName;
ARC_String_CreateWithStrlen(&spritesheetName, pointerCString);
ARC_String_AppendCStringWithStrlen(&spritesheetName, "ARC_Spritesheet");
//remove the spritesheet from the config (it won't error if it doesn't exist)
//ARC_Config_RemoveWithCStr(config, spritesheetName->data, ARC_False);
//cleanup
ARC_String_Destroy(spritesheetName);
}

View file

@ -91,7 +91,9 @@ void ARC_Sprite_SetOrigin(ARC_Sprite *sprite, ARC_FPoint origin){
void ARC_Sprite_SetOpacity(ARC_Sprite *sprite, float opacity){
sprite->opacity = opacity;
SDL_SetTextureAlphaMod((SDL_Texture *)sprite->spritesheet->texture, sprite->opacity);
if(sprite->spritesheet != NULL){
SDL_SetTextureAlphaMod((SDL_Texture *)sprite->spritesheet->texture, sprite->opacity);
}
}
uint32_t ARC_Sprite_GetFrameIndex(ARC_Sprite *sprite){