MCPcopy Create free account
hub / github.com/defold/defold / GetAtlas

Function GetAtlas

engine/gamesys/src/gamesys/scripts/script_resource.cpp:2828–2906  ·  view source on GitHub ↗

Get atlas data * Returns the atlas data for an atlas * * @name resource.get_atlas * * @param path [type:hash|string] The path to the atlas resource * * @return data [type:table] A table with the following entries: * * - texture * - geometries * - animations * * Each animation entry also contains a `frames` table with indices into * `geometries`, preserving the frame-to-geometry mappi

Source from the content-addressed store, hash-verified

2826 *
2827 */
2828static int GetAtlas(lua_State* L)
2829{
2830 DM_LUA_STACK_CHECK(L, 1);
2831
2832 dmhash_t path_hash = dmScript::CheckHashOrString(L, 1);
2833
2834 TextureSetResource* texture_set_res = (TextureSetResource*) CheckResource(L, g_ResourceModule.m_Factory, path_hash, "texturesetc");
2835 dmGameSystemDDF::TextureSet* texture_set = texture_set_res->m_TextureSet;
2836 assert(texture_set);
2837
2838 #define SET_LUA_TABLE_FIELD(set_fn, key, val) \
2839 set_fn(L, val); \
2840 lua_setfield(L, -2, key);
2841
2842 lua_newtable(L);
2843
2844 if (texture_set->m_TextureHash)
2845 {
2846 SET_LUA_TABLE_FIELD(dmScript::PushHash, "texture", texture_set->m_TextureHash);
2847 }
2848 else
2849 {
2850 SET_LUA_TABLE_FIELD(lua_pushstring, "texture", texture_set->m_Texture);
2851 }
2852
2853 lua_pushliteral(L, "animations");
2854 lua_newtable(L);
2855 {
2856 for (int i = 0; i < texture_set->m_Animations.m_Count; ++i)
2857 {
2858 dmGameSystemDDF::TextureSetAnimation& anim = texture_set->m_Animations[i];
2859
2860 lua_pushinteger(L, (lua_Integer) (i+1));
2861 lua_newtable(L);
2862
2863 SET_LUA_TABLE_FIELD(lua_pushstring, "id", anim.m_Id);
2864 SET_LUA_TABLE_FIELD(lua_pushinteger, "width", anim.m_Width);
2865 SET_LUA_TABLE_FIELD(lua_pushinteger, "height", anim.m_Height);
2866 SET_LUA_TABLE_FIELD(lua_pushinteger, "fps", anim.m_Fps);
2867 SET_LUA_TABLE_FIELD(lua_pushinteger, "playback", (lua_Integer) DDFPlaybackToGameObjectPlayback(anim.m_Playback));
2868 SET_LUA_TABLE_FIELD(lua_pushboolean, "flip_horizontal", anim.m_FlipHorizontal);
2869 SET_LUA_TABLE_FIELD(lua_pushboolean, "flip_vertical", anim.m_FlipVertical);
2870 lua_pushliteral(L, "frames");
2871 lua_newtable(L);
2872
2873 for (uint32_t frame_index = anim.m_Start; frame_index < anim.m_End; ++frame_index)
2874 {
2875 uint32_t geometry_index = texture_set->m_FrameIndices[frame_index];
2876 lua_pushinteger(L, (lua_Integer) (frame_index - anim.m_Start + 1));
2877 lua_pushinteger(L, (lua_Integer) (geometry_index + 1));
2878 lua_rawset(L, -3);
2879 }
2880 lua_settable(L, -3);
2881
2882 lua_rawset(L, -3);
2883 }
2884 }
2885 lua_rawset(L, -3);

Callers

nothing calls this directly

Calls 10

CheckHashOrStringFunction · 0.85
CheckResourceFunction · 0.85
lua_pushintegerFunction · 0.85
lua_rawsetFunction · 0.85
lua_settableFunction · 0.85
GetTextureWidthFunction · 0.85
GetTextureHeightFunction · 0.85
PushGeometryFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected