diff --git a/src/asset/asset.c b/src/asset/asset.c index 38d63a0..c5804b9 100644 --- a/src/asset/asset.c +++ b/src/asset/asset.c @@ -94,8 +94,14 @@ errorret_t assetLoad(const char_t *filename, void *output) { errorChain(ret); break; - case ASSET_LOAD_STRAT_TEST: - assertUnreachable("Asset load strategy not implemented yet."); + case ASSET_LOAD_STRAT_CUSTOM: + assertNotNull(def->custom, "Asset load function cannot be NULL."); + assetcustom_t customData = { + .zipFile = file, + .output = output + }; + errorChain(def->custom(&customData)); + break; default: assertUnreachable("Unknown asset load strategy."); diff --git a/src/asset/asset.h b/src/asset/asset.h index 1469af2..571a0fa 100644 --- a/src/asset/asset.h +++ b/src/asset/asset.h @@ -7,7 +7,7 @@ #pragma once #include "error/error.h" -#include +#include "assettype.h" #if ASSET_TYPE == wad #else diff --git a/src/asset/assettype.h b/src/asset/assettype.h index 4c1b27c..5b81029 100644 --- a/src/asset/assettype.h +++ b/src/asset/assettype.h @@ -8,6 +8,8 @@ #pragma once #include "type/assetpaletteimage.h" #include "type/assetalphaimage.h" +#include "type/assetlanguage.h" +#include typedef enum { ASSET_TYPE_NULL, @@ -19,18 +21,21 @@ typedef enum { typedef enum { ASSET_LOAD_STRAT_ENTIRE, - ASSET_LOAD_STRAT_TEST + ASSET_LOAD_STRAT_CUSTOM } assetloadstrat_t; +typedef struct assetcustom_s { + zip_file_t *zipFile; + void *output; +} assetcustom_t; + typedef struct { const char_t *header; const size_t dataSize; const assetloadstrat_t loadStrategy; union { errorret_t (*entire)(void *data, void *output); - struct { - void *test; - } test; + errorret_t (*custom)(assetcustom_t *custom); }; } assettypedef_t; @@ -55,10 +60,7 @@ static const assettypedef_t ASSET_TYPE_DEFINITIONS[ASSET_TYPE_COUNT] = { [ASSET_TYPE_LANGUAGE] = { .header = "DLF", - .loadStrategy = ASSET_LOAD_STRAT_TEST, - .dataSize = 0, // Variable size - .test = { - .test = NULL - } + .loadStrategy = ASSET_LOAD_STRAT_CUSTOM, + .custom = assetLanguageInit } }; \ No newline at end of file diff --git a/src/asset/type/CMakeLists.txt b/src/asset/type/CMakeLists.txt index ba07c92..1b37565 100644 --- a/src/asset/type/CMakeLists.txt +++ b/src/asset/type/CMakeLists.txt @@ -8,4 +8,5 @@ target_sources(${DUSK_TARGET_NAME} PRIVATE assetalphaimage.c assetpaletteimage.c + assetlanguage.c ) \ No newline at end of file diff --git a/src/asset/type/assetlanguage.c b/src/asset/type/assetlanguage.c index e692be1..6e449cd 100644 --- a/src/asset/type/assetlanguage.c +++ b/src/asset/type/assetlanguage.c @@ -5,4 +5,10 @@ * https://opensource.org/licenses/MIT */ -#include "assetlanguage.h" \ No newline at end of file +#include "asset/asset.h" + +errorret_t assetLanguageInit(assetcustom_t *custom) { + zip_fclose(custom->zipFile); + + errorOk(); +} \ No newline at end of file diff --git a/src/asset/type/assetlanguage.h b/src/asset/type/assetlanguage.h index 451eb7b..f0c62d2 100644 --- a/src/asset/type/assetlanguage.h +++ b/src/asset/type/assetlanguage.h @@ -6,6 +6,7 @@ */ #pragma once +#include "error/error.h" #include "locale/language/keys.h" #define ASSET_LANG_CHUNK_CHAR_COUNT 6 * 1024 // 6 KB per chunk @@ -26,4 +27,14 @@ typedef struct { typedef struct { assetlanguagestring_t strings[LANG_KEY_COUNT]; } assetlanguageheader_t; -#pragma pack(pop) \ No newline at end of file +#pragma pack(pop) + +typedef struct assetcustom_s assetcustom_t; + +/** + * Receiving function from the asset manager to initialize language assets. + * + * @param custom Pointer to custom asset loading data. + * @return Error code. + */ +errorret_t assetLanguageInit(assetcustom_t *custom); \ No newline at end of file