DOF/sqr/User/Controller/Controller.nut

77 lines
1.9 KiB
Plaintext
Raw Normal View History

2024-12-25 11:35:29 +08:00
/*
文件名:Controller.nut
路径:User/Controller/Controller.nut
创建日期:2024-12-21 07:31
文件用途:控制器类
*/
class _GameController_ extends _Input_ {
//最新键码输入
2025-01-11 23:58:10 +08:00
2024-12-25 11:35:29 +08:00
KeyCode = null;
GameKeyCode = null;
GameKeyCodeCallback = null;
constructor() {
base.constructor();
GameKeyCodeCallback = {};
//建立键码表 按下flag全部为false
this.KeyCode = {};
foreach(value in getconsttable().KeyCode) {
this.KeyCode.rawset(value, false);
}
//建立游戏键码表
this.GameKeyCode = {};
foreach(Key, Value in getconsttable().CONTROLLER) {
this.GameKeyCode.rawset(Key, Value);
}
}
//系统对游戏的输入
function SystemInput(Code, Type) {
SetKeyCode(Code, Type);
}
//设定键码状态
function SetKeyCode(Code, Status) {
this.KeyCode[Code] = Status;
//只遍历有回调的键码
2025-01-11 23:58:10 +08:00
foreach(RCode, Callback in GameKeyCodeCallback) {
if (RCode == Code) {
Callback(Status);
2024-12-25 11:35:29 +08:00
}
}
}
//获取键码状态
function GetKeyCode(Code) {
return this.KeyCode[Code];
}
//获取游戏键码状态
function GetGameKeyCode(Code) {
if (!(GameKeyCode.rawin(Code))) return false;
return GetKeyCode(GameKeyCode[Code]);
}
//注册游戏键码回调函数
function RegisterGameKeyCode(Code, Callback) {
GameKeyCodeCallback[Code] <- Callback;
}
//Proc逻辑
function Proc(Dt, GameLister) {
// //只遍历有回调的键码
// foreach(Code, Callback in GameKeyCodeCallback) {
// //是否按下传递不同指令
// if (GetGameKeyCode(Code)) {
// Callback(true);
// } else {
// Callback(false);
// }
// }
}
}