From f62875e6e726547e769b1972ba30b556765298cd Mon Sep 17 00:00:00 2001 From: David Bloomin Date: Tue, 13 Feb 2024 13:58:45 -0800 Subject: [PATCH 01/10] sort variableNames to provide consistent observations --- src/Griddly/Core/Grid.cpp | 6 +++++- src/Griddly/Core/Grid.hpp | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Griddly/Core/Grid.cpp b/src/Griddly/Core/Grid.cpp index c15b26fd..427dcce5 100644 --- a/src/Griddly/Core/Grid.cpp +++ b/src/Griddly/Core/Grid.cpp @@ -497,6 +497,10 @@ void Grid::initObject(std::string objectName, std::vector variableN objectCounters_.insert({objectName, {{0, std::make_shared(0)}}}); for (auto& variableName : variableNames) { + objectVariables_.insert(variableName); + } + objectVariableMap_.clear(); + for (auto& variableName : objectVariables_) { objectVariableIds_.insert({variableName, objectVariableIds_.size()}); } @@ -739,4 +743,4 @@ const std::unordered_map>& Grid::ge return collisionObjectActionNames_; } -} // namespace griddly \ No newline at end of file +} // namespace griddly diff --git a/src/Griddly/Core/Grid.hpp b/src/Griddly/Core/Grid.hpp index c3ad8b3f..21b996e2 100644 --- a/src/Griddly/Core/Grid.hpp +++ b/src/Griddly/Core/Grid.hpp @@ -110,7 +110,7 @@ class Grid : public std::enable_shared_from_this { virtual const std::unordered_set>& getObjects(); virtual void addPlayerDefaultEmptyObject(std::shared_ptr emptyObject); - + virtual void addPlayerDefaultBoundaryObject(std::shared_ptr boundaryObject); virtual std::shared_ptr getPlayerDefaultEmptyObject(uint32_t playerId) const; @@ -199,6 +199,7 @@ class Grid : public std::enable_shared_from_this { std::vector> updatedLocations_; std::unordered_map objectIds_; + std::set objectVariables_; std::unordered_map objectVariableIds_; std::unordered_map> objectVariableMap_; std::unordered_set> objects_; @@ -248,4 +249,4 @@ class Grid : public std::enable_shared_from_this { std::shared_ptr randomGenerator_ = std::make_shared(RandomGenerator()); }; -} // namespace griddly \ No newline at end of file +} // namespace griddly From 76c15ff474f84a502b995045f15b0f78763e1ad7 Mon Sep 17 00:00:00 2001 From: David Bloomin Date: Sun, 10 Mar 2024 21:09:38 -0700 Subject: [PATCH 02/10] add keyboard bindings --- js/griddlyjs-app/package-lock.json | 2 +- .../src/renderer/Sprite2DRenderer.js | 13 +++- .../level_player/scenes/HumanPlayerScene.js | 69 +++++++++++++------ resources/games/RTS/Stratega/heal-or-die.yaml | 4 +- 4 files changed, 61 insertions(+), 27 deletions(-) diff --git a/js/griddlyjs-app/package-lock.json b/js/griddlyjs-app/package-lock.json index 23a1994d..17f4b4a0 100644 --- a/js/griddlyjs-app/package-lock.json +++ b/js/griddlyjs-app/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "griddlyjs-app", - "version": "1.6.3", + "version": "1.6.7", "dependencies": { "@fortawesome/fontawesome-svg-core": "^6.1.1", "@fortawesome/free-brands-svg-icons": "^6.1.1", diff --git a/js/griddlyjs-app/src/renderer/Sprite2DRenderer.js b/js/griddlyjs-app/src/renderer/Sprite2DRenderer.js index 16333e75..a97168cf 100644 --- a/js/griddlyjs-app/src/renderer/Sprite2DRenderer.js +++ b/js/griddlyjs-app/src/renderer/Sprite2DRenderer.js @@ -123,7 +123,7 @@ class Sprite2DRenderer extends RendererBase { sprite.setDisplaySize( this.renderConfig.TileSize, - this.renderConfig.TileSize + this.renderConfig.TileSize ); } @@ -141,7 +141,12 @@ class Sprite2DRenderer extends RendererBase { if (!sprite) { return; } - const objectTemplate = this.objectTemplates[objectTemplateName]; + var objectTemplate = this.objectTemplates[objectTemplateName]; + if (!objectTemplate) { + // pick the first one + objectTemplate = this.objectTemplates[Object.keys(this.objectTemplates)[0]]; + } + sprite.setPosition(this.getCenteredX(x), this.getCenteredY(y)); sprite.setTexture(this.getTilingImage(objectTemplate, x, y)); @@ -228,6 +233,10 @@ class Sprite2DRenderer extends RendererBase { }; getTilingImage = (objectTemplate, x, y) => { + if (objectTemplate === undefined) { + console.log("Undefined object template"); + }; + if (objectTemplate.tilingMode === "WALL_16") { const objectLeft = this.tileLocations.get( this.getObjectLocationKey(x - 1, y) diff --git a/js/griddlyjs-app/src/renderer/level_player/scenes/HumanPlayerScene.js b/js/griddlyjs-app/src/renderer/level_player/scenes/HumanPlayerScene.js index 050f6cde..6189df36 100644 --- a/js/griddlyjs-app/src/renderer/level_player/scenes/HumanPlayerScene.js +++ b/js/griddlyjs-app/src/renderer/level_player/scenes/HumanPlayerScene.js @@ -454,12 +454,57 @@ class HumanPlayerScene extends Phaser.Scene { this.keyMap = new Map(); + const mapKeyToAction = (key, actionName, actionTypeId, actionId, mapping) => { + const mappedKey = this.input.keyboard.addKey(key, false); + mappedKey.on("down", this.processUserKeydown); + mappedKey.on("up", this.processUserKeyup); + + this.keyMap.set(key, { + actionName, + actionTypeId, + actionId, + description: mapping.description, + }); + }; + + const presetActionKeys = { + "move": [ Phaser.Input.Keyboard.KeyCodes.E, Phaser.Input.Keyboard.KeyCodes.R ], + "rotate": [ Phaser.Input.Keyboard.KeyCodes.S, Phaser.Input.Keyboard.KeyCodes.A, + Phaser.Input.Keyboard.KeyCodes.D, Phaser.Input.Keyboard.KeyCodes.W ], + "pickup": [ Phaser.Input.Keyboard.KeyCodes.Y ], + "use": [ Phaser.Input.Keyboard.KeyCodes.U ], + "shield": [ Phaser.Input.Keyboard.KeyCodes.O ], + "prestige": [ Phaser.Input.Keyboard.KeyCodes.PLUS ], + "attack": [ Phaser.Input.Keyboard.KeyCodes.NUMPAD_ONE, + Phaser.Input.Keyboard.KeyCodes.NUMPAD_TWO, + Phaser.Input.Keyboard.KeyCodes.NUMPAD_THREE, + Phaser.Input.Keyboard.KeyCodes.NUMPAD_FOUR, + Phaser.Input.Keyboard.KeyCodes.NUMPAD_FIVE, + Phaser.Input.Keyboard.KeyCodes.NUMPAD_SIX, + Phaser.Input.Keyboard.KeyCodes.NUMPAD_SEVEN, + Phaser.Input.Keyboard.KeyCodes.NUMPAD_EIGHT, + Phaser.Input.Keyboard.KeyCodes.NUMPAD_NINE, + ] + }; + actionNames.forEach((actionName, actionTypeId) => { const actionMapping = actionInputMappings[actionName]; if (!actionMapping.internal) { const inputMappings = Object.entries(actionMapping.inputMappings); console.log(inputMappings); + // If the action is one of the preset actions, use the preset keys + if (actionName in presetActionKeys) { + const keys = presetActionKeys[actionName]; + inputMappings.forEach((inputMapping) => { + const actionId = Number(inputMapping[0]); + const key = keys[actionId - 1]; + const mapping = inputMapping[1]; + mapKeyToAction(key, actionName, actionTypeId, actionId, mapping); + }); + return; + } + const actionDirections = new Set(); inputMappings.forEach((inputMapping) => { // check that all the vectorToDest are different @@ -485,36 +530,16 @@ class HumanPlayerScene extends Phaser.Scene { key = movementKeys[this.toMovementKey(mapping.orientationVector)]; } - const mappedKey = this.input.keyboard.addKey(key, false); - mappedKey.on("down", this.processUserKeydown); - mappedKey.on("up", this.processUserKeyup); - - this.keyMap.set(key, { - actionName, - actionTypeId, - actionId, - description: mapping.description, - }); + mapKeyToAction(key, actionName, actionTypeId, actionId, mapping); }); } else { // We have an action Key - inputMappings.forEach((inputMapping) => { const key = actionKeyOrder.pop(); const actionId = Number(inputMapping[0]); const mapping = inputMapping[1]; - - const mappedKey = this.input.keyboard.addKey(key, false); - mappedKey.on("down", this.processUserKeydown); - mappedKey.on("up", this.processUserKeyup); - - this.keyMap.set(key, { - actionName, - actionTypeId, - actionId, - description: mapping.description, - }); + mapKeyToAction(key, actionName, actionTypeId, actionId, mapping); }); } } diff --git a/resources/games/RTS/Stratega/heal-or-die.yaml b/resources/games/RTS/Stratega/heal-or-die.yaml index ede044a4..96e63f45 100644 --- a/resources/games/RTS/Stratega/heal-or-die.yaml +++ b/resources/games/RTS/Stratega/heal-or-die.yaml @@ -2,8 +2,8 @@ Version: "0.1" Environment: Name: Heal Or Die Description: | - Game environment ported from https://github.com/GAIGResearch/Stratega. - You have units that heal and units that perform close combat. + Game environment ported from https://github.com/GAIGResearch/Stratega. + You have units that heal and units that perform close combat. Additionally, on every turn, the health of your units decreases. Win the game by killing your opponents pieces first. Observers: Sprite2D: From 943bc0ac701f84715199fae22de8708b5af56dbc Mon Sep 17 00:00:00 2001 From: David Bloomin Date: Wed, 20 Mar 2024 16:42:46 -0700 Subject: [PATCH 03/10] add build_release script --- build_release.sh | 14 ++++++++++++++ deps/build.profile | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100755 build_release.sh diff --git a/build_release.sh b/build_release.sh new file mode 100755 index 00000000..a96f29df --- /dev/null +++ b/build_release.sh @@ -0,0 +1,14 @@ +./configure.sh + +conan profile update settings.compiler.libcxx=libstdc++11 default + +conan install deps/conanfile.txt --profile default \ + --profile deps/build.profile \ + -s build_type=Release --build missing -if build + +cmake . -B build -GNinja -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake + +cmake --build build --config Release + +pip install -e python diff --git a/deps/build.profile b/deps/build.profile index 11b07fd0..a0563eb1 100644 --- a/deps/build.profile +++ b/deps/build.profile @@ -2,4 +2,7 @@ ninja/1.11.1 [conf] -tools.cmake.cmaketoolchain:generator=Ninja \ No newline at end of file +tools.cmake.cmaketoolchain:generator=Ninja + +[settings] +compiler.libcxx=libstdc++11 From a2e483b77a6083c068fcb628911d8b15b619e2e0 Mon Sep 17 00:00:00 2001 From: David Bloomin Date: Wed, 20 Mar 2024 17:21:44 -0700 Subject: [PATCH 04/10] update build_release to not install python --- build_release.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/build_release.sh b/build_release.sh index a96f29df..04d99f15 100755 --- a/build_release.sh +++ b/build_release.sh @@ -11,4 +11,3 @@ cmake . -B build -GNinja -DCMAKE_BUILD_TYPE=Release \ cmake --build build --config Release -pip install -e python From 2e14981f0944321335bcf37d52992fcfa7f02673 Mon Sep 17 00:00:00 2001 From: David Bloomin Date: Wed, 20 Mar 2024 17:28:12 -0700 Subject: [PATCH 05/10] Update build-test-publish.yml --- .github/workflows/build-test-publish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-test-publish.yml b/.github/workflows/build-test-publish.yml index 07d08979..06eea313 100644 --- a/.github/workflows/build-test-publish.yml +++ b/.github/workflows/build-test-publish.yml @@ -178,6 +178,7 @@ jobs: - name: Poetry install run: | cd python + poetry lock poetry install # Run python tests From e699266724660ffe244459fb6548c848a2c80b2e Mon Sep 17 00:00:00 2001 From: David Bloomin Date: Wed, 20 Mar 2024 17:33:56 -0700 Subject: [PATCH 06/10] install ninja in github actions --- .github/workflows/build-test-publish.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-test-publish.yml b/.github/workflows/build-test-publish.yml index 06eea313..329e259a 100644 --- a/.github/workflows/build-test-publish.yml +++ b/.github/workflows/build-test-publish.yml @@ -93,6 +93,10 @@ jobs: run: | /opt/python/$PYBIN/bin/pip install poetry cmake conan==1.59.0 + # Install Ninja + - name: Install Ninja + run: sudo apt-get install -y ninja-build + # Configure conan for release build - name: Build run: | @@ -152,7 +156,7 @@ jobs: id: py with: python-version: ${{ matrix.windows_config.python-version }} - + # Setup MSVC - name: Setup MSVC uses: ilammy/msvc-dev-cmd@v1 From 86017ff594f2fa159479b91d171862c5416e3761 Mon Sep 17 00:00:00 2001 From: David Bloomin Date: Wed, 20 Mar 2024 17:42:30 -0700 Subject: [PATCH 07/10] Update build-test-publish.yml --- .github/workflows/build-test-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test-publish.yml b/.github/workflows/build-test-publish.yml index 329e259a..af93ff2d 100644 --- a/.github/workflows/build-test-publish.yml +++ b/.github/workflows/build-test-publish.yml @@ -95,7 +95,7 @@ jobs: # Install Ninja - name: Install Ninja - run: sudo apt-get install -y ninja-build + run: apt-get install -y ninja-build # Configure conan for release build - name: Build From bd857b29b0ffc41ec19c3597b8af099dfd19f4b0 Mon Sep 17 00:00:00 2001 From: David Bloomin Date: Wed, 20 Mar 2024 18:28:34 -0700 Subject: [PATCH 08/10] install ninja in manylinux --- .github/workflows/build-test-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test-publish.yml b/.github/workflows/build-test-publish.yml index 329e259a..42882abb 100644 --- a/.github/workflows/build-test-publish.yml +++ b/.github/workflows/build-test-publish.yml @@ -95,7 +95,7 @@ jobs: # Install Ninja - name: Install Ninja - run: sudo apt-get install -y ninja-build + run: yum install -y ninja-build # Configure conan for release build - name: Build From caf0179c470084f7c236eee5f4b1eee6634f2351 Mon Sep 17 00:00:00 2001 From: David Bloomin Date: Wed, 20 Mar 2024 18:31:08 -0700 Subject: [PATCH 09/10] remove wrong settings --- build_release.sh | 2 -- deps/build.profile | 3 --- 2 files changed, 5 deletions(-) diff --git a/build_release.sh b/build_release.sh index 04d99f15..1e65ecaf 100755 --- a/build_release.sh +++ b/build_release.sh @@ -1,7 +1,5 @@ ./configure.sh -conan profile update settings.compiler.libcxx=libstdc++11 default - conan install deps/conanfile.txt --profile default \ --profile deps/build.profile \ -s build_type=Release --build missing -if build diff --git a/deps/build.profile b/deps/build.profile index a0563eb1..06f9be69 100644 --- a/deps/build.profile +++ b/deps/build.profile @@ -3,6 +3,3 @@ ninja/1.11.1 [conf] tools.cmake.cmaketoolchain:generator=Ninja - -[settings] -compiler.libcxx=libstdc++11 From 499412cb1eda60deb93d8f71a4d8896917a9a60c Mon Sep 17 00:00:00 2001 From: David Bloomin Date: Wed, 20 Mar 2024 19:31:18 -0700 Subject: [PATCH 10/10] Update build-test-publish.yml --- .github/workflows/build-test-publish.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-test-publish.yml b/.github/workflows/build-test-publish.yml index 42882abb..1d7eb3a0 100644 --- a/.github/workflows/build-test-publish.yml +++ b/.github/workflows/build-test-publish.yml @@ -116,6 +116,7 @@ jobs: - name: Poetry install run: | cd python + /opt/python/$PYBIN/bin/poetry lock /opt/python/$PYBIN/bin/poetry install # Run python tests @@ -245,6 +246,7 @@ jobs: - name: Poetry install run: | cd python + poetry lock poetry install # Run python tests