diff --git a/src/Misc.h b/src/Misc.h index c7696c909..2ebc6fe76 100644 --- a/src/Misc.h +++ b/src/Misc.h @@ -5,6 +5,19 @@ #include #include +template +inline std::pair floorDiv(Signed a, Signed b) +{ + auto quo = a / b; + auto rem = a % b; + if (a < Signed(0) && rem) + { + quo -= Signed(1); + rem += b; + } + return { quo, rem }; +} + //Linear interpolation template inline T LinearInterpolate(T val1, T val2, T lowerCoord, T upperCoord, T coord) { diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index 189d322a1..395857cdb 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -1930,19 +1930,6 @@ void GameView::TransformSave(Mat2 mulToTransform) ApplyTransformPlaceSave(); } -template -static std::pair floorDiv(Signed a, Signed b) -{ - auto quo = a / b; - auto rem = a % b; - if (a < Signed(0) && rem) - { - quo -= Signed(1); - rem += b; - } - return { quo, rem }; -} - void GameView::ApplyTransformPlaceSave() { auto remX = floorDiv(placeSaveTranslate.X, CELL).second; diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index ccacd3103..abc918e93 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -1967,8 +1967,12 @@ int LuaScriptInterface::simulation_loadStamp(lua_State * l) int i = -1; int pushed = 1; std::unique_ptr tempfile; - int x = luaL_optint(l,2,0) / CELL; - int y = luaL_optint(l,3,0) / CELL; + Vec2 partP = { + luaL_optint(l, 2, 0), + luaL_optint(l, 3, 0), + }; + auto hflip = lua_toboolean(l, 4); + auto rotation = luaL_optint(l, 5, 0) & 3; // [0, 3] rotations auto &client = Client::Ref(); if (lua_isstring(l, 1)) //Load from 10 char name, or full filename { @@ -1986,9 +1990,23 @@ int LuaScriptInterface::simulation_loadStamp(lua_State * l) if (tempfile && tempfile->GetGameSave()) { - // TODO: maybe do a gameSave->Transform with a new transform argument for the lua function and the "low" [0, CELL) part of x, y auto gameSave = tempfile->TakeGameSave(); - luacon_sim->Load(gameSave.get(), !luacon_controller->GetView()->ShiftBehaviour(), { x, y }); + auto [ quoX, remX ] = floorDiv(partP.X, CELL); + auto [ quoY, remY ] = floorDiv(partP.Y, CELL); + if (remX || remY || hflip || rotation) + { + auto transform = Mat2::Identity; + if (hflip) + { + transform = Mat2::MirrorX * transform; + } + for (auto i = 0; i < rotation; ++i) + { + transform = Mat2::CCW * transform; + } + gameSave->Transform(transform, { remX, remY }); + } + luacon_sim->Load(gameSave.get(), !luacon_controller->GetView()->ShiftBehaviour(), { quoX, quoY }); lua_pushinteger(l, 1); if (gameSave->authors.size())