Input.count, Input.repeatcount, System.user_name

This commit is contained in:
Roza 2021-02-22 18:36:53 -05:00
parent 51c6f627bc
commit 79dbb9856d
4 changed files with 667 additions and 605 deletions

View file

@ -1,23 +1,23 @@
/* /*
** binding-mri.cpp ** binding-mri.cpp
** **
** This file is part of mkxp. ** This file is part of mkxp.
** **
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com> ** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
** **
** mkxp is free software: you can redistribute it and/or modify ** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by ** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 2 of the License, or ** the Free Software Foundation, either version 2 of the License, or
** (at your option) any later version. ** (at your option) any later version.
** **
** mkxp is distributed in the hope that it will be useful, ** mkxp is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details. ** GNU General Public License for more details.
** **
** You should have received a copy of the GNU General Public License ** You should have received a copy of the GNU General Public License
** along with mkxp. If not, see <http://www.gnu.org/licenses/>. ** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "audio/audio.h" #include "audio/audio.h"
#include "filesystem/filesystem.h" #include "filesystem/filesystem.h"
@ -122,6 +122,7 @@ RB_METHOD(mkxpRawKeyStates);
RB_METHOD(mkxpMouseInWindow); RB_METHOD(mkxpMouseInWindow);
RB_METHOD(mkxpPlatform); RB_METHOD(mkxpPlatform);
RB_METHOD(mkxpUserLanguage); RB_METHOD(mkxpUserLanguage);
RB_METHOD(mkxpUserName);
RB_METHOD(mkxpGameTitle); RB_METHOD(mkxpGameTitle);
RB_METHOD(mkxpPowerState); RB_METHOD(mkxpPowerState);
RB_METHOD(mkxpSettingsMenu); RB_METHOD(mkxpSettingsMenu);
@ -204,6 +205,7 @@ static void mriBindingInit() {
_rb_define_module_function(mod, "mouse_in_window", mkxpMouseInWindow); _rb_define_module_function(mod, "mouse_in_window", mkxpMouseInWindow);
_rb_define_module_function(mod, "platform", mkxpPlatform); _rb_define_module_function(mod, "platform", mkxpPlatform);
_rb_define_module_function(mod, "user_language", mkxpUserLanguage); _rb_define_module_function(mod, "user_language", mkxpUserLanguage);
_rb_define_module_function(mod, "user_name", mkxpUserName);
_rb_define_module_function(mod, "game_title", mkxpGameTitle); _rb_define_module_function(mod, "game_title", mkxpGameTitle);
_rb_define_module_function(mod, "power_state", mkxpPowerState); _rb_define_module_function(mod, "power_state", mkxpPowerState);
_rb_define_module_function(mod, "nproc", mkxpCpuCount); _rb_define_module_function(mod, "nproc", mkxpCpuCount);
@ -339,6 +341,12 @@ RB_METHOD(mkxpUserLanguage) {
return rb_str_new_cstr(mkxp_sys::getSystemLanguage().c_str()); return rb_str_new_cstr(mkxp_sys::getSystemLanguage().c_str());
} }
RB_METHOD(mkxpUserName) {
RB_UNUSED_PARAM;
return rb_str_new_cstr(mkxp_sys::getUserName().c_str());
}
RB_METHOD(mkxpGameTitle) { RB_METHOD(mkxpGameTitle) {
RB_UNUSED_PARAM; RB_UNUSED_PARAM;
@ -701,13 +709,13 @@ static void runRMXPScripts(BacktraceData &btData) {
// any extra stuff before the end (primarily stupid Essentials fixes) // any extra stuff before the end (primarily stupid Essentials fixes)
// Will be placed within a build option later if I decide to add more // Will be placed within a build option later if I decide to add more
#ifndef MKXPZ_BUILD_XCODE #ifndef MKXPZ_BUILD_XCODE
#define SCRIPT(name) rb_str_new((const char*)&___scripts_##name##_rb, ___scripts_##name##_rb_len), #name " (Internal)" #define SCRIPT(name) rb_str_new((const char*)&___scripts_##name##_rb, ___scripts_##name##_rb_len), #name " (Internal)"
#define EVALFILE(name) if (!evalScript(SCRIPT(name))) break; #define EVALFILE(name) if (!evalScript(SCRIPT(name))) break;
#else #else
#define EVALFILE(name) { \ #define EVALFILE(name) { \
std::string s = mkxp_fs::contentsOfAssetAsString("BindingScripts/" #name, "rb"); \ std::string s = mkxp_fs::contentsOfAssetAsString("BindingScripts/" #name, "rb"); \
if (!evalScript(rb_str_new_cstr(s.c_str()), #name)) break; \ if (!evalScript(rb_str_new_cstr(s.c_str()), #name)) break; \
} }
#endif #endif
if (i + 2 == scriptCount){ if (i + 2 == scriptCount){
#ifdef MKXPZ_ESSENTIALS_DEBUG #ifdef MKXPZ_ESSENTIALS_DEBUG
@ -862,14 +870,14 @@ static void mriBindingExecute() {
if (state || !valid) { if (state || !valid) {
// The message is formatted for and automatically spits // The message is formatted for and automatically spits
// out to the terminal, so let's leave it that way for now // out to the terminal, so let's leave it that way for now
/* /*
VALUE exc = rb_errinfo(); VALUE exc = rb_errinfo();
#if RAPI_FULL >= 250 #if RAPI_FULL >= 250
VALUE msg = rb_funcall(exc, rb_intern("full_message"), 0); VALUE msg = rb_funcall(exc, rb_intern("full_message"), 0);
#else #else
VALUE msg = rb_funcall(exc, rb_intern("message"), 0); VALUE msg = rb_funcall(exc, rb_intern("message"), 0);
#endif #endif
*/ */
showMsg("An error occurred while initializing Ruby. (Invalid JIT settings?)"); showMsg("An error occurred while initializing Ruby. (Invalid JIT settings?)");
ruby_cleanup(state); ruby_cleanup(state);
shState->rtData().rqTermAck.set(); shState->rtData().rqTermAck.set();

View file

@ -125,6 +125,19 @@ RB_METHOD(inputRelease) {
return rb_bool_new(shState->input().isReleased(num)); return rb_bool_new(shState->input().isReleased(num));
} }
RB_METHOD(inputCount) {
RB_UNUSED_PARAM;
rb_check_argc(argc, 1);
VALUE button;
rb_scan_args(argc, argv, "1", &button);
int num = getButtonArg(&button);
return UINT2NUM(shState->input().count(num));
}
RB_METHOD(inputPressEx) { RB_METHOD(inputPressEx) {
RB_UNUSED_PARAM; RB_UNUSED_PARAM;
@ -181,6 +194,20 @@ RB_METHOD(inputReleaseEx) {
return rb_bool_new(shState->input().isReleasedEx(NUM2INT(button), 1)); return rb_bool_new(shState->input().isReleasedEx(NUM2INT(button), 1));
} }
RB_METHOD(inputCountEx) {
RB_UNUSED_PARAM;
VALUE button;
rb_scan_args(argc, argv, "1", &button);
if (SYMBOL_P(button)) {
int num = getScancodeArg(&button);
return UINT2NUM(shState->input().repeatcount(num, 0));
}
return UINT2NUM(shState->input().repeatcount(NUM2INT(button), 1));
}
RB_METHOD(inputDir4) { RB_METHOD(inputDir4) {
RB_UNUSED_PARAM; RB_UNUSED_PARAM;
@ -350,10 +377,12 @@ void inputBindingInit() {
_rb_define_module_function(module, "trigger?", inputTrigger); _rb_define_module_function(module, "trigger?", inputTrigger);
_rb_define_module_function(module, "repeat?", inputRepeat); _rb_define_module_function(module, "repeat?", inputRepeat);
_rb_define_module_function(module, "release?", inputRelease); _rb_define_module_function(module, "release?", inputRelease);
_rb_define_module_function(module, "count", inputCount);
_rb_define_module_function(module, "pressex?", inputPressEx); _rb_define_module_function(module, "pressex?", inputPressEx);
_rb_define_module_function(module, "triggerex?", inputTriggerEx); _rb_define_module_function(module, "triggerex?", inputTriggerEx);
_rb_define_module_function(module, "repeatex?", inputRepeatEx); _rb_define_module_function(module, "repeatex?", inputRepeatEx);
_rb_define_module_function(module, "releaseex?", inputReleaseEx); _rb_define_module_function(module, "releaseex?", inputReleaseEx);
_rb_define_module_function(module, "repeatcount", inputCountEx);
_rb_define_module_function(module, "dir4", inputDir4); _rb_define_module_function(module, "dir4", inputDir4);
_rb_define_module_function(module, "dir8", inputDir8); _rb_define_module_function(module, "dir8", inputDir8);

View file

@ -1180,6 +1180,13 @@ bool Input::isReleased(int button) {
return p->getStateCheck(button).released; return p->getStateCheck(button).released;
} }
unsigned int Input::count(int button) {
if (button != p->repeating)
return 0;
return p->repeatCount;
}
bool Input::isPressedEx(int code, bool isVKey) bool Input::isPressedEx(int code, bool isVKey)
{ {
return p->getStateRaw(code, isVKey).pressed; return p->getStateRaw(code, isVKey).pressed;
@ -1200,6 +1207,22 @@ bool Input::isReleasedEx(int code, bool isVKey)
return p->getStateRaw(code, isVKey).released; return p->getStateRaw(code, isVKey).released;
} }
unsigned int Input::repeatcount(int code, bool isVKey) {
unsigned int c = code;
if (isVKey) {
try {
c = vKeyToScancode[code];
}
catch (...) {
return 0;
}
}
if (c != p->rawRepeating)
return 0;
return p->rawRepeatCount;
}
int Input::dir4Value() int Input::dir4Value()
{ {
return p->dir4Data.active; return p->dir4Data.active;

View file

@ -61,10 +61,12 @@ public:
bool isTriggered(int button); bool isTriggered(int button);
bool isRepeated(int button); bool isRepeated(int button);
bool isReleased(int button); bool isReleased(int button);
unsigned int count(int button);
bool isPressedEx(int code, bool isVKey); bool isPressedEx(int code, bool isVKey);
bool isTriggeredEx(int code, bool isVKey); bool isTriggeredEx(int code, bool isVKey);
bool isRepeatedEx(int code, bool isVKey); bool isRepeatedEx(int code, bool isVKey);
bool isReleasedEx(int code, bool isVKey); bool isReleasedEx(int code, bool isVKey);
unsigned int repeatcount(int code, bool isVKey);
int dir4Value(); int dir4Value();
int dir8Value(); int dir8Value();