Files
EVEngine/test/joystick.nut
T
西风逍遥游 2ab09dcf68 feat(script): bind Image decode, Joystick Pad axes/buttons, Mouse relative mode
- Image: expose newImageData(newImageDataFromFile)/newEmptyImageData/isCompressed and a
  full ImageData script class (getWidth/Height/Format/Size, pixel get/set, paste, clone,
  rotate). ImageData is now registered once by the Image module; drop the duplicate
  minimal registrations in Font and Model3D that could overwrite each other.
- Joystick: expose getJoystick/getJoystickFromID/getIndex/addJoystick/removeJoystick and a
  Pad class with raw axes/buttons/hats, GameController axis/button names, device info,
  and vibration. Pads stay owned by the module (non-owning script handles).
- Mouse: expose setRelativeMode/getRelativeMode plus setVisible/setPosition/setX/setY/
  setGrabbed/isGrabbed (SDL backend already implemented them).
- Tests: add image.nut/image_script.cpp and joystick.nut/joystick_script.cpp script tests,
  extend mouse.nut with relative-mode/visibility checks, wire into test CMake and the nut
  embed template.
- Docs: update image/joystick/mouse user chapters, MODULES.md and the REVIEW log.
2026-08-20 12:31:11 +08:00

59 lines
1.6 KiB
Plaintext

function basic() {
if (eve.Joystick == null) {
print("can not find Joystick");
return false;
}
local p = eve.Joystick();
if (p.getName() != "Joystick") {
print("Joystick name is not right: ");
print(p.getName());
return false;
}
return true;
}
function padClass() {
if (eve.Pad == null) {
print("can not find Pad class");
return false;
}
return true;
}
function query() {
local joy = eve.Joystick();
local n = joy.getJoystickCount();
if (n < 0) return false;
if (joy.getJoystick(-1) != null) return false;
if (joy.getJoystick(n) != null) return false;
if (joy.getJoystickFromID(-999999) != null) return false;
for (local i = 0; i < n; i++) {
local pad = joy.getJoystick(i);
if (pad == null) return false;
if (joy.getIndex(pad) != i) return false;
if (pad.getAxisCount() < 0) return false;
if (pad.getButtonCount() < 0) return false;
if (pad.getHatCount() < 0) return false;
if (pad.getID() < 0) return false;
}
return true;
}
function axes() {
local joy = eve.Joystick();
local n = joy.getJoystickCount();
if (n == 0) return true; // no device attached; nothing to verify
local pad = joy.getJoystick(0);
local axes = pad.getAxes();
if (typeof axes != "array") return false;
if (axes.len() != pad.getAxisCount()) return false;
for (local i = 0; i < axes.len(); i++) {
if (axes[i] < -1.0 || axes[i] > 1.0) return false;
}
if (pad.getHatCount() > 0 && pad.getHat(0) == "") return false;
return true;
}