diff --git a/dl/base/dl_vector2.h b/dl/base/dl_vector2.h index cdb2ff97..0ed5cb69 100644 --- a/dl/base/dl_vector2.h +++ b/dl/base/dl_vector2.h @@ -250,6 +250,18 @@ public: { return _data.end(); } + void reserve(size_t i) + { + _data.reserve(i); + } + void emplace_back(T&& t) + { + _data.emplace_back(t); + } + size_t size() const + { + return _data.size(); + } // 顺时针旋转90度 static Vector2 RotateRightAngle1(const Vector2& v) { diff --git a/dl/script/dl_lua.h b/dl/script/dl_lua.h index c670a2a7..6886b098 100644 --- a/dl/script/dl_lua.h +++ b/dl/script/dl_lua.h @@ -18,6 +18,7 @@ #include #define LUA_USE_APICHECK +#define LUABRIDGE_HAS_EXCEPTIONS 0 #include #include diff --git a/dl/script/dl_lua_register.cpp b/dl/script/dl_lua_register.cpp index 6a117464..ae288752 100644 --- a/dl/script/dl_lua_register.cpp +++ b/dl/script/dl_lua_register.cpp @@ -6,86 +6,7 @@ #include "script/dl_lua.h" #include "ui/dl_ui_manager.h" #include "render/dl_image.h" - -#include -#include - - -// Array 绑定 -namespace luabridge { - - //================================================================================================= - /** - * @brief Stack specialization for `dl::Array`. - */ - template - struct Stack> - { - using Type = dl::Array; - - [[nodiscard]] static Result push(lua_State* L, const Type& array) - { -#if LUABRIDGE_SAFE_STACK_CHECKS - if (!lua_checkstack(L, 3)) - return makeErrorCode(ErrorCode::LuaStackOverflow); -#endif - - StackRestore stackRestore(L); - - lua_createtable(L, static_cast(Size), 0); - - for (std::size_t i = 0; i < Size; ++i) - { - lua_pushinteger(L, static_cast(i + 1)); - - auto result = Stack::push(L, array[i]); - if (!result) - return result; - - lua_settable(L, -3); - } - - stackRestore.reset(); - return {}; - } - - [[nodiscard]] static TypeResult get(lua_State* L, int index) - { - if (!lua_istable(L, index)) - return makeErrorCode(ErrorCode::InvalidTypeCast); - - if (get_length(L, index) != Size) - return makeErrorCode(ErrorCode::InvalidTableSizeInCast); - - const StackRestore stackRestore(L); - - Type array; - - int absIndex = lua_absindex(L, index); - lua_pushnil(L); - - int arrayIndex = 0; - while (lua_next(L, absIndex) != 0) - { - auto item = Stack::get(L, -1); - if (!item) - return makeErrorCode(ErrorCode::InvalidTypeCast); - - array[arrayIndex++] = *item; - lua_pop(L, 1); - } - - return array; - } - - [[nodiscard]] static bool isInstance(lua_State* L, int index) - { - return lua_istable(L, index) && get_length(L, index) == Size; - } - }; - -} // namespace luabridge - +#include "script/dl_lua_register_container.h" // 枚举类绑定 @@ -109,26 +30,36 @@ namespace dl delete img; } + std::string lua_to_string(const Position2& pos) + { + return to_string(pos); + } + void lua_register_base(lua_State* L) { luabridge::getGlobalNamespace(L) - .addFunction("log", lua_log); + .addFunction("log", lua_log) + .addFunction("delete", lua_delete) + .addFunction("to_string", + luabridge::overload(lua_to_string)); - luabridge::getGlobalNamespace(L) - .addFunction("delete", lua_delete); luabridge::getGlobalNamespace(L) .beginNamespace("String") .addFunction("ErasePath", String::ErasePath) + .addFunction("GetFileStem", String::GetFileStem) + .addFunction("toPosition2", String::toPosition2) .addFunction("ReplaceExtension", luabridge::overload(String::ReplaceExtension)) + .addFunction("EraseFilename", + luabridge::overload(String::EraseFilename)) .endNamespace(); luabridge::getGlobalNamespace(L) .beginNamespace("Img") .addVariable("REGEX_FORMAT", Img::REGEX_FORMAT) .addFunction("ResizeImage", - luabridge::overload(Img::ResizeImage), + luabridge::overload(Img::ResizeImage), luabridge::overload(Img::ResizeImage)) .endNamespace(); @@ -138,8 +69,8 @@ namespace dl luabridge::getGlobalNamespace(L) .addFunction("createImage", - luabridge::overload(&createImage), - luabridge::overload(&createImage)) + luabridge::overload(createImage), + luabridge::overload(createImage)) .addFunction("saveImage", &saveImage); } @@ -177,14 +108,17 @@ namespace dl luabridge::getGlobalNamespace(L) .beginNamespace("g_file") - .addFunction("GetPathFileAll", &lua_GetPathFileAll_3, &lua_GetPathFileAll_2, &lua_GetPathFileAll_1) - .addFunction("GetAbsolute", &File::GetAbsolute) - .addFunction("GetRelative", &File::GetRelative) - .addFunction("CreateFolder", &File::CreateFolder) - .addFunction("Rename", &File::Rename) - .addFunction("Copy", &File::Copy) - .addFunction("GetFilePath", &File::GetFilePath) - .addFunction("GetFileName", &File::GetFileName) + .addFunction("GetPathFileAll", lua_GetPathFileAll_3, lua_GetPathFileAll_2, lua_GetPathFileAll_1) + .addFunction("GetAbsolute", File::GetAbsolute) + .addFunction("GetRelative", File::GetRelative) + .addFunction("CreateFolder", File::CreateFolder) + .addFunction("Rename", File::Rename) + .addFunction("Copy", File::Copy) + .addFunction("GetFilePath", File::GetFilePath) + .addFunction("GetFileName", File::GetFileName) + .addFunction("GetString", File::GetString) + .addFunction("SaveString", + luabridge::overload(File::SaveString)) .endNamespace(); } diff --git a/dl/script/dl_lua_register_container.h b/dl/script/dl_lua_register_container.h new file mode 100644 index 00000000..07c75057 --- /dev/null +++ b/dl/script/dl_lua_register_container.h @@ -0,0 +1,157 @@ +/** +* @file dl_lua_register.h +* @brief lua脚本接口注册 +* +* +* @version 1.0 +* @author lveyou +* @date 24-12-25 +* +* @note +*/ +#pragma once + +#include +#include + +// Array 绑定 +namespace luabridge { + + //================================================================================================= + /** + * @brief Stack specialization for `dl::Array`. + */ + template + struct Stack> + { + using Type = dl::Array; + + [[nodiscard]] static Result push(lua_State* L, const Type& array) + { +#if LUABRIDGE_SAFE_STACK_CHECKS + if (!lua_checkstack(L, 3)) + return makeErrorCode(ErrorCode::LuaStackOverflow); +#endif + + StackRestore stackRestore(L); + + lua_createtable(L, static_cast(Size), 0); + + for (std::size_t i = 0; i < Size; ++i) + { + lua_pushinteger(L, static_cast(i + 1)); + + auto result = Stack::push(L, array[i]); + if (!result) + return result; + + lua_settable(L, -3); + } + + stackRestore.reset(); + return {}; + } + + [[nodiscard]] static TypeResult get(lua_State* L, int index) + { + if (!lua_istable(L, index)) + return makeErrorCode(ErrorCode::InvalidTypeCast); + + if (get_length(L, index) != Size) + return makeErrorCode(ErrorCode::InvalidTableSizeInCast); + + const StackRestore stackRestore(L); + + Type array; + + int absIndex = lua_absindex(L, index); + lua_pushnil(L); + + int arrayIndex = 0; + while (lua_next(L, absIndex) != 0) + { + auto item = Stack::get(L, -1); + if (!item) + return makeErrorCode(ErrorCode::InvalidTypeCast); + + array[arrayIndex++] = *item; + lua_pop(L, 1); + } + + return array; + } + + [[nodiscard]] static bool isInstance(lua_State* L, int index) + { + return lua_istable(L, index) && get_length(L, index) == Size; + } + }; + +} // namespace luabridge + +namespace luabridge{ +//================================================================================================= +/** + * @brief Stack specialization for `dl::Vector2`. + */ +template +struct Stack, T> +{ + using Type = dl::Vector2; + + [[nodiscard]] static Result push(lua_State* L, const Type& vec) + { +#if LUABRIDGE_SAFE_STACK_CHECKS + if (!lua_checkstack(L, 3)) + return makeErrorCode(ErrorCode::LuaStackOverflow); +#endif + + StackRestore stackRestore(L); + + lua_createtable(L, 0, static_cast(vec.size())); + + for (auto it = vec.begin(); it != vec.end(); ++it) + { + auto result = Stack::push(L, *it); + if (!result) + return result; + + lua_settable(L, -3); + } + + stackRestore.reset(); + return {}; + } + + [[nodiscard]] static TypeResult get(lua_State* L, int index) + { + if (!lua_istable(L, index)) + return makeErrorCode(ErrorCode::InvalidTypeCast); + + const StackRestore stackRestore(L); + + Type vec; + + int absIndex = lua_absindex(L, index); + lua_pushnil(L); + + while (lua_next(L, absIndex) != 0) + { + auto value = Stack::get(L, -1); + if (!value) + return makeErrorCode(ErrorCode::InvalidTypeCast); + + vec.emplace_back(*value); + lua_pop(L, 1); + } + + return vec; + } + + [[nodiscard]] static bool isInstance(lua_State* L, int index) + { + return lua_istable(L, index); + } +}; + +} // namespace luabridge \ No newline at end of file diff --git a/project/dl_console/res/.gitignore b/project/dl_console/res/.gitignore index b14f813c..b605e1d1 100644 --- a/project/dl_console/res/.gitignore +++ b/project/dl_console/res/.gitignore @@ -8,3 +8,4 @@ /binary /dl /Microsoft.DTfW.DHL.manifest +/out diff --git a/project/dl_console/res/out/000833.png b/project/dl_console/res/out/000833.png deleted file mode 100644 index 1d98def5..00000000 Binary files a/project/dl_console/res/out/000833.png and /dev/null differ diff --git a/project/dl_console/res/out/000834.png b/project/dl_console/res/out/000834.png deleted file mode 100644 index 1f25ad29..00000000 Binary files a/project/dl_console/res/out/000834.png and /dev/null differ diff --git a/project/dl_console/res/out/000835.png b/project/dl_console/res/out/000835.png deleted file mode 100644 index 2d747271..00000000 Binary files a/project/dl_console/res/out/000835.png and /dev/null differ diff --git a/project/dl_console/res/批量缩放图片.lua b/project/dl_console/res/批量缩放图片.lua index 85829aef..75443f47 100644 --- a/project/dl_console/res/批量缩放图片.lua +++ b/project/dl_console/res/批量缩放图片.lua @@ -8,6 +8,7 @@ g_file.CreateFolder(path_out) local ret_files = g_file.GetPathFileAll(path_src, Img.REGEX_FORMAT, false) for key, value in pairs(ret_files) do + -- local img = createImage(value); local out = path_out .. g_file.GetRelative(value, path_src) out = String.ReplaceExtension(out, "png") @@ -17,10 +18,28 @@ for key, value in pairs(ret_files) do saveImage(img_out, out) delete(img_out) + -- 锚点文件处理 + local mata_name = String.EraseFilename(value) + mata_name = mata_name .. "Placements/".. String.GetFileStem(value) .. ".txt" + local out_name = String.EraseFilename(out) + g_file.CreateFolder(out_name .. "Placements/") + out_name = out_name .. "Placements/".. String.GetFileStem(value) .. ".txt" + + + local str = g_file.GetString(mata_name) + if #str > 0 then + print(str) + local pos = String.toPosition2(str, '\n') + pos[1] = math.floor(pos[1] * scale) + pos[2] = math.floor(pos[2] * scale) + str = pos[1]..'\n'..pos[2] + + g_file.SaveString(str, out_name) + end print(value .. "->" .. out) end -print "此工具会批量修改src文件夹的所有文件名为小写" +print "此工具会批量缩放src文件夹的所有图片,若只是统一转换为png,则scale填1" system "pause"