From f0b88b69ef7492a48880e75ebe4cc392bff2e686 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Thu, 13 Jul 2017 12:38:21 -0400 Subject: [PATCH] Update scripting --- chaigame/keyboard.cpp | 4 ++-- chaigame/keyboard.h | 2 +- chaigame/script.cpp | 7 +++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/chaigame/keyboard.cpp b/chaigame/keyboard.cpp index 26b5d40..40d5520 100644 --- a/chaigame/keyboard.cpp +++ b/chaigame/keyboard.cpp @@ -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) { diff --git a/chaigame/keyboard.h b/chaigame/keyboard.h index 7750947..75d48ae 100644 --- a/chaigame/keyboard.h +++ b/chaigame/keyboard.h @@ -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); diff --git a/chaigame/script.cpp b/chaigame/script.cpp index 7c7d834..3d4022f 100644 --- a/chaigame/script.cpp +++ b/chaigame/script.cpp @@ -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(&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(&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