diff --git a/headers/enduro2d/high/assets/json_asset.hpp b/headers/enduro2d/high/assets/json_asset.hpp index 04192f41..ff880930 100644 --- a/headers/enduro2d/high/assets/json_asset.hpp +++ b/headers/enduro2d/high/assets/json_asset.hpp @@ -12,7 +12,7 @@ namespace e2d { - using json_uptr = std::unique_ptr; + using json_uptr = std::shared_ptr; class json_asset final : public content_asset { public: static const char* type_name() noexcept { return "json_asset"; } diff --git a/headers/enduro2d/high/assets/xml_asset.hpp b/headers/enduro2d/high/assets/xml_asset.hpp index 4988303d..18fc856b 100644 --- a/headers/enduro2d/high/assets/xml_asset.hpp +++ b/headers/enduro2d/high/assets/xml_asset.hpp @@ -12,7 +12,7 @@ namespace e2d { - using xml_uptr = std::unique_ptr; + using xml_uptr = std::shared_ptr; class xml_asset final : public content_asset { public: static const char* type_name() noexcept { return "xml_asset"; } diff --git a/samples/bin/library/scripts/emmy/assets/atlas.lua b/samples/bin/library/scripts/emmy/assets/atlas.lua new file mode 100644 index 00000000..806f19e4 --- /dev/null +++ b/samples/bin/library/scripts/emmy/assets/atlas.lua @@ -0,0 +1,15 @@ +---@class atlas +local atlas = { +} + +---@type atlas +_G.atlas = _G.atlas or atlas + +---@class atlas_asset +local atlas_asset = { + ---@type atlas + content = nil +} + +---@type atlas_asset +_G.atlas_asset = _G.atlas_asset or atlas_asset diff --git a/samples/bin/library/scripts/emmy/assets/binary.lua b/samples/bin/library/scripts/emmy/assets/binary.lua new file mode 100644 index 00000000..47b1b28c --- /dev/null +++ b/samples/bin/library/scripts/emmy/assets/binary.lua @@ -0,0 +1,15 @@ +---@class binary +local binary = { +} + +---@type binary +_G.binary = _G.binary or binary + +---@class binary_asset +local binary_asset = { + ---@type binary + content = nil +} + +---@type binary_asset +_G.binary_asset = _G.binary_asset or binary_asset diff --git a/samples/bin/library/scripts/emmy/assets/flipbook.lua b/samples/bin/library/scripts/emmy/assets/flipbook.lua new file mode 100644 index 00000000..8553efff --- /dev/null +++ b/samples/bin/library/scripts/emmy/assets/flipbook.lua @@ -0,0 +1,15 @@ +---@class flipbook +local flipbook = { +} + +---@type flipbook +_G.flipbook = _G.flipbook or flipbook + +---@class flipbook_asset +local flipbook_asset = { + ---@type flipbook + content = nil +} + +---@type flipbook_asset +_G.flipbook_asset = _G.flipbook_asset or flipbook_asset diff --git a/samples/bin/library/scripts/emmy/assets/font.lua b/samples/bin/library/scripts/emmy/assets/font.lua new file mode 100644 index 00000000..fd50f3de --- /dev/null +++ b/samples/bin/library/scripts/emmy/assets/font.lua @@ -0,0 +1,15 @@ +---@class font +local font = { +} + +---@type font +_G.font = _G.font or font + +---@class font_asset +local font_asset = { + ---@type font + content = nil +} + +---@type font_asset +_G.font_asset = _G.font_asset or font_asset diff --git a/samples/bin/library/scripts/emmy/assets/image.lua b/samples/bin/library/scripts/emmy/assets/image.lua new file mode 100644 index 00000000..b5d8b94b --- /dev/null +++ b/samples/bin/library/scripts/emmy/assets/image.lua @@ -0,0 +1,15 @@ +---@class image +local image = { +} + +---@type image +_G.image = _G.image or image + +---@class image_asset +local image_asset = { + ---@type image + content = nil +} + +---@type image_asset +_G.image_asset = _G.image_asset or image_asset diff --git a/samples/bin/library/scripts/emmy/assets/json.lua b/samples/bin/library/scripts/emmy/assets/json.lua new file mode 100644 index 00000000..3f9cab9e --- /dev/null +++ b/samples/bin/library/scripts/emmy/assets/json.lua @@ -0,0 +1,15 @@ +---@class json +local json = { +} + +---@type json +_G.json = _G.json or json + +---@class json_asset +local json_asset = { + ---@type json + content = nil +} + +---@type json_asset +_G.json_asset = _G.json_asset or json_asset diff --git a/samples/bin/library/scripts/emmy/assets/material.lua b/samples/bin/library/scripts/emmy/assets/material.lua new file mode 100644 index 00000000..e24f38c7 --- /dev/null +++ b/samples/bin/library/scripts/emmy/assets/material.lua @@ -0,0 +1,15 @@ +---@class material +local material = { +} + +---@type material +_G.material = _G.material or material + +---@class material_asset +local material_asset = { + ---@type material + content = nil +} + +---@type material_asset +_G.material_asset = _G.material_asset or material_asset diff --git a/samples/bin/library/scripts/emmy/assets/mesh.lua b/samples/bin/library/scripts/emmy/assets/mesh.lua new file mode 100644 index 00000000..eaac6546 --- /dev/null +++ b/samples/bin/library/scripts/emmy/assets/mesh.lua @@ -0,0 +1,15 @@ +---@class mesh +local mesh = { +} + +---@type mesh +_G.mesh = _G.mesh or mesh + +---@class mesh_asset +local mesh_asset = { + ---@type mesh + content = nil +} + +---@type mesh_asset +_G.mesh_asset = _G.mesh_asset or mesh_asset diff --git a/samples/bin/library/scripts/emmy/assets/model.lua b/samples/bin/library/scripts/emmy/assets/model.lua new file mode 100644 index 00000000..5e2c98ed --- /dev/null +++ b/samples/bin/library/scripts/emmy/assets/model.lua @@ -0,0 +1,15 @@ +---@class model +local model = { +} + +---@type model +_G.model = _G.model or model + +---@class model_asset +local model_asset = { + ---@type model + content = nil +} + +---@type model_asset +_G.model_asset = _G.model_asset or model_asset diff --git a/samples/bin/library/scripts/emmy/assets/prefab.lua b/samples/bin/library/scripts/emmy/assets/prefab.lua new file mode 100644 index 00000000..f40bd6c8 --- /dev/null +++ b/samples/bin/library/scripts/emmy/assets/prefab.lua @@ -0,0 +1,15 @@ +---@class prefab +local prefab = { +} + +---@type prefab +_G.prefab = _G.prefab or prefab + +---@class prefab_asset +local prefab_asset = { + ---@type prefab + content = nil +} + +---@type prefab_asset +_G.prefab_asset = _G.prefab_asset or prefab_asset diff --git a/samples/bin/library/scripts/emmy/assets/script.lua b/samples/bin/library/scripts/emmy/assets/script.lua new file mode 100644 index 00000000..6b2fb30e --- /dev/null +++ b/samples/bin/library/scripts/emmy/assets/script.lua @@ -0,0 +1,15 @@ +---@class script +local script = { +} + +---@type script +_G.script = _G.script or script + +---@class script_asset +local script_asset = { + ---@type script + content = nil +} + +---@type script_asset +_G.script_asset = _G.script_asset or script_asset diff --git a/samples/bin/library/scripts/emmy/assets/shader.lua b/samples/bin/library/scripts/emmy/assets/shader.lua new file mode 100644 index 00000000..d1346071 --- /dev/null +++ b/samples/bin/library/scripts/emmy/assets/shader.lua @@ -0,0 +1,15 @@ +---@class shader +local shader = { +} + +---@type shader +_G.shader = _G.shader or shader + +---@class shader_asset +local shader_asset = { + ---@type shader + content = nil +} + +---@type shader_asset +_G.shader_asset = _G.shader_asset or shader_asset diff --git a/samples/bin/library/scripts/emmy/assets/shape.lua b/samples/bin/library/scripts/emmy/assets/shape.lua new file mode 100644 index 00000000..b3d9e4e4 --- /dev/null +++ b/samples/bin/library/scripts/emmy/assets/shape.lua @@ -0,0 +1,15 @@ +---@class shape +local shape = { +} + +---@type shape +_G.shape = _G.shape or shape + +---@class shape_asset +local shape_asset = { + ---@type shape + content = nil +} + +---@type shape_asset +_G.shape_asset = _G.shape_asset or shape_asset diff --git a/samples/bin/library/scripts/emmy/assets/sound.lua b/samples/bin/library/scripts/emmy/assets/sound.lua new file mode 100644 index 00000000..e5072959 --- /dev/null +++ b/samples/bin/library/scripts/emmy/assets/sound.lua @@ -0,0 +1,15 @@ +---@class sound +local sound = { +} + +---@type sound +_G.sound = _G.sound or sound + +---@class sound_asset +local sound_asset = { + ---@type sound + content = nil +} + +---@type sound_asset +_G.sound_asset = _G.sound_asset or sound_asset diff --git a/samples/bin/library/scripts/emmy/assets/spine.lua b/samples/bin/library/scripts/emmy/assets/spine.lua new file mode 100644 index 00000000..44d40899 --- /dev/null +++ b/samples/bin/library/scripts/emmy/assets/spine.lua @@ -0,0 +1,15 @@ +---@class spine +local spine = { +} + +---@type spine +_G.spine = _G.spine or spine + +---@class spine_asset +local spine_asset = { + ---@type spine + content = nil +} + +---@type spine_asset +_G.spine_asset = _G.spine_asset or spine_asset diff --git a/samples/bin/library/scripts/emmy/assets/sprite.lua b/samples/bin/library/scripts/emmy/assets/sprite.lua new file mode 100644 index 00000000..2840286a --- /dev/null +++ b/samples/bin/library/scripts/emmy/assets/sprite.lua @@ -0,0 +1,15 @@ +---@class sprite +local sprite = { +} + +---@type sprite +_G.sprite = _G.sprite or sprite + +---@class sprite_asset +local sprite_asset = { + ---@type sprite + content = nil +} + +---@type sprite_asset +_G.sprite_asset = _G.sprite_asset or sprite_asset diff --git a/samples/bin/library/scripts/emmy/assets/text.lua b/samples/bin/library/scripts/emmy/assets/text.lua new file mode 100644 index 00000000..d328a9f1 --- /dev/null +++ b/samples/bin/library/scripts/emmy/assets/text.lua @@ -0,0 +1,15 @@ +---@class text +local text = { +} + +---@type text +_G.text = _G.text or text + +---@class text_asset +local text_asset = { + ---@type text + content = nil +} + +---@type text_asset +_G.text_asset = _G.text_asset or text_asset diff --git a/samples/bin/library/scripts/emmy/assets/texture.lua b/samples/bin/library/scripts/emmy/assets/texture.lua new file mode 100644 index 00000000..51dd0acf --- /dev/null +++ b/samples/bin/library/scripts/emmy/assets/texture.lua @@ -0,0 +1,15 @@ +---@class texture +local texture = { +} + +---@type texture +_G.texture = _G.texture or texture + +---@class texture_asset +local texture_asset = { + ---@type texture + content = nil +} + +---@type texture_asset +_G.texture_asset = _G.texture_asset or texture_asset diff --git a/samples/bin/library/scripts/emmy/assets/xml.lua b/samples/bin/library/scripts/emmy/assets/xml.lua new file mode 100644 index 00000000..c0e557ca --- /dev/null +++ b/samples/bin/library/scripts/emmy/assets/xml.lua @@ -0,0 +1,15 @@ +---@class xml +local xml = { +} + +---@type xml +_G.xml = _G.xml or xml + +---@class xml_asset +local xml_asset = { + ---@type xml + content = nil +} + +---@type xml_asset +_G.xml_asset = _G.xml_asset or xml_asset diff --git a/samples/bin/library/scripts/emmy/high/library.lua b/samples/bin/library/scripts/emmy/high/library.lua new file mode 100644 index 00000000..d9095d2d --- /dev/null +++ b/samples/bin/library/scripts/emmy/high/library.lua @@ -0,0 +1,101 @@ +---@class library +local library = { +} + +---@param self library +---@param address string +---@return atlas_asset +function library.load_atlas(self, address) end + +---@param self library +---@param address string +---@return binary_asset +function library.load_binary(self, address) end + +---@param self library +---@param address string +---@return flipbook_asset +function library.load_flipbook(self, address) end + +---@param self library +---@param address string +---@return font_asset +function library.load_font(self, address) end + +---@param self library +---@param address string +---@return image_asset +function library.load_image(self, address) end + +---@param self library +---@param address string +---@return json_asset +function library.load_json(self, address) end + +---@param self library +---@param address string +---@return material_asset +function library.load_material(self, address) end + +---@param self library +---@param address string +---@return mesh_asset +function library.load_mesh(self, address) end + +---@param self library +---@param address string +---@return model_asset +function library.load_model(self, address) end + +---@param self library +---@param address string +---@return prefab_asset +function library.load_prefab(self, address) end + +---@param self library +---@param address string +---@return script_asset +function library.load_script(self, address) end + +---@param self library +---@param address string +---@return shader_asset +function library.load_shader(self, address) end + +---@param self library +---@param address string +---@return shape_asset +function library.load_shape(self, address) end + +---@param self library +---@param address string +---@return sound_asset +function library.load_sound(self, address) end + +---@param self library +---@param address string +---@return spine_asset +function library.load_spine(self, address) end + +---@param self library +---@param address string +---@return sprite_asset +function library.load_sprite(self, address) end + +---@param self library +---@param address string +---@return text_asset +function library.load_text(self, address) end + +---@param self library +---@param address string +---@return texture_asset +function library.load_texture(self, address) end + +---@param self library +---@param address string +---@return xml_asset +function library.load_xml(self, address) end + +---@type library +_G.the_library = _G.the_library or library diff --git a/sources/enduro2d/high/assets/json_asset.cpp b/sources/enduro2d/high/assets/json_asset.cpp index aefed664..cadb241b 100644 --- a/sources/enduro2d/high/assets/json_asset.cpp +++ b/sources/enduro2d/high/assets/json_asset.cpp @@ -26,7 +26,7 @@ namespace e2d return library.load_asset_async(address) .then([](const text_asset::load_result& json_data){ return the().do_in_worker_thread([json_data](){ - auto json = std::make_unique(); + auto json = std::make_shared(); if ( json->Parse(json_data->content().c_str()).HasParseError() ) { throw json_asset_loading_exception(); } diff --git a/sources/enduro2d/high/assets/xml_asset.cpp b/sources/enduro2d/high/assets/xml_asset.cpp index c98cdab9..de8aec11 100644 --- a/sources/enduro2d/high/assets/xml_asset.cpp +++ b/sources/enduro2d/high/assets/xml_asset.cpp @@ -26,7 +26,7 @@ namespace e2d return library.load_asset_async(address) .then([](const text_asset::load_result& xml_data){ return the().do_in_worker_thread([xml_data](){ - auto xml = std::make_unique(); + auto xml = std::make_shared(); if ( !xml->load_string(xml_data->content().c_str()) ) { throw xml_asset_loading_exception(); } diff --git a/sources/enduro2d/high/bindings/high_binds/_high_binds.hpp b/sources/enduro2d/high/bindings/high_binds/_high_binds.hpp index bef1fbc0..572f9c2f 100644 --- a/sources/enduro2d/high/bindings/high_binds/_high_binds.hpp +++ b/sources/enduro2d/high/bindings/high_binds/_high_binds.hpp @@ -1,8 +1,8 @@ /******************************************************************************* -* This file is part of the "Enduro2D" -* For conditions of distribution and use, see copyright notice in LICENSE.md -* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) -******************************************************************************/ + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ #pragma once diff --git a/sources/enduro2d/high/bindings/high_binds/library_binds.cpp b/sources/enduro2d/high/bindings/high_binds/library_binds.cpp index 9a1d0427..d2872bc6 100644 --- a/sources/enduro2d/high/bindings/high_binds/library_binds.cpp +++ b/sources/enduro2d/high/bindings/high_binds/library_binds.cpp @@ -1,18 +1,77 @@ /******************************************************************************* -* This file is part of the "Enduro2D" -* For conditions of distribution and use, see copyright notice in LICENSE.md -* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) -******************************************************************************/ + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ #include "_high_binds.hpp" -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + using namespace e2d; + + template < typename Asset > + void bind_asset(const str& base_name, sol::state& l) { + l.new_usertype(base_name + "_asset", + sol::no_constructor, + + "content", sol::property([](const Asset& a){ + return a.content(); + }) + ); + + l["library"][str("load_") + base_name] = + [](const library& l, str_view address){ + return l.load_main_asset(address); + }; + } +} namespace e2d::bindings::high { void bind_library(sol::state& l) { - l["e2d"].get_or_create() - ["high"].get_or_create() - .new_usertype("library"); + l.new_usertype("library", + sol::no_constructor + ); + + bind_asset("atlas", l); + bind_asset("binary", l); + bind_asset("flipbook", l); + bind_asset("font", l); + bind_asset("image", l); + bind_asset("json", l); + bind_asset("material", l); + bind_asset("mesh", l); + bind_asset("model", l); + bind_asset("prefab", l); + bind_asset("script", l); + bind_asset("shader", l); + bind_asset("shape", l); + bind_asset("sound", l); + bind_asset("spine", l); + bind_asset("sprite", l); + bind_asset("text", l); + bind_asset("texture", l); + bind_asset("xml", l); } }