Skip to content

Commit

Permalink
Merge branch 'release/1.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bam4d committed Jul 17, 2022
2 parents 24c21c3 + a55c9d1 commit da7b68c
Show file tree
Hide file tree
Showing 17 changed files with 244 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.4.0]
- Version [e.g. 1.4.1]

**Additional context**
Add any other context about the problem here.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10.0)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version")
project(Griddly VERSION 1.4.0)
project(Griddly VERSION 1.4.1)

set(BINARY ${CMAKE_PROJECT_NAME})

Expand Down
2 changes: 1 addition & 1 deletion bindings/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace griddly {

PYBIND11_MODULE(python_griddly, m) {
m.doc() = "Griddly python bindings";
m.attr("version") = "1.4.0";
m.attr("version") = "1.4.1";

#ifndef NDEBUG
spdlog::set_level(spdlog::level::debug);
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Chris Bamford'

# The full version, including alpha/beta/rc tags
release = '1.4.0'
release = '1.4.1'


# -- General configuration ---------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions js/bindings/GriddlyJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ std::shared_ptr<GriddlyJSGDYWrapper> GriddlyJS::loadString(std::string levelStri
std::istringstream s(levelString);
gdyFactory->parseFromStream(s);
return std::make_shared<GriddlyJSGDYWrapper>(GriddlyJSGDYWrapper(gdyFactory));
}

std::string GriddlyJS::getExceptionMessage(intptr_t exceptionPtr) {
return std::string(reinterpret_cast<std::exception *>(exceptionPtr)->what());
}
6 changes: 5 additions & 1 deletion js/bindings/GriddlyJS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class GriddlyJS {
public:
GriddlyJS();
std::shared_ptr<GriddlyJSGDYWrapper> loadString(std::string levelString);
std::string getExceptionMessage(intptr_t exceptionPtr);
};

template <typename K, typename V>
Expand All @@ -25,11 +26,14 @@ e::class_<std::unordered_map<K, V>> register_unordered_map(const char* name) {
.function("keys", e::internal::MapAccess<MapType>::keys);
}


EMSCRIPTEN_BINDINGS(GriddlyJS) {
// Classes
e::class_<GriddlyJS>("GriddlyJS")
.constructor()
.function("loadString", &GriddlyJS::loadString);
.function("loadString", &GriddlyJS::loadString)
.function("getExceptionMessage", &GriddlyJS::getExceptionMessage);


e::class_<GriddlyJSGDYWrapper>("GriddlyJSGDYWrapper")
.smart_ptr<std::shared_ptr<GriddlyJSGDYWrapper>>("GriddlyJSGDYWrapper")
Expand Down
4 changes: 2 additions & 2 deletions js/griddlyjs-app/package-lock.json

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

2 changes: 1 addition & 1 deletion js/griddlyjs-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "griddlyjs-app",
"version": "1.4.0",
"version": "1.4.1",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.1.1",
Expand Down
Binary file modified js/griddlyjs-app/public/js/griddlyjs.wasm
Binary file not shown.
176 changes: 125 additions & 51 deletions js/griddlyjs-app/src/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// import logo from './logo.svg';
import yaml from "js-yaml";
import yaml, { YAMLException } from "js-yaml";
import React, { Component } from "react";
import "./App.scss";
import GriddlyJSCore from "./GriddlyJSCore";
Expand Down Expand Up @@ -107,6 +107,9 @@ class App extends Component {

setCurrentLevel = (levelId) => {
this.setState((state) => {
if (!state.gdy || !this.griddlyjs) {
return state;
}
const levelString = state.gdy.Environment.Levels[levelId];

try {
Expand Down Expand Up @@ -175,7 +178,10 @@ class App extends Component {
levelString,
this.state.selectedLevelId
);
this.editorStateHandler.loadLevelString(levelString, this.state.selectedLevelId);
this.editorStateHandler.loadLevelString(
levelString,
this.state.selectedLevelId
);
this.griddlyjs.reset(levelString);
this.setState((state) => {
return {
Expand Down Expand Up @@ -206,7 +212,10 @@ class App extends Component {

saveNewLevel = () => {
const savedLevelId = this.saveLevelString(this.state.levelString);
this.editorStateHandler.loadLevelString(this.state.levelString, this.state.selectedLevelId);
this.editorStateHandler.loadLevelString(
this.state.levelString,
this.state.selectedLevelId
);
this.griddlyjs.reset(this.state.levelString);
this.setState((state) => {
return {
Expand All @@ -221,7 +230,10 @@ class App extends Component {
this.state.levelString,
this.state.selectedLevelId
);
this.editorStateHandler.loadLevelString(this.state.levelString, this.state.selectedLevelId);
this.editorStateHandler.loadLevelString(
this.state.levelString,
this.state.selectedLevelId
);
this.griddlyjs.reset(this.state.levelString);

this.setState((state) => {
Expand Down Expand Up @@ -424,31 +436,27 @@ class App extends Component {
this.setState((state) => {
return {
...state,
loading: true
}
loading: true,
};
});

setTimeout(() => {
try {
this.updateGDY(gdyString, projectName);
this.setCurrentLevel(lastLevelId);
} catch (e) {
this.displayMessage("Could not load GDY", "error", e);
this.setState((state) => {
return {
...state,
projectName,
gdyHash: hashString(gdyString),
gdyString: gdyString,
gdy: gdy,
editorStateHandler: this.editorStateHandler,
selectedLevelId: lastLevelId,
};
});
}
}, 100);


try {
this.updateGDY(gdyString, projectName);
this.setCurrentLevel(lastLevelId);
} catch (e) {
this.displayMessage("Could not load GDY", "error", e);
this.setState((state) => {
return {
...state,
projectName,
gdyHash: hashString(gdyString),
gdyString: gdyString,
gdy: gdy,
editorStateHandler: this.editorStateHandler,
selectedLevelId: lastLevelId,
};
});
}
} catch (e) {
this.displayMessage("Could not load GDY", "error", e);
this.setState((state) => {
Expand Down Expand Up @@ -488,31 +496,82 @@ class App extends Component {
});
};

checkGriddlyJSCompatibility = (gdy) => {
// Check for avatar object
if (
!("Player" in gdy.Environment) ||
!("AvatarObject" in gdy.Environment.Player)
) {
throw new Error(
"Currently only Single-Player environments where an avatar is controlled by the agent are compatible with GriddlyJS. \n\n Perhaps you forgot to set the AvatarObject?"
);
}

if (!("Levels" in gdy.Environment)) {
throw new Error("Please define at least one level.");
}
};

updateGDY = (gdyString, projectName) => {
const gdy = yaml.load(gdyString);
this.editorHistory.updateState(projectName, { gdy });
this.closeAllMessages();

try {
this.griddlyjs.unloadGDY();
this.griddlyjs.loadGDY(gdyString);
} catch (e) {
this.displayMessage("Unable to load GDY", "error", e);
}
this.editorStateHandler.loadGDY(gdy);
const gdy = yaml.load(gdyString);
this.checkGriddlyJSCompatibility(gdy);
this.editorHistory.updateState(projectName, { gdy });
try {
this.griddlyjs.unloadGDY();
this.griddlyjs.loadGDY(gdyString);

this.loadRenderers(gdy);
this.editorStateHandler.loadGDY(gdy);

this.setState((state) => {
return {
...state,
projectName,
gdyHash: hashString(gdyString),
gdyString: gdyString,
gdy: gdy,
griddlyjs: this.griddlyjs,
editorStateHandler: this.editorStateHandler,
loading: false
};
});
this.loadRenderers(gdy);
this.setState((state) => {
return {
...state,
projectName,
gdyHash: hashString(gdyString),
gdyString: gdyString,
gdy: gdy,
griddlyjs: this.griddlyjs,
editorStateHandler: this.editorStateHandler,
loading: false,
};
});
} catch (e) {
this.displayMessage("Unable to load GDY \n\n" + e.message, "error", e);
this.setState((state) => {
return {
...state,
projectName,
// gdyHash: hashString(gdyString),
// gdy: gdy,
gdyString: gdyString,
editorStateHandler: this.editorStateHandler,
loading: false,
};
});
}
} catch (e) {
this.setState((state) => {
return {
...state,
projectName,
gdyHash: hashString(gdyString),
gdyString: gdyString,
loading: false,
};
});
if (e instanceof YAMLException) {
this.displayMessage(
"There are syntax errors in your GDY: " + e.message,
"error",
e
);
} else {
this.displayMessage("Unable to load GDY \n\n" + e.message, "error", e);
}
}
};

updatePhaserCanvasSize = () => {
Expand Down Expand Up @@ -710,12 +769,18 @@ class App extends Component {
});
};

closeAllMessages = () => {
Object.entries(this.state.messages).map(([key, message]) => {
this.closeMessage(key);
});
};

render() {
return (
<Container fluid className="griddlyjs-ide-container">
<Intro onClose={this.closeIntroModal} show={this.state.showIntro} />
<Modal show={this.state.loading} backdrop="static">
<Modal.Header>
<Modal.Header>
<Modal.Title>Loading Project.....</Modal.Title>
</Modal.Header>
</Modal>
Expand Down Expand Up @@ -751,7 +816,7 @@ class App extends Component {
</Button>
</Modal.Footer>
</Modal>
<ToastContainer className="p-3" position="top-left">
<ToastContainer className="p-5" position="top-start">
{Object.entries(this.state.messages).map(([key, message]) => {
let icon;
switch (message.type) {
Expand Down Expand Up @@ -799,7 +864,16 @@ class App extends Component {
}}
>
<Toast.Header closeButton={true}>{icon}</Toast.Header>
<Toast.Body>{message.content}</Toast.Body>
<Toast.Body className="message-text">
{message.content.split("\n").map(function (item, idx) {
return (
<span key={idx}>
{item}
<br />
</span>
);
})}
</Toast.Body>
</Toast>
);
})}
Expand Down
6 changes: 6 additions & 0 deletions js/griddlyjs-app/src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@
text-align: center;
margin: 20px;
}

.message-text {
white-space: pre-wrap;
text-align: left;
font-family: monospace;
}
Loading

0 comments on commit da7b68c

Please sign in to comment.