diff --git a/src/jasper/modules/world/include/jasper/world/worlddoc.hpp b/src/jasper/modules/world/include/jasper/world/worlddoc.hpp index 4b518c1..7e7e8ea 100644 --- a/src/jasper/modules/world/include/jasper/world/worlddoc.hpp +++ b/src/jasper/modules/world/include/jasper/world/worlddoc.hpp @@ -89,7 +89,7 @@ struct WorldDoc { [[nodiscard]] constexpr ox::Result objectSetPath(WorldDoc const&wd, uint64_t setId) noexcept { - auto obj = ox::find_if(wd.objSets.begin(), wd.objSets.end(), [setId](ObjectSetEntry const&e) { + auto const obj = ox::find_if(wd.objSets.begin(), wd.objSets.end(), [setId](ObjectSetEntry const&e) { return e.id == setId; }); oxReturnError(OxError(obj == wd.objSets.end(), "Obj set not found")); @@ -98,7 +98,7 @@ constexpr ox::Result objectSetPath(WorldDoc const&wd, uint64_t setId [[nodiscard]] constexpr ox::Result objectSetId(WorldDoc const&wd, ox::StringView setPath) noexcept { - auto obj = ox::find_if(wd.objSets.begin(), wd.objSets.end(), [setPath](ObjectSetEntry const&e) { + auto const obj = ox::find_if(wd.objSets.begin(), wd.objSets.end(), [setPath](ObjectSetEntry const&e) { return e.path == setPath; }); oxReturnError(OxError(obj == wd.objSets.end(), "Obj set not found")); @@ -117,7 +117,9 @@ oxModelEnd() ObjectSetEntry const*objSetEntry(WorldDoc const&doc, size_t id) noexcept; [[nodiscard]] -auto &tile(ox::CommonRefWith auto &doc, size_t lyr, ox::Integer_c auto col, ox::Integer_c auto row) noexcept { +auto &tile( + ox::CommonRefWith auto &doc, size_t lyr, + ox::IntegerRange_c<500> auto col, ox::IntegerRange_c<500> auto row) noexcept { return doc.tiles[lyr][static_cast(row)][static_cast(col)]; } diff --git a/src/jasper/modules/world/include/jasper/world/worldstatic.hpp b/src/jasper/modules/world/include/jasper/world/worldstatic.hpp index b78b88b..53b30f6 100644 --- a/src/jasper/modules/world/include/jasper/world/worldstatic.hpp +++ b/src/jasper/modules/world/include/jasper/world/worldstatic.hpp @@ -113,7 +113,7 @@ ox::Result loadWorldStatic(ObjectCache const&objCache, WorldDoc con auto &tile( ox::CommonRefWith auto&ws, size_t lyr, - ox::Integer_c auto col, + ox::IntegerRange_c<500> auto col, ox::Integer_c auto row) noexcept { auto const idx = static_cast(row) * static_cast(ws.columns) + static_cast(col); return ws.map[lyr].tiles[idx]; diff --git a/src/jasper/modules/world/src/studio/worldeditor/commands/modifytiles.cpp b/src/jasper/modules/world/src/studio/worldeditor/commands/modifytiles.cpp index 257623c..3ccf854 100644 --- a/src/jasper/modules/world/src/studio/worldeditor/commands/modifytiles.cpp +++ b/src/jasper/modules/world/src/studio/worldeditor/commands/modifytiles.cpp @@ -2,6 +2,8 @@ * Copyright 2023 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved. */ +#include + #include "commands.hpp" #include "modifytiles.hpp" @@ -16,15 +18,11 @@ ModifyTilesCommand::ModifyTilesCommand( m_worldStatic(worldStatic), m_objCache(objCache), m_mods(std::move(mods)) { - bool noChanges = true; - for (auto const&mod : m_mods) { + auto const unchanged = [this](Mod const&mod) { auto const&docTile = tile(m_doc, mod.layer, mod.tileAddr.x, mod.tileAddr.y); - if (docTile.obj.worldObjectId != mod.objId || docTile.obj.worldObjectSetId != mod.setId) { - noChanges = false; - break; - } - } - if (noChanges) { + return docTile.obj.worldObjectId == mod.objId && docTile.obj.worldObjectSetId == mod.setId; + }; + if (ox::all_of(m_mods.begin(), m_mods.end(), unchanged)) { throw studio::NoChangesException(); } } @@ -51,4 +49,4 @@ void ModifyTilesCommand::swap() noexcept { } } -} \ No newline at end of file +}