Quellcode durchsuchen

+ handle input fix

tianhaobu vor 3 Monaten
Ursprung
Commit
c93f73fcff

+ 3 - 0
notes/必读(更新日志)/必读(更新日志).txt

@@ -114,6 +114,9 @@ input_handle_find("A")
 根据注册名返回函数名,"A"表示注册名
 通常搭配autodel_handle()使用
 
+2026/2/19 tianhaobu
+没错还是我,修复了handle input,现在直接使用_xxx = ingame.kc("X")即可,无需if(xxx != undefined)了
+
 2026/2/15 Dr.Duck
 
 1. 优化check_hazard逻辑,功能实现没问题但不够优雅

+ 2 - 1
objects/oMain/Create_0.gml

@@ -6,8 +6,9 @@ global.input_handles_index = [
 	"inventory",
 	"title"
 ]
+create_dummy_handle()
 for(var i = 0; i < array_length(global.input_handles_index); i++)
-    variable_instance_set(id, global.input_handles_index[i], undefined);
+    variable_instance_set(id, global.input_handles_index[i], global.handle_dummy);
 	
 autoreg_handle("ingame", "ingame", 1);
 autoreg_handle("title", "title", 100);

+ 19 - 23
objects/oMain/Step_0.gml

@@ -1,14 +1,14 @@
-_jump_p = ingame.kcp("Z");
-_jump_r = ingame.kcr("Z");
-_dash   = ingame.kcp("C");
-_attack = ingame.kcp("X");
-_left   = ingame.kc(vk_left);
-_right  = ingame.kc(vk_right);
-_up     = ingame.kc(vk_up);
-_down   = ingame.kc(vk_down);
+_jump_p    = ingame.kcp("Z");
+_jump_r    = ingame.kcr("Z");
+_dash      = ingame.kcp("C");
+_attack    = ingame.kcp("X");
+_left      = ingame.kc(vk_left);
+_right     = ingame.kc(vk_right);
+_up        = ingame.kc(vk_up);
+_down      = ingame.kc(vk_down);
 _inventory = ingame.kcp("I");
 
-_return = ingame.kcp(vk_escape); // for debugging
+_return    = ingame.kcp(vk_escape); // for debugging
 
 /*
 if (ingame.kcp(vk_escape)) {
@@ -18,20 +18,16 @@ if (title != undefined && title.kcp(vk_escape)) {
     autodel_handle("title"); 
 }
 */
-if title != undefined
-{
-	_newgame = title.kcp(vk_space);
-	_continue = title.kcp(vk_enter);
-	_quitgame = title.kcp(vk_escape);
-}
-if inventory != undefined
-{
-	_left = inventory.kcp(vk_left);
-	_right = inventory.kcp(vk_right);
-	_up = inventory.kcp(vk_up);
-	_down = inventory.kcp(vk_down);
-	_close = inventory.kcp("I") || inventory.kcp(vk_escape);
-}
+_newgame  = title.kcp(vk_space);
+_continue = title.kcp(vk_enter);
+_quitgame = title.kcp(vk_escape);
+
+_left_inv = inventory.kcp(vk_left);
+_right_inv= inventory.kcp(vk_right);
+_up_inv   = inventory.kcp(vk_up);
+_down_inv = inventory.kcp(vk_down);
+_close    = inventory.kcp("I") || inventory.kcp(vk_escape);
+
 
 
 if global.developer_mode && room == rTitle

+ 23 - 3
scripts/Interaction/Interaction.gml

@@ -135,6 +135,18 @@ function input_handle_find(_reg_name) {
     return undefined;
 }
 
+/// @desc 创建空句柄
+function create_dummy_handle(){
+	global.handle_dummy = {
+    kc:  function() { return false; },
+    kcp: function() { return false; },
+    kcr: function() { return false; },
+    destroy: function() {  },
+    active: false,
+    priority: -9999
+};
+}
+
 /// @desc 自动化注册句柄,核心部分等效于 _new_handle = new input_handle(_reg_name, _priority)
 /// @param {String} _func_name handle变量名
 /// @param {String} _reg_name 注册名
@@ -150,6 +162,12 @@ function autoreg_handle(_func_name, _reg_name, _priority){
 	}
 	if (!_found) throw("ERROR:尝试注册的变量名'" + _func_name + "'不在input_handles_index内")
 	
+	var _current = variable_instance_get(id, _func_name);
+    
+    // 如果已经存在,则销毁旧的
+    if (is_struct(_current) && _current != global.handle_dummy) {
+        _current.destroy();
+    }
 	var _new_handle = new input_handle(_reg_name, _priority);
 	variable_instance_set(id, _func_name, _new_handle);
 }
@@ -158,8 +176,10 @@ function autoreg_handle(_func_name, _reg_name, _priority){
 /// @param {String} _func_name handle变量名
 function autodel_handle(_func_name){
     var _handle = variable_instance_get(id, _func_name);
-    if (_handle != undefined && is_struct(_handle)) {
-        _handle.destroy();
-        variable_instance_set(id, _func_name, undefined);
+    if (is_struct(_handle) && _handle != global.handle_dummy) {
+        if (variable_struct_exists(_handle, "destroy")) {
+            _handle.destroy(); 
+        }
     }
+	variable_instance_set(id, _func_name, global.handle_dummy);
 }