Input: Implement RGSS3 functionality in bindings
Ie. using symbols instead of Input:: constants to query button states.
This commit is contained in:
parent
5a6c0c14ed
commit
64f1e32fdc
|
@ -237,6 +237,24 @@ rb_get_args(int argc, VALUE *argv, const char *format, ...)
|
|||
break;
|
||||
}
|
||||
|
||||
case 'n' :
|
||||
{
|
||||
if (argI >= argc)
|
||||
break;
|
||||
|
||||
ID *sym = va_arg(ap, ID*);
|
||||
|
||||
VALUE symVal = *arg++;
|
||||
|
||||
if (!SYMBOL_P(symVal))
|
||||
rb_raise(rb_eTypeError, "Argument %d: Expected symbol", argI);
|
||||
|
||||
*sym = SYM2ID(symVal);
|
||||
++argI;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case '|' :
|
||||
opt = true;
|
||||
break;
|
||||
|
|
|
@ -131,7 +131,7 @@ wrapNilProperty(VALUE self, const char *iv)
|
|||
rb_iv_set(self, iv, Qnil);
|
||||
}
|
||||
|
||||
/* Implemented: oSszfib| */
|
||||
/* Implemented: oSszfibn| */
|
||||
int
|
||||
rb_get_args(int argc, VALUE *argv, const char *format, ...);
|
||||
|
||||
|
|
|
@ -33,40 +33,45 @@ RB_METHOD(inputUpdate)
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
static int getButtonArg(VALUE self, int argc, VALUE *argv)
|
||||
{
|
||||
int num;
|
||||
|
||||
#ifdef RGSS3
|
||||
ID sym;
|
||||
rb_get_args(argc, argv, "n", &sym RB_ARG_END);
|
||||
|
||||
if (rb_const_defined(self, sym))
|
||||
num = FIX2INT(rb_const_get(self, sym));
|
||||
else
|
||||
num = 0;
|
||||
#else
|
||||
(void) self;
|
||||
rb_get_args(argc, argv, "i", &num RB_ARG_END);
|
||||
#endif
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
RB_METHOD(inputPress)
|
||||
{
|
||||
RB_UNUSED_PARAM;
|
||||
int num = getButtonArg(self, argc, argv);
|
||||
|
||||
int num;
|
||||
rb_get_args(argc, argv, "i", &num RB_ARG_END);
|
||||
|
||||
Input::ButtonCode bc = (Input::ButtonCode) num;
|
||||
|
||||
return rb_bool_new(shState->input().isPressed(bc));
|
||||
return rb_bool_new(shState->input().isPressed(num));
|
||||
}
|
||||
|
||||
RB_METHOD(inputTrigger)
|
||||
{
|
||||
RB_UNUSED_PARAM;
|
||||
int num = getButtonArg(self, argc, argv);
|
||||
|
||||
int num;
|
||||
rb_get_args(argc, argv, "i", &num RB_ARG_END);
|
||||
|
||||
Input::ButtonCode bc = (Input::ButtonCode) num;
|
||||
|
||||
return rb_bool_new(shState->input().isTriggered(bc));
|
||||
return rb_bool_new(shState->input().isTriggered(num));
|
||||
}
|
||||
|
||||
RB_METHOD(inputRepeat)
|
||||
{
|
||||
RB_UNUSED_PARAM;
|
||||
int num = getButtonArg(self, argc, argv);
|
||||
|
||||
int num;
|
||||
rb_get_args(argc, argv, "i", &num RB_ARG_END);
|
||||
|
||||
Input::ButtonCode bc = (Input::ButtonCode) num;
|
||||
|
||||
return rb_bool_new(shState->input().isRepeated(bc));
|
||||
return rb_bool_new(shState->input().isRepeated(num));
|
||||
}
|
||||
|
||||
RB_METHOD(inputDir4)
|
||||
|
|
|
@ -33,34 +33,44 @@ MRB_FUNCTION(inputUpdate)
|
|||
return mrb_nil_value();
|
||||
}
|
||||
|
||||
MRB_FUNCTION(inputPress)
|
||||
static mrb_int getButtonArg(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
mrb_int num;
|
||||
|
||||
#ifdef RGSS3
|
||||
mrb_sym sym;
|
||||
mrb_get_args(mrb, "n", &sym);
|
||||
|
||||
if (mrb_const_defined(mrb, self, sym))
|
||||
num = mrb_fixnum(mrb_const_get(mrb, self, sym));
|
||||
else
|
||||
num = 0;
|
||||
#else
|
||||
mrb_get_args(mrb, "i", &num);
|
||||
#endif
|
||||
|
||||
Input::ButtonCode bc = (Input::ButtonCode) num;
|
||||
|
||||
return mrb_bool_value(shState->input().isPressed(bc));
|
||||
return num;
|
||||
}
|
||||
|
||||
MRB_FUNCTION(inputTrigger)
|
||||
MRB_METHOD(inputPress)
|
||||
{
|
||||
mrb_int num;
|
||||
mrb_get_args(mrb, "i", &num);
|
||||
mrb_int num = getButtonArg(mrb, self);
|
||||
|
||||
Input::ButtonCode bc = (Input::ButtonCode) num;
|
||||
|
||||
return mrb_bool_value(shState->input().isTriggered(bc));
|
||||
return mrb_bool_value(shState->input().isPressed(num));
|
||||
}
|
||||
|
||||
MRB_FUNCTION(inputRepeat)
|
||||
MRB_METHOD(inputTrigger)
|
||||
{
|
||||
mrb_int num;
|
||||
mrb_get_args(mrb, "i", &num);
|
||||
mrb_int num = getButtonArg(mrb, self);
|
||||
|
||||
Input::ButtonCode bc = (Input::ButtonCode) num;
|
||||
return mrb_bool_value(shState->input().isTriggered(num));
|
||||
}
|
||||
|
||||
return mrb_bool_value(shState->input().isRepeated(bc));
|
||||
MRB_METHOD(inputRepeat)
|
||||
{
|
||||
mrb_int num = getButtonArg(mrb, self);
|
||||
|
||||
return mrb_bool_value(shState->input().isRepeated(num));
|
||||
}
|
||||
|
||||
MRB_FUNCTION(inputDir4)
|
||||
|
|
Loading…
Reference in New Issue