Update scripting

This commit is contained in:
Rob Loach 2017-07-13 12:38:21 -04:00
parent d39262a1f9
commit f0b88b69ef
No known key found for this signature in database
GPG Key ID: 627C60834A74A21A
3 changed files with 8 additions and 5 deletions

View File

@ -5,13 +5,13 @@
namespace chaigame {
bool keyboard::isKeyDown(int key) {
bool keyboard::isDown(int key) {
return (bool)keys[key];
}
bool keyboard::isDown(const std::string& key) {
int keycode = getKeyCodeFromName(key);
return isKeyDown(keycode);
return isDown(keycode);
}
int keyboard::getKeyCodeFromName(const std::string& name) {

View File

@ -11,7 +11,7 @@ namespace chaigame {
Uint8* keys;
bool load();
bool isDown(const std::string& key);
bool isKeyDown(int key);
bool isDown(int key);
void setKeyRepeat(int delay = 400, int interval = 30);
bool update();
int getKeyCodeFromName(const std::string& name);

View File

@ -91,8 +91,8 @@ namespace chaigame {
chai.add_global(var(std::ref(app->graphics)), "graphics");
// Register the Keyboard module.
chai.add(fun(&keyboard::update), "update");
chai.add(fun(&keyboard::isDown), "isDown");
chai.add(fun<bool, keyboard, const std::string&>(&keyboard::isDown), "isDown");
chai.add(fun(&keyboard::setKeyRepeat), "setKeyRepeat");
chai.add_global(var(std::ref(app->keyboard)), "keyboard");
// Register the Event module.
@ -106,6 +106,7 @@ namespace chaigame {
// Register the Filesystem module.
chai.add(fun(&filesystem::read), "read");
chai.add(fun(&filesystem::exists), "exists");
chai.add(fun(&filesystem::mount), "mount");
chai.add(fun<int, filesystem, const std::string&>(&filesystem::getSize), "getSize");
chai.add(fun(&filesystem::load), "load");
chai.add_global(var(std::ref(app->filesystem)), "filesystem");
@ -262,9 +263,11 @@ namespace chaigame {
printf("Skipping call to update(): %s\n", e.what());
}
catch (std::exception& e) {
hasUpdate = false;
printf("Failed to call update(t): %s\n", e.what());
}
catch (...) {
hasUpdate = false;
printf("Unhandled exception in update()");
}
#endif