Merge pull request #76 from Kilkenni/player-bindings-return-values

return values for bookmark Lua callbacks
This commit is contained in:
Kae 2024-07-02 22:37:55 +10:00 committed by GitHub
commit 4b0d1cb90d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 17 deletions

View File

@ -71,30 +71,30 @@ List<pair<Vec3I, OrbitBookmark>> PlayerUniverseMap::orbitBookmarks() const {
return bookmarks; return bookmarks;
} }
void PlayerUniverseMap::addOrbitBookmark(CelestialCoordinate const& system, OrbitBookmark const& bookmark) { bool PlayerUniverseMap::addOrbitBookmark(CelestialCoordinate const& system, OrbitBookmark const& bookmark) {
if (system.isNull()) if (system.isNull())
throw StarException("Cannot add orbit bookmark to null system"); throw StarException("Cannot add orbit bookmark to null system");
m_universeMaps[*m_serverUuid].systems[system.location()].bookmarks.add(std::move(bookmark)); return m_universeMaps[*m_serverUuid].systems[system.location()].bookmarks.add(std::move(bookmark));
} }
void PlayerUniverseMap::removeOrbitBookmark(CelestialCoordinate const& system, OrbitBookmark const& bookmark) { bool PlayerUniverseMap::removeOrbitBookmark(CelestialCoordinate const& system, OrbitBookmark const& bookmark) {
if (system.isNull()) if (system.isNull())
throw StarException("Cannot remove orbit bookmark from null system"); throw StarException("Cannot remove orbit bookmark from null system");
m_universeMaps[*m_serverUuid].systems[system.location()].bookmarks.remove(bookmark); return m_universeMaps[*m_serverUuid].systems[system.location()].bookmarks.remove(bookmark);
} }
List<TeleportBookmark> PlayerUniverseMap::teleportBookmarks() const { List<TeleportBookmark> PlayerUniverseMap::teleportBookmarks() const {
return universeMap().teleportBookmarks.values(); return universeMap().teleportBookmarks.values();
} }
void PlayerUniverseMap::addTeleportBookmark(TeleportBookmark bookmark) { bool PlayerUniverseMap::addTeleportBookmark(TeleportBookmark bookmark) {
m_universeMaps[*m_serverUuid].teleportBookmarks.add(std::move(bookmark)); return m_universeMaps[*m_serverUuid].teleportBookmarks.add(std::move(bookmark));
} }
void PlayerUniverseMap::removeTeleportBookmark(TeleportBookmark const& bookmark) { bool PlayerUniverseMap::removeTeleportBookmark(TeleportBookmark const& bookmark) {
m_universeMaps[*m_serverUuid].teleportBookmarks.remove(bookmark); return m_universeMaps[*m_serverUuid].teleportBookmarks.remove(bookmark);
} }
void PlayerUniverseMap::invalidateWarpAction(WarpAction const& warpAction) { void PlayerUniverseMap::invalidateWarpAction(WarpAction const& warpAction) {

View File

@ -53,12 +53,12 @@ public:
// pair of system location and bookmark, not all orbit bookmarks include the system // pair of system location and bookmark, not all orbit bookmarks include the system
List<pair<Vec3I, OrbitBookmark>> orbitBookmarks() const; List<pair<Vec3I, OrbitBookmark>> orbitBookmarks() const;
void addOrbitBookmark(CelestialCoordinate const& system, OrbitBookmark const& bookmark); bool addOrbitBookmark(CelestialCoordinate const& system, OrbitBookmark const& bookmark);
void removeOrbitBookmark(CelestialCoordinate const& system, OrbitBookmark const& bookmark); bool removeOrbitBookmark(CelestialCoordinate const& system, OrbitBookmark const& bookmark);
List<TeleportBookmark> teleportBookmarks() const; List<TeleportBookmark> teleportBookmarks() const;
void addTeleportBookmark(TeleportBookmark bookmark); bool addTeleportBookmark(TeleportBookmark bookmark);
void removeTeleportBookmark(TeleportBookmark const& bookmark); bool removeTeleportBookmark(TeleportBookmark const& bookmark);
void invalidateWarpAction(WarpAction const& bookmark); void invalidateWarpAction(WarpAction const& bookmark);
Maybe<OrbitBookmark> worldBookmark(CelestialCoordinate const& world) const; Maybe<OrbitBookmark> worldBookmark(CelestialCoordinate const& world) const;

View File

@ -594,12 +594,12 @@ LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) {
}); });
}); });
callbacks.registerCallback("addOrbitBookmark", [player](Json const& system, Json const& bookmarkConfig) { callbacks.registerCallback("addOrbitBookmark", [player](Json const& system, Json const& bookmarkConfig) -> bool {
CelestialCoordinate coordinate = CelestialCoordinate(system); CelestialCoordinate coordinate = CelestialCoordinate(system);
return player->universeMap()->addOrbitBookmark(coordinate, OrbitBookmark::fromJson(bookmarkConfig)); return player->universeMap()->addOrbitBookmark(coordinate, OrbitBookmark::fromJson(bookmarkConfig));
}); });
callbacks.registerCallback("removeOrbitBookmark", [player](Json const& system, Json const& bookmarkConfig) { callbacks.registerCallback("removeOrbitBookmark", [player](Json const& system, Json const& bookmarkConfig) -> bool {
CelestialCoordinate coordinate = CelestialCoordinate(system); CelestialCoordinate coordinate = CelestialCoordinate(system);
return player->universeMap()->removeOrbitBookmark(coordinate, OrbitBookmark::fromJson(bookmarkConfig)); return player->universeMap()->removeOrbitBookmark(coordinate, OrbitBookmark::fromJson(bookmarkConfig));
}); });
@ -610,12 +610,12 @@ LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) {
}); });
}); });
callbacks.registerCallback("addTeleportBookmark", [player](Json const& bookmarkConfig) { callbacks.registerCallback("addTeleportBookmark", [player](Json const& bookmarkConfig) -> bool {
return player->universeMap()->addTeleportBookmark(TeleportBookmark::fromJson(bookmarkConfig)); return player->universeMap()->addTeleportBookmark(TeleportBookmark::fromJson(bookmarkConfig));
}); });
callbacks.registerCallback("removeTeleportBookmark", [player](Json const& bookmarkConfig) { callbacks.registerCallback("removeTeleportBookmark", [player](Json const& bookmarkConfig) -> bool {
player->universeMap()->removeTeleportBookmark(TeleportBookmark::fromJson(bookmarkConfig)); return player->universeMap()->removeTeleportBookmark(TeleportBookmark::fromJson(bookmarkConfig));
}); });
callbacks.registerCallback("isMapped", [player](Json const& coords) { callbacks.registerCallback("isMapped", [player](Json const& coords) {