Add hflip and rotation parameters to sim.loadStamp
This commit is contained in:
parent
7b894a693e
commit
1a69bbfb51
13
src/Misc.h
13
src/Misc.h
@ -5,6 +5,19 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
template<class Signed>
|
||||||
|
inline std::pair<Signed, Signed> 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
|
//Linear interpolation
|
||||||
template <typename T> inline T LinearInterpolate(T val1, T val2, T lowerCoord, T upperCoord, T coord)
|
template <typename T> inline T LinearInterpolate(T val1, T val2, T lowerCoord, T upperCoord, T coord)
|
||||||
{
|
{
|
||||||
|
@ -1930,19 +1930,6 @@ void GameView::TransformSave(Mat2<int> mulToTransform)
|
|||||||
ApplyTransformPlaceSave();
|
ApplyTransformPlaceSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Signed>
|
|
||||||
static std::pair<Signed, Signed> 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()
|
void GameView::ApplyTransformPlaceSave()
|
||||||
{
|
{
|
||||||
auto remX = floorDiv(placeSaveTranslate.X, CELL).second;
|
auto remX = floorDiv(placeSaveTranslate.X, CELL).second;
|
||||||
|
@ -1967,8 +1967,12 @@ int LuaScriptInterface::simulation_loadStamp(lua_State * l)
|
|||||||
int i = -1;
|
int i = -1;
|
||||||
int pushed = 1;
|
int pushed = 1;
|
||||||
std::unique_ptr<SaveFile> tempfile;
|
std::unique_ptr<SaveFile> tempfile;
|
||||||
int x = luaL_optint(l,2,0) / CELL;
|
Vec2<int> partP = {
|
||||||
int y = luaL_optint(l,3,0) / CELL;
|
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();
|
auto &client = Client::Ref();
|
||||||
if (lua_isstring(l, 1)) //Load from 10 char name, or full filename
|
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())
|
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();
|
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<int>::Identity;
|
||||||
|
if (hflip)
|
||||||
|
{
|
||||||
|
transform = Mat2<int>::MirrorX * transform;
|
||||||
|
}
|
||||||
|
for (auto i = 0; i < rotation; ++i)
|
||||||
|
{
|
||||||
|
transform = Mat2<int>::CCW * transform;
|
||||||
|
}
|
||||||
|
gameSave->Transform(transform, { remX, remY });
|
||||||
|
}
|
||||||
|
luacon_sim->Load(gameSave.get(), !luacon_controller->GetView()->ShiftBehaviour(), { quoX, quoY });
|
||||||
lua_pushinteger(l, 1);
|
lua_pushinteger(l, 1);
|
||||||
|
|
||||||
if (gameSave->authors.size())
|
if (gameSave->authors.size())
|
||||||
|
Reference in New Issue
Block a user