rm for ... in
This commit is contained in:
35
action.cm
35
action.cm
@@ -170,9 +170,9 @@ action.current_device = 'keyboard'
|
||||
action.current_gamepad_type = null
|
||||
|
||||
// Copy defaults
|
||||
for (var key in default_action_map) {
|
||||
arrfor(array(default_action_map), function(key) {
|
||||
action.action_map[key] = array(default_action_map[key])
|
||||
}
|
||||
})
|
||||
|
||||
// Swipe‐recognizer state & tuning
|
||||
var swipe = { x0:null, y0:null, t0:0 }
|
||||
@@ -224,7 +224,7 @@ action.on_input = function(action_id, evt)
|
||||
|
||||
// 3) Otherwise, find all mapped actions for this input
|
||||
var matched_actions = []
|
||||
for (var mapped_action in this.action_map) {
|
||||
arrfor(array(this.action_map), mapped_action => {
|
||||
if (find(this.action_map[mapped_action], action_id) != null) {
|
||||
matched_actions.push(mapped_action)
|
||||
|
||||
@@ -233,7 +233,7 @@ action.on_input = function(action_id, evt)
|
||||
else if (evt.released)
|
||||
this.down[mapped_action] = false
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Send all matched actions (only if we found mappings - this means it's a raw input)
|
||||
if (length(matched_actions) > 0) {
|
||||
@@ -253,11 +253,11 @@ action.rebind_action = function(action_name, new_key) {
|
||||
if (!this.action_map[action_name]) return
|
||||
|
||||
// Remove this key from all other actions
|
||||
for (var act in this.action_map) {
|
||||
arrfor(array(this.action_map), act => {
|
||||
var idx = find(this.action_map[act], new_key)
|
||||
if (idx != null)
|
||||
this.action_map[act].splice(idx, 1)
|
||||
}
|
||||
})
|
||||
|
||||
// Clear existing bindings for the current device from the target action
|
||||
var target_bindings = this.action_map[action_name]
|
||||
@@ -300,11 +300,7 @@ action.get_current_device_binding = function(action_name) {
|
||||
|
||||
action.save_bindings = function() {
|
||||
try {
|
||||
var bindings_data = {}
|
||||
for (var key in this.action_map) {
|
||||
bindings_data[key] = this.action_map[key]
|
||||
}
|
||||
io.slurpwrite('keybindings.json', json.encode(bindings_data))
|
||||
io.slurpwrite('keybindings.json', json.encode(this.action_map))
|
||||
} catch(e) {
|
||||
log.console("Failed to save key bindings:", e)
|
||||
}
|
||||
@@ -314,12 +310,7 @@ action.load_bindings = function() {
|
||||
try {
|
||||
if (io.exists('keybindings.json')) {
|
||||
var data = io.slurp('keybindings.json')
|
||||
var bindings = json.decode(data)
|
||||
for (var key in bindings) {
|
||||
if (this.action_map[key]) {
|
||||
this.action_map[key] = bindings[key]
|
||||
}
|
||||
}
|
||||
var bindings = object(json.decode(data), this.action_map)
|
||||
}
|
||||
} catch(e) {
|
||||
log.console("Failed to load key bindings:", e)
|
||||
@@ -327,25 +318,19 @@ action.load_bindings = function() {
|
||||
}
|
||||
|
||||
action.reset_to_defaults = function() {
|
||||
for (var key in default_action_map) {
|
||||
this.action_map[key] = array(default_action_map[key])
|
||||
}
|
||||
this.action_map = object(default_action_map)
|
||||
this.save_bindings()
|
||||
}
|
||||
|
||||
return function()
|
||||
{
|
||||
var obj = meme(action)
|
||||
obj.action_map = {}
|
||||
obj.action_map = object(default_action_map)
|
||||
obj.display_names = action_display_names
|
||||
obj.is_rebinding = false
|
||||
obj.rebind_target = null
|
||||
obj.current_device = 'keyboard'
|
||||
obj.current_gamepad_type = null
|
||||
// Copy defaults
|
||||
for (var key in default_action_map) {
|
||||
obj.action_map[key] = array(default_action_map[key])
|
||||
}
|
||||
obj.load_bindings()
|
||||
return obj
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user