diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 5c56283a4..1e232ae00 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -24,7 +24,7 @@ If applicable, add screenshots to help explain your problem. **Desktop (please complete the following information):** - OS: [e.g. mac/linux/windows] - - Version [e.g. 1.2.14] + - Version [e.g. 1.2.15] **Additional context** Add any other context about the problem here. diff --git a/CMakeLists.txt b/CMakeLists.txt index 8da86ff7b..a1009f699 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10.0) -project(Griddly VERSION 1.2.14) +project(Griddly VERSION 1.2.15) set(BINARY ${CMAKE_PROJECT_NAME}) diff --git a/bindings/python.cpp b/bindings/python.cpp index 5661fd42a..67db38412 100644 --- a/bindings/python.cpp +++ b/bindings/python.cpp @@ -12,7 +12,7 @@ namespace griddly { PYBIND11_MODULE(python_griddly, m) { m.doc() = "Griddly python bindings"; - m.attr("version") = "1.2.14"; + m.attr("version") = "1.2.15"; #ifndef NDEBUG spdlog::set_level(spdlog::level::debug); diff --git a/docs/conf.py b/docs/conf.py index b04233283..a8ddff4fb 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,7 +22,7 @@ author = 'Chris Bamford' # The full version, including alpha/beta/rc tags -release = '1.2.14' +release = '1.2.15' # -- General configuration --------------------------------------------------- diff --git a/python/setup.py b/python/setup.py index 3e7da18ba..352e95cad 100644 --- a/python/setup.py +++ b/python/setup.py @@ -71,7 +71,7 @@ def griddly_package_data(config='Debug'): setup( name='griddly', - version="1.2.14", + version="1.2.15", author_email="chrisbam4d@gmail.com", description="Griddly Python Libraries", long_description=long_description, diff --git a/src/Griddly/Core/GDY/Actions/Direction.hpp b/src/Griddly/Core/GDY/Actions/Direction.hpp index d216aa521..2cc21c8db 100644 --- a/src/Griddly/Core/GDY/Actions/Direction.hpp +++ b/src/Griddly/Core/GDY/Actions/Direction.hpp @@ -62,7 +62,7 @@ class DiscreteOrientation { } } - float getAngleRadians() { + float getAngleRadians() const { switch (direction_) { case Direction::NONE: case Direction::UP: @@ -78,7 +78,7 @@ class DiscreteOrientation { } } - glm::ivec2 getUnitVector() { + glm::ivec2 getUnitVector() const { return unitVector_; } @@ -100,11 +100,11 @@ class DiscreteOrientation { } // If the current direction is DOWN and the input vector is "right" we return "left" etc.. - glm::ivec2 getRelativeUnitVector(glm::ivec2 vector) { + glm::ivec2 getRelativeUnitVector(glm::ivec2 vector) const { return vector * getRotationMatrix(); } - glm::imat2x2 getRotationMatrix() { + glm::imat2x2 getRotationMatrix() const { switch (direction_) { default: case Direction::NONE: @@ -119,10 +119,17 @@ class DiscreteOrientation { } } - Direction getDirection() { + Direction getDirection() const { return direction_; } + inline bool operator==(const DiscreteOrientation& other) const { + bool equal = direction_ == other.getDirection() && + unitVector_ == other.getUnitVector(); + + return equal; + } + private: glm::ivec2 unitVector_ = {0, 0}; Direction direction_ = Direction::NONE; diff --git a/src/Griddly/Core/GDY/Objects/Object.cpp b/src/Griddly/Core/GDY/Objects/Object.cpp index aa4d3de2e..f7577acf5 100644 --- a/src/Griddly/Core/GDY/Objects/Object.cpp +++ b/src/Griddly/Core/GDY/Objects/Object.cpp @@ -729,6 +729,10 @@ void Object::setRenderTileId(uint32_t renderTileId) { renderTileId_ = renderTileId; } +uint32_t Object::getRenderTileId() const { + return renderTileId_; +} + void Object::removeObject() { grid_->removeObject(shared_from_this()); } diff --git a/src/Griddly/Core/GDY/Objects/Object.hpp b/src/Griddly/Core/GDY/Objects/Object.hpp index 2584055cc..590cb98a3 100644 --- a/src/Griddly/Core/GDY/Objects/Object.hpp +++ b/src/Griddly/Core/GDY/Objects/Object.hpp @@ -94,6 +94,10 @@ class Object : public std::enable_shared_from_this { virtual bool isPlayerAvatar() const; + virtual void setRenderTileId(uint32_t renderTileId); + + virtual uint32_t getRenderTileId() const; + virtual void markAsPlayerAvatar(); // Set this object as a player avatar virtual bool isValidAction(std::shared_ptr action) const; @@ -158,8 +162,6 @@ class Object : public std::enable_shared_from_this { virtual bool moveObject(glm::ivec2 newLocation); - virtual void setRenderTileId(uint32_t renderTileId); - virtual void removeObject(); SingleInputMapping getInputMapping(std::string actionName, uint32_t actionId, bool randomize, InputMapping fallback); diff --git a/src/Griddly/Core/GDY/Objects/ObjectGenerator.cpp b/src/Griddly/Core/GDY/Objects/ObjectGenerator.cpp index c8af91f2d..f43934a30 100644 --- a/src/Griddly/Core/GDY/Objects/ObjectGenerator.cpp +++ b/src/Griddly/Core/GDY/Objects/ObjectGenerator.cpp @@ -92,6 +92,7 @@ std::shared_ptr ObjectGenerator::cloneInstance(std::shared_ptr t } } + auto objectZIdx = objectDefinition->zIdx; auto mapCharacter = objectDefinition->mapCharacter; auto initializedObject = std::shared_ptr(new Object(objectName, mapCharacter, playerId, objectZIdx, availableVariables, shared_from_this(), grid)); @@ -100,6 +101,9 @@ std::shared_ptr ObjectGenerator::cloneInstance(std::shared_ptr t initializedObject->markAsPlayerAvatar(); } + initializedObject->setRenderTileId(toClone->getRenderTileId()); + + for (auto &actionBehaviourDefinition : objectDefinition->actionBehaviourDefinitions) { switch (actionBehaviourDefinition.behaviourType) { case ActionBehaviourType::SOURCE: diff --git a/src/Griddly/Core/Grid.cpp b/src/Griddly/Core/Grid.cpp index 23b2cdf5b..d0820e616 100644 --- a/src/Griddly/Core/Grid.cpp +++ b/src/Griddly/Core/Grid.cpp @@ -526,7 +526,7 @@ std::shared_ptr Grid::getPlayerDefaultObject(uint32_t playerId) const { return defaultObject_.at(playerId); } -void Grid::addObject(glm::ivec2 location, std::shared_ptr object, bool applyInitialActions, std::shared_ptr originatingAction) { +void Grid::addObject(glm::ivec2 location, std::shared_ptr object, bool applyInitialActions, std::shared_ptr originatingAction, DiscreteOrientation orientation) { auto objectName = object->getObjectName(); auto playerId = object->getPlayerId(); @@ -540,7 +540,7 @@ void Grid::addObject(glm::ivec2 location, std::shared_ptr object, bool a auto canAddObject = objects_.insert(object).second; if (canAddObject) { - object->init(location); + object->init(location, orientation); auto objectZIdx = object->getZIdx(); auto& objectsAtLocation = occupiedLocations_[location]; diff --git a/src/Griddly/Core/Grid.hpp b/src/Griddly/Core/Grid.hpp index 746e83921..3a1bc0839 100644 --- a/src/Griddly/Core/Grid.hpp +++ b/src/Griddly/Core/Grid.hpp @@ -100,7 +100,7 @@ class Grid : public std::enable_shared_from_this { virtual void initObject(std::string objectName, std::vector objectVariableNames); - virtual void addObject(glm::ivec2 location, std::shared_ptr object, bool applyInitialActions = true, std::shared_ptr originatingAction = nullptr); + virtual void addObject(glm::ivec2 location, std::shared_ptr object, bool applyInitialActions = true, std::shared_ptr originatingAction = nullptr, DiscreteOrientation orientation=DiscreteOrientation()); virtual bool removeObject(std::shared_ptr object); diff --git a/src/Griddly/Core/TurnBasedGameProcess.cpp b/src/Griddly/Core/TurnBasedGameProcess.cpp index 11a3d3f44..75e3cdc0c 100644 --- a/src/Griddly/Core/TurnBasedGameProcess.cpp +++ b/src/Griddly/Core/TurnBasedGameProcess.cpp @@ -133,7 +133,7 @@ std::shared_ptr TurnBasedGameProcess::clone() { auto& objectsToCopy = grid_->getObjects(); for (const auto& toCopy : objectsToCopy) { auto clonedObject = objectGenerator->cloneInstance(toCopy, clonedGrid); - clonedGrid->addObject(toCopy->getLocation(), clonedObject, false); + clonedGrid->addObject(toCopy->getLocation(), clonedObject, false, nullptr, toCopy->getObjectOrientation()); // We need to know which objects are equivalent in the grid so we can // map delayed actions later diff --git a/tests/src/Griddly/Core/GDY/GDYFactoryTest.cpp b/tests/src/Griddly/Core/GDY/GDYFactoryTest.cpp index 8ec84dd0b..f634ce2fe 100644 --- a/tests/src/Griddly/Core/GDY/GDYFactoryTest.cpp +++ b/tests/src/Griddly/Core/GDY/GDYFactoryTest.cpp @@ -4,6 +4,7 @@ #include #include +#include "Griddly/Core/TestUtils/common.hpp" #include "Griddly/Core/GDY/Actions/Action.hpp" #include "Griddly/Core/GDY/GDYFactory.hpp" #include "Mocks//Griddly/Core/LevelGenerators/MockLevelGenerator.hpp" @@ -537,32 +538,6 @@ TEST(GDYFactoryTest, load_object_initial_actions) { EXPECT_TRUE(Mock::VerifyAndClearExpectations(mockObjectGeneratorPtr.get())); } -bool commandArgumentsEqual(BehaviourCommandArguments a, BehaviourCommandArguments b) { - for (auto it = a.begin(); it != a.end(); ++it) { - auto key = it->first; - auto node = it->second; - - if (node.Type() != b[key].Type()) { - return false; - } - } - return true; -} - -//! the comparison here is not comparing the values of the YAML but just the types. Its not perfect. -MATCHER_P(ActionBehaviourDefinitionEqMatcher, behaviour, "") { - auto isEqual = behaviour.behaviourType == arg.behaviourType && - behaviour.sourceObjectName == arg.sourceObjectName && - behaviour.destinationObjectName == arg.destinationObjectName && - behaviour.actionName == arg.actionName && - behaviour.commandName == arg.commandName && - commandArgumentsEqual(behaviour.commandArguments, arg.commandArguments); - //behaviour.actionPreconditions == arg.actionPreconditions && - //behaviour.conditionalCommands == arg.conditionalCommands; - - return isEqual; -} - void expectOpposingDefinitionNOP(ActionBehaviourType behaviourType, std::string sourceObjectName, std::string destinationObjectName, std::shared_ptr mockObjectGeneratorPtr) { ActionBehaviourDefinition expectedNOPDefinition = GDYFactory::makeBehaviourDefinition( behaviourType == ActionBehaviourType::DESTINATION ? ActionBehaviourType::SOURCE : ActionBehaviourType::DESTINATION, diff --git a/tests/src/Griddly/Core/GDY/Objects/ObjectGeneratorTest.cpp b/tests/src/Griddly/Core/GDY/Objects/ObjectGeneratorTest.cpp new file mode 100644 index 000000000..2efdcce88 --- /dev/null +++ b/tests/src/Griddly/Core/GDY/Objects/ObjectGeneratorTest.cpp @@ -0,0 +1,75 @@ +#include + +#include "Griddly/Core/TestUtils/common.hpp" +#include "Griddly/Core/GDY/Objects/Object.hpp" +#include "Griddly/Core/GDY/Objects/ObjectGenerator.hpp" +#include "Mocks/Griddly/Core/GDY/Actions/MockAction.hpp" +#include "Mocks/Griddly/Core/MockGrid.hpp" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using ::testing::_; +using ::testing::ElementsAre; +using ::testing::Eq; +using ::testing::Invoke; +using ::testing::Mock; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::UnorderedElementsAre; + +#define _V(X) std::make_shared(X) +#define _Y(X) YAML::Node(X) + +namespace griddly { +TEST(ObjectGeneratorTest, cloneInstance) { + std::string objectAName = "objectA"; + std::string objectBName = "objectB"; + DiscreteOrientation orientation = DiscreteOrientation(Direction::RIGHT); + glm::ivec2 location = {4, 5}; + char mapCharacter = 'A'; + uint32_t zIdx = 1; + + ActionBehaviourDefinition mockBehaviourDefinition; + + mockBehaviourDefinition.behaviourType = ActionBehaviourType::SOURCE; + mockBehaviourDefinition.sourceObjectName = objectAName; + mockBehaviourDefinition.destinationObjectName = objectBName; + mockBehaviourDefinition.actionName = "actionA"; + mockBehaviourDefinition.commandName = "eq"; + mockBehaviourDefinition.commandArguments = {{"0", _Y("0")}, {"1", _Y("10")}}; + mockBehaviourDefinition.actionPreconditions = {{"eq", {{"0", _Y("0")}, {"1", _Y("1")}}}, {"eq", {{"0", _Y("1")}, {"1", _Y("0")}}}}; + mockBehaviourDefinition.conditionalCommands = {{"reward", {{"0", _Y("1")}}}}; + mockBehaviourDefinition.executionProbability = 0.4; + + auto mockObjectPtr = mockObject(objectAName, mapCharacter, 1, zIdx, location, orientation, {"actionA"}, {{"variable1", _V(10)}, {"variable2", _V(20)}}); + + EXPECT_CALL(*mockObjectPtr, getRenderTileId).WillOnce(Return(4)); + + auto mockGridPtr = std::shared_ptr(new MockGrid()); + + std::unordered_map>> globalVariables = { + {"globalVariable1", {{0, _V(1)}}}, + {"globalVariable2", {{0, _V(1)},{1, _V(2)}}}, + }; + + EXPECT_CALL(*mockGridPtr, getGlobalVariables()).WillOnce(ReturnRef(globalVariables)); + + auto objectGenerator = std::shared_ptr(new ObjectGenerator()); + + objectGenerator->setAvatarObject(objectAName); + objectGenerator->defineNewObject(objectAName, mapCharacter, zIdx, {{"variable1", 0}, {"variable2", 0}}); + objectGenerator->defineActionBehaviour(objectAName, mockBehaviourDefinition); + + auto clonedObject = objectGenerator->cloneInstance(mockObjectPtr, mockGridPtr); + + ASSERT_EQ(clonedObject->getObjectName(), objectAName); + //ASSERT_EQ(clonedObject->getLocation(), location); // At this point the object has not been added to the grid, so it does not have a location or orientation + //ASSERT_EQ(clonedObject->getObjectOrientation().getDirection(), orientation.getDirection()); + ASSERT_EQ(clonedObject->getZIdx(), zIdx); + ASSERT_EQ(clonedObject->getMapCharacter(), mapCharacter); + ASSERT_EQ(clonedObject->getObjectRenderTileName(), objectAName+"4"); + ASSERT_EQ(clonedObject->isPlayerAvatar(), true); + ASSERT_THAT(clonedObject->getAvailableActionNames(), UnorderedElementsAre("actionA")); + +} +} // namespace griddly \ No newline at end of file diff --git a/tests/src/Griddly/Core/GDY/Objects/ObjectTest.cpp b/tests/src/Griddly/Core/GDY/Objects/ObjectTest.cpp index a4ff3b237..5e52f2437 100644 --- a/tests/src/Griddly/Core/GDY/Objects/ObjectTest.cpp +++ b/tests/src/Griddly/Core/GDY/Objects/ObjectTest.cpp @@ -1158,13 +1158,13 @@ TEST(ObjectTest, command_change_to) { EXPECT_CALL(*mockGridPtr, removeObject(Eq(srcObjectPtr))) .Times(1) .WillOnce(Return(true)); - EXPECT_CALL(*mockGridPtr, addObject(Eq(glm::ivec2(0, 0)), Eq(newObjectPtr), Eq(true), Eq(mockActionPtr))) + EXPECT_CALL(*mockGridPtr, addObject(Eq(glm::ivec2(0, 0)), Eq(newObjectPtr), Eq(true), Eq(mockActionPtr), Eq(DiscreteOrientation()))) .Times(1); EXPECT_CALL(*mockGridPtr, removeObject(Eq(dstObjectPtr))) .Times(1) .WillOnce(Return(true)); - EXPECT_CALL(*mockGridPtr, addObject(Eq(glm::ivec2(1, 0)), Eq(newObjectPtr), Eq(true), Eq(mockActionPtr))) + EXPECT_CALL(*mockGridPtr, addObject(Eq(glm::ivec2(1, 0)), Eq(newObjectPtr), Eq(true), Eq(mockActionPtr), Eq(DiscreteOrientation()))) .Times(1); auto srcResult = addCommandsAndExecute(ActionBehaviourType::SOURCE, mockActionPtr, "change_to", {{"0", _Y("newObject")}}, srcObjectPtr, dstObjectPtr); @@ -1229,7 +1229,7 @@ TEST(ObjectTest, command_spawn) { EXPECT_CALL(*mockObjectGenerator, newInstance(Eq("newObject"), Eq(1), Eq(mockGridPtr))) .WillOnce(Return(newObjectPtr)); - EXPECT_CALL(*mockGridPtr, addObject(Eq(glm::ivec2(1, 0)), Eq(newObjectPtr), Eq(true), Eq(mockActionPtr))) + EXPECT_CALL(*mockGridPtr, addObject(Eq(glm::ivec2(1, 0)), Eq(newObjectPtr), Eq(true), Eq(mockActionPtr), Eq(DiscreteOrientation()))) .Times(1); auto srcResult = addCommandsAndExecute(ActionBehaviourType::SOURCE, mockActionPtr, "spawn", {{"0", _Y("newObject")}}, srcObjectPtr, nullptr); diff --git a/tests/src/Griddly/Core/GridTest.cpp b/tests/src/Griddly/Core/GridTest.cpp index 23c347f83..ff93ee859 100644 --- a/tests/src/Griddly/Core/GridTest.cpp +++ b/tests/src/Griddly/Core/GridTest.cpp @@ -643,7 +643,7 @@ TEST(GridTest, objectCounters) { auto mockObject = std::shared_ptr(new MockObject()); glm::ivec2 location = {(int32_t)p, (int32_t)o}; - EXPECT_CALL(*mockObject, init).Times(1); + EXPECT_CALL(*mockObject, init(Eq(location), _)).Times(1); EXPECT_CALL(*mockObject, getZIdx).WillRepeatedly(Return(0)); EXPECT_CALL(*mockObject, getLocation).WillRepeatedly(Return(location)); diff --git a/tests/src/Griddly/Core/LevelGenerator/MapReaderTest.cpp b/tests/src/Griddly/Core/LevelGenerator/MapReaderTest.cpp index 3a02e9c0e..fe0345390 100644 --- a/tests/src/Griddly/Core/LevelGenerator/MapReaderTest.cpp +++ b/tests/src/Griddly/Core/LevelGenerator/MapReaderTest.cpp @@ -81,10 +81,10 @@ TEST(MapGeneratorTest, testLoadStringWithPlayerObjects) { EXPECT_CALL(*mockGridPtr, resetMap(Eq(3), Eq(3))) .Times(1); - EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr))) + EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation()))) .Times(8); - EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr))) + EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation()))) .Times(1); std::string levelString = "W W W\nW P1 W\nW W W"; @@ -150,10 +150,10 @@ TEST(MapGeneratorTest, testLoadStringWithPlayerObjectsRandomWhitespace) { EXPECT_CALL(*mockGridPtr, resetMap(Eq(3), Eq(3))) .Times(1); - EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr))) + EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation()))) .Times(8); - EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr))) + EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation()))) .Times(1); std::string levelString = "W W W \nW P1 W\t\nW\tW\tW\n"; @@ -219,10 +219,10 @@ TEST(MapGeneratorTest, testLoadStringNoSpaces) { EXPECT_CALL(*mockGridPtr, resetMap(Eq(3), Eq(3))) .Times(1); - EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr))) + EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation()))) .Times(8); - EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr))) + EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation()))) .Times(1); std::string levelString = "WWW\nWP1W\nWWW"; auto levelStringStream = std::stringstream(levelString); @@ -287,10 +287,10 @@ TEST(MapGeneratorTest, testLoadStringNoSpacesWithDots) { EXPECT_CALL(*mockGridPtr, resetMap(Eq(5), Eq(3))) .Times(1); - EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr))) + EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation()))) .Times(12); - EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr))) + EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation()))) .Times(1); std::string levelString = "WWWWW\nW.P1.W\nWWWWW"; auto levelStringStream = std::stringstream(levelString); @@ -371,13 +371,13 @@ TEST(MapGeneratorTest, testLoadStringMultipleOccupants) { EXPECT_CALL(*mockGridPtr, resetMap(Eq(5), Eq(3))) .Times(1); - EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr))) + EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation()))) .Times(12); - EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr))) + EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation()))) .Times(1); - EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockFloorObject), Eq(true), Eq(nullptr))) + EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockFloorObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation()))) .Times(1); std::string levelString = "W W W W W\nW . P1/F . W\n W W W W W"; diff --git a/tests/src/Griddly/Core/TestUtils/common.hpp b/tests/src/Griddly/Core/TestUtils/common.hpp index d512477cd..419143038 100644 --- a/tests/src/Griddly/Core/TestUtils/common.hpp +++ b/tests/src/Griddly/Core/TestUtils/common.hpp @@ -28,6 +28,10 @@ std::shared_ptr static mockObject(std::string objectName = "object", EXPECT_CALL(*mockObjectPtr, getAvailableVariables()).WillRepeatedly(Return(availableVariables)); EXPECT_CALL(*mockObjectPtr, getAvailableActionNames()).WillRepeatedly(Return(availableActionNames)); + for(auto variable : availableVariables) { + EXPECT_CALL(*mockObjectPtr, getVariableValue(Eq(variable.first))).WillRepeatedly(Return(variable.second)); + } + return mockObjectPtr; } @@ -76,4 +80,47 @@ std::shared_ptr static mockAction(std::string actionName, std::share return mockActionPtr; } +bool static commandArgumentsEqual(BehaviourCommandArguments a, BehaviourCommandArguments b) { + for (auto it = a.begin(); it != a.end(); ++it) { + auto key = it->first; + auto node = it->second; + + if (node.Type() != b[key].Type()) { + return false; + } + } + return true; +} + +bool static commandListEqual(std::vector> a, std::vector> b) { + + for(int i = 0; i, getVariableValue, (std::string variableName), ()); + MOCK_METHOD(std::vector>, getInitialActions, (std::shared_ptr originatingAction), ()); MOCK_METHOD(bool, isValidAction, (std::shared_ptr action), (const)); diff --git a/tests/src/Mocks/Griddly/Core/MockGrid.hpp b/tests/src/Mocks/Griddly/Core/MockGrid.hpp index a32903383..f0c28577b 100644 --- a/tests/src/Mocks/Griddly/Core/MockGrid.hpp +++ b/tests/src/Mocks/Griddly/Core/MockGrid.hpp @@ -25,7 +25,7 @@ class MockGrid : public Grid { MOCK_METHOD((std::unordered_map), performActions, (uint32_t playerId, std::vector> actions), ()); MOCK_METHOD(void, initObject, (std::string, std::vector), ()); - MOCK_METHOD(void, addObject, (glm::ivec2 location, std::shared_ptr object, bool applyInitialActions, std::shared_ptr originatingAction), ()); + MOCK_METHOD(void, addObject, (glm::ivec2 location, std::shared_ptr object, bool applyInitialActions, std::shared_ptr originatingAction, DiscreteOrientation orientation), ()); MOCK_METHOD(void, addPlayerDefaultObject, (std::shared_ptr object)); MOCK_METHOD(std::shared_ptr, getPlayerDefaultObject, (uint32_t playerId), (const)); MOCK_METHOD(bool, removeObject, (std::shared_ptr object), ());