Input: Integer button codes are still allowed in RGSS3

This commit is contained in:
Jonas Kulla 2014-12-09 04:21:48 +01:00
parent 6c92101e05
commit 685f8b63b3
2 changed files with 23 additions and 12 deletions

View File

@ -38,17 +38,22 @@ static int getButtonArg(int argc, VALUE *argv)
{
int num;
if (rgssVer >= 3)
{
ID sym;
rb_get_args(argc, argv, "n", &sym RB_ARG_END);
rb_check_argc(argc, 1);
if (FIXNUM_P(argv[0]))
{
num = FIX2INT(argv[0]);
}
else if (SYMBOL_P(argv[0]) && rgssVer >= 3)
{
VALUE symHash = getRbData()->buttoncodeHash;
num = FIX2INT(rb_hash_lookup2(symHash, ID2SYM(sym), INT2FIX(Input::None)));
num = FIX2INT(rb_hash_lookup2(symHash, argv[0], INT2FIX(Input::None)));
}
else
{
rb_get_args(argc, argv, "i", &num RB_ARG_END);
// FIXME: RMXP allows only few more types that
// don't make sense (symbols in pre 3, floats)
num = 0;
}
return num;

View File

@ -40,20 +40,26 @@ MRB_FUNCTION(inputUpdate)
static mrb_int getButtonArg(mrb_state *mrb)
{
mrb_int num;
mrb_value arg;
if (rgssVer >= 3)
mrb_get_args(mrb, "o", &arg);
if (mrb_fixnum_p(arg))
{
num = mrb_fixnum(arg);
}
else if (mrb_symbol_p(arg) && rgssVer >= 3)
{
mrb_sym sym;
mrb_get_args(mrb, "n", &sym);
mrb_value symHash = getMrbData(mrb)->buttoncodeHash;
mrb_value numVal = mrb_hash_fetch(mrb, symHash, mrb_symbol_value(sym),
mrb_value numVal = mrb_hash_fetch(mrb, symHash, arg,
mrb_fixnum_value(Input::None));
num = mrb_fixnum(numVal);
}
else
{
mrb_get_args(mrb, "i", &num);
// FIXME: RMXP allows only few more types that
// don't make sense (symbols in pre 3, floats)
num = 0;
}
return num;