[jasper/world] Cleanup
This commit is contained in:
parent
355f583382
commit
1988e785e6
@ -89,7 +89,7 @@ struct WorldDoc {
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Result<ox::String> 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<ox::String> objectSetPath(WorldDoc const&wd, uint64_t setId
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Result<uint64_t> 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<WorldDoc> auto &doc, size_t lyr, ox::Integer_c auto col, ox::Integer_c auto row) noexcept {
|
||||
auto &tile(
|
||||
ox::CommonRefWith<WorldDoc> auto &doc, size_t lyr,
|
||||
ox::IntegerRange_c<500> auto col, ox::IntegerRange_c<500> auto row) noexcept {
|
||||
return doc.tiles[lyr][static_cast<size_t>(row)][static_cast<size_t>(col)];
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ ox::Result<WorldStatic> loadWorldStatic(ObjectCache const&objCache, WorldDoc con
|
||||
auto &tile(
|
||||
ox::CommonRefWith<WorldStatic> 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<size_t>(row) * static_cast<size_t>(ws.columns) + static_cast<size_t>(col);
|
||||
return ws.map[lyr].tiles[idx];
|
||||
|
@ -2,6 +2,8 @@
|
||||
* Copyright 2023 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <ox/std/ranges.hpp>
|
||||
|
||||
#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 {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user