* associates a ttf resource to a .fontc file. * @note The ttf font is loaded via the resource system. There are a few ways it can be accessed: * - It was already loaded in the resource system * - It is bundled via our game data * - It is accessible via a live update mount * * @note The reference count will increase for the .ttf font * * * @name font.add_font * @param fontc [t
| 72 | * ``` |
| 73 | */ |
| 74 | static int AddFont(lua_State* L) |
| 75 | { |
| 76 | DM_LUA_STACK_CHECK(L, 0); |
| 77 | |
| 78 | dmhash_t fontc_path_hash = dmScript::CheckHashOrString(L, 1); |
| 79 | // TODO: If it's a string, pass a string to the function to allow for explicit loading of the resource |
| 80 | const char* ttf_path = 0; |
| 81 | dmhash_t ttf_path_hash = 0; |
| 82 | if (lua_isstring(L, 2)) |
| 83 | { |
| 84 | ttf_path = luaL_checkstring(L, 2); |
| 85 | } |
| 86 | else |
| 87 | { |
| 88 | ttf_path_hash = dmScript::CheckHash(L, 2); |
| 89 | } |
| 90 | |
| 91 | dmGameSystem::FontResource* resource; |
| 92 | dmResource::Result r = dmResource::GetWithExt(g_ResourceFactory, fontc_path_hash, EXT_HASH_FONTC, (void**)&resource); |
| 93 | if (dmResource::RESULT_OK != r) |
| 94 | { |
| 95 | return DM_LUA_ERROR("Failed to get font %s: %d", dmHashReverseSafe64(fontc_path_hash), r); |
| 96 | } |
| 97 | |
| 98 | if (ttf_path) |
| 99 | r = dmGameSystem::ResFontAddFontByPath(g_ResourceFactory, resource, ttf_path); |
| 100 | else |
| 101 | r = dmGameSystem::ResFontAddFontByPathHash(g_ResourceFactory, resource, ttf_path_hash); |
| 102 | dmResource::Release(g_ResourceFactory, resource); |
| 103 | |
| 104 | if (dmResource::RESULT_OK != r) |
| 105 | { |
| 106 | return DM_LUA_ERROR("Failed to add font '%s' to font collection '%s'", dmHashReverseSafe64(ttf_path_hash), dmHashReverseSafe64(fontc_path_hash)); |
| 107 | } |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | /*# |
| 113 | * associates a ttf resource to a .fontc file |
no test coverage detected