diff options
| -rw-r--r-- | src/font.cpp | 11 | ||||
| -rw-r--r-- | src/font.hpp | 1 | ||||
| -rw-r--r-- | src/serialization-font.cpp | 22 | ||||
| -rw-r--r-- | src/serialization.hpp | 2 | ||||
| -rw-r--r-- | tests/pke-test-serialization.cpp | 12 |
5 files changed, 34 insertions, 14 deletions
diff --git a/src/font.cpp b/src/font.cpp index 35db13f..bd4d530 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -491,6 +491,17 @@ FontType* FontType_Get(FontTypeIndex idx) { return &ftd.arr_ft[static_cast<FontTypeIndex_T>(idx)]; } +FontType* FontType_GetByTitle(const pk_cstr title) { + assert(title.val != nullptr); + for (FontTypeIndex_T i = 0; i < static_cast<FontTypeIndex_T>(ftd.h_ft); ++i) { + if (ftd.arr_ft[i].title.val == title.val) + return &ftd.arr_ft[i]; + if (strcmp(ftd.arr_ft[i].title.val, title.val) == 0) + return &ftd.arr_ft[i]; + } + return nullptr; +} + FontType* FontType_GetFonts(FontTypeIndex &count) { count = ftd.h_ft; return ftd.arr_ft; diff --git a/src/font.hpp b/src/font.hpp index a8b1ecf..f07e640 100644 --- a/src/font.hpp +++ b/src/font.hpp @@ -119,6 +119,7 @@ void FontType_Tick(double delta); void FontType_Serialize(std::ostream &stream, FontType *ft); void FontType_Deserialize(std::istream &stream); FontType* FontType_Get(FontTypeIndex idx); +FontType* FontType_GetByTitle(const pk_cstr title); FontType* FontType_GetFonts(FontTypeIndex &count); FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle, AssetHandle glyphsHandle, FontTypeMSDFSettings *msdf_settings, FontTypeSpacing *spacing); void FontType_Unload(FontTypeIndex idx); diff --git a/src/serialization-font.cpp b/src/serialization-font.cpp index b57e6e7..c0a9471 100644 --- a/src/serialization-font.cpp +++ b/src/serialization-font.cpp @@ -10,6 +10,7 @@ pk_handle pke_serialize_font_render(srlztn_serialize_helper *h, FontRender *fr) assert(h != nullptr); assert(fr != nullptr); char *s; + int len; pk_handle font_render_settings_handle; pke_kve kve{}; pke_kve_container kvec{}; @@ -38,10 +39,11 @@ pk_handle pke_serialize_font_render(srlztn_serialize_helper *h, FontRender *fr) pk_arr_append_t(&kvec.arr, kve); } { - kve.key = SRLZTN_UI_FONT_RENDER_FONT_TYPE_UUID; - s = pk_new<char>(37, h->bkt); + kve.key = SRLZTN_UI_FONT_RENDER_FONT_TYPE_TITLE; FontType *ft = FontType_Get(fr->fr_handle.index_ft); - sprintf(s, pk_uuid_printf_format, pk_uuid_printf_var(ft->uuid)); + len = snprintf(nullptr, 0, "%s", ft->title.val); + s = pk_new<char>(len+1, h->bkt); + sprintf(s, "%s", ft->title.val); kve.val = s; kve.end = SRLZTN_KVE_END; pk_arr_append_t(&kvec.arr, kve); @@ -69,8 +71,8 @@ void pke_deserialize_font_render(srlztn_deserialize_helper *h, pke_kve_container pke_kve *kve = nullptr; pk_uuid uuid; - pk_uuid font_type_uuid; pk_cstr str; + FontType *font_type_ent; FontRenderSettings frs{}; pke_deserialize_font_render_settings(h, kvec->children[0], &frs); @@ -82,8 +84,14 @@ void pke_deserialize_font_render(srlztn_deserialize_helper *h, pke_kve_container kve->val >> uuid; continue; } - if (strcmp(kve->key, SRLZTN_UI_FONT_RENDER_FONT_TYPE_UUID) == 0) { - kve->val >> font_type_uuid; + if (strcmp(kve->key, SRLZTN_UI_FONT_RENDER_FONT_TYPE_TITLE) == 0) { + pk_cstr font_type_title; + font_type_title.length = strlen(kve->val) + 1; + font_type_title.reserved = font_type_title.length + 1; + s = pk_new<char>(font_type_title.reserved, h->bkt); + sprintf(s, "%s", kve->val); + font_type_title.val = s; + font_type_ent = FontType_GetByTitle(font_type_title); continue; } if (strcmp(kve->key, SRLZTN_UI_FONT_RENDER_TEXT_BEGIN) == 0) { @@ -97,8 +105,8 @@ void pke_deserialize_font_render(srlztn_deserialize_helper *h, pke_kve_container } } - FontType *font_type_ent = static_cast<FontType *>(ECS_GetEntityByUUID(font_type_uuid)); // parent is set later - up to the parent to take ownership + assert(font_type_ent != nullptr); FontType_AddStringRender(font_type_ent->index_ft, std::move(str), &frs, nullptr, uuid); } diff --git a/src/serialization.hpp b/src/serialization.hpp index 1f9df48..e26667f 100644 --- a/src/serialization.hpp +++ b/src/serialization.hpp @@ -59,7 +59,7 @@ iccsc SRLZTN_UI_BOX_TYPE = "Type:"; iccsc SRLZTN_UI_BOX_DATA_TEXT_FONT_RENDER_UUID = "FontRenderUUID:"; iccsc SRLZTN_UI_FONT_RENDER_UUID = "UUID:"; -iccsc SRLZTN_UI_FONT_RENDER_FONT_TYPE_UUID = "FontTypeUUID:"; +iccsc SRLZTN_UI_FONT_RENDER_FONT_TYPE_TITLE = "FontTypeTitle:"; iccsc SRLZTN_UI_FONT_RENDER_TEXT_BEGIN = "TextBegin::"; iccsc SRLZTN_UI_FONT_RENDER_SETTINGS_CHAR_SCALE = "CharScale:"; iccsc SRLZTN_UI_FONT_RENDER_SETTINGS_LINE_HEIGHT_SCALE = "LineHeightScale:"; diff --git a/tests/pke-test-serialization.cpp b/tests/pke-test-serialization.cpp index 5663275..724ccae 100644 --- a/tests/pke-test-serialization.cpp +++ b/tests/pke-test-serialization.cpp @@ -42,7 +42,7 @@ const pk_uuid uuid_n[] = { FAKE_UUID_GEN(0x0e), FAKE_UUID_GEN(0x0f), }; -const pk_uuid uuid_17 = FAKE_UUID_GEN(0x11); +// const pk_uuid uuid_17 = FAKE_UUID_GEN(0x11); // const pk_uuid uuid_34 = FAKE_UUID_GEN(0x22); void pke_test_serialization_spinup() { @@ -56,10 +56,10 @@ void pke_test_serialization_spinup() { FontType_Init(); pke_scene_master_init(); test_scene = pke_scene_create(test_scene_name); - FontTypeIndex fti; - FontType *ft = FontType_GetFonts(fti); - assert(fti > FontTypeIndex{0}); - ft->uuid = uuid_17; + // FontTypeIndex fti; + // FontType *ft = FontType_GetFonts(fti); + // assert(fti > FontTypeIndex{0}); + // ft->uuid = uuid_17; }; void pke_test_serialization_teardown() { @@ -400,7 +400,7 @@ SurfaceAreaFlags:0x03 FontRender:00000000!00000001 ChildId:00000000!00000000 UUID:01010101-0101-0101-0101-010101010101 -FontTypeUUID:11111111-1111-1111-1111-111111111111 +FontTypeTitle:fnt_mquin_7y TextBegin:: asdf :MULTILINE_END: |
