Skip to content

Commit

Permalink
Merge pull request #298 from daveey/develop
Browse files Browse the repository at this point in the history
sort variableNames to provide consistent observations
  • Loading branch information
Bam4d authored Apr 7, 2024
2 parents 9623461 + 499412c commit 8ccd178
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 32 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/build-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ jobs:
run: |
/opt/python/$PYBIN/bin/pip install poetry cmake conan==1.59.0
# Install Ninja
- name: Install Ninja
run: yum install -y ninja-build

# Configure conan for release build
- name: Build
run: |
Expand All @@ -112,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
Expand Down Expand Up @@ -152,7 +157,7 @@ jobs:
id: py
with:
python-version: ${{ matrix.windows_config.python-version }}

# Setup MSVC
- name: Setup MSVC
uses: ilammy/msvc-dev-cmd@v1
Expand All @@ -178,6 +183,7 @@ jobs:
- name: Poetry install
run: |
cd python
poetry lock
poetry install
# Run python tests
Expand Down Expand Up @@ -240,6 +246,7 @@ jobs:
- name: Poetry install
run: |
cd python
poetry lock
poetry install
# Run python tests
Expand Down
11 changes: 11 additions & 0 deletions build_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
./configure.sh

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

2 changes: 1 addition & 1 deletion deps/build.profile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
ninja/1.11.1

[conf]
tools.cmake.cmaketoolchain:generator=Ninja
tools.cmake.cmaketoolchain:generator=Ninja
2 changes: 1 addition & 1 deletion js/griddlyjs-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions js/griddlyjs-app/src/renderer/Sprite2DRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Sprite2DRenderer extends RendererBase {

sprite.setDisplaySize(
this.renderConfig.TileSize,
this.renderConfig.TileSize
this.renderConfig.TileSize
);
}

Expand All @@ -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));
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions resources/games/RTS/Stratega/heal-or-die.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion src/Griddly/Core/Grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,10 @@ void Grid::initObject(std::string objectName, std::vector<std::string> variableN
objectCounters_.insert({objectName, {{0, std::make_shared<int32_t>(0)}}});

for (auto& variableName : variableNames) {
objectVariables_.insert(variableName);
}
objectVariableMap_.clear();
for (auto& variableName : objectVariables_) {
objectVariableIds_.insert({variableName, objectVariableIds_.size()});
}

Expand Down Expand Up @@ -739,4 +743,4 @@ const std::unordered_map<std::string, std::unordered_set<std::string>>& Grid::ge
return collisionObjectActionNames_;
}

} // namespace griddly
} // namespace griddly
5 changes: 3 additions & 2 deletions src/Griddly/Core/Grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Grid : public std::enable_shared_from_this<Grid> {
virtual const std::unordered_set<std::shared_ptr<Object>>& getObjects();

virtual void addPlayerDefaultEmptyObject(std::shared_ptr<Object> emptyObject);

virtual void addPlayerDefaultBoundaryObject(std::shared_ptr<Object> boundaryObject);

virtual std::shared_ptr<Object> getPlayerDefaultEmptyObject(uint32_t playerId) const;
Expand Down Expand Up @@ -199,6 +199,7 @@ class Grid : public std::enable_shared_from_this<Grid> {
std::vector<std::unordered_set<glm::ivec2>> updatedLocations_;

std::unordered_map<std::string, uint32_t> objectIds_;
std::set<std::string> objectVariables_;
std::unordered_map<std::string, uint32_t> objectVariableIds_;
std::unordered_map<std::string, std::vector<std::string>> objectVariableMap_;
std::unordered_set<std::shared_ptr<Object>> objects_;
Expand Down Expand Up @@ -248,4 +249,4 @@ class Grid : public std::enable_shared_from_this<Grid> {
std::shared_ptr<RandomGenerator> randomGenerator_ = std::make_shared<RandomGenerator>(RandomGenerator());
};

} // namespace griddly
} // namespace griddly

0 comments on commit 8ccd178

Please sign in to comment.