rm for ... in

This commit is contained in:
2026-01-19 18:57:25 -06:00
parent 1d78e725bb
commit 027435d193
22 changed files with 102 additions and 174 deletions

View File

@@ -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])
}
})
// Swiperecognizer 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
}

34
clay.cm
View File

@@ -213,7 +213,7 @@ function build_drawables(node, root_height, parent_abs_x, parent_abs_y, parent_s
// --- Item Creation Helpers ---
function process_configs(configs) {
var cfg = meme(base_config, ...configs)
var cfg = meme(base_config, configs)
cfg.color = normalize_color(cfg.color, base_config.color)
if (cfg.background_color) cfg.background_color = normalize_color(cfg.background_color, {r:1,g:1,b:1,a:1})
@@ -304,41 +304,47 @@ clay.zstack = function(configs, fn) {
}
// Leaf nodes
clay.image = function(path, ...configs) {
clay.image = function(path, configs) {
var img = graphics.texture(path)
var c = {image: path}
var c = [{image: path}]
var final_config = process_configs(configs)
if (!final_config.size && !final_config.behave) {
if (!final_config.size && !final_config.behave)
c.size = {width: img.width, height: img.height}
}
if (!is_array(configs)) configs = [configs]
push_node([c, ...configs], null)
push_node(array(c, configs), null)
pop_node()
}
clay.text = function(str, ...configs) {
var c = {text: str}
clay.text = function(str, configs) {
var c = [{text: str}]
var final_config = process_configs(configs)
if (!final_config.size && !final_config.behave) {
c.size = {width: 100, height: 20}
}
if (!is_array(configs)) configs = [configs]
push_node([c, ...configs], null)
push_node(array(c, configs), null)
pop_node()
}
clay.rectangle = function(...configs) {
clay.rectangle = function(configs) {
if (!is_array(configs)) configs = [configs]
push_node(configs, null)
pop_node()
}
clay.button = function(str, action, ...configs) {
var btn_config = {
clay.button = function(str, action, configs) {
var btn_config = [{
padding: 10,
background_color: {r:0.3, g:0.3, b:0.4, a:1}
}
}]
clay.zstack([btn_config, ...configs], function() {
if (!is_array(configs)) configs = [configs]
clay.zstack(array(btn_config, configs), function() {
clay.text(str, {color: {r:1,g:1,b:1,a:1}})
})
}

View File

@@ -56,13 +56,13 @@ function compile_plane(plane_config, ctx, group_effects) {
// Build set of groups used as masks (these should not be drawn directly)
var mask_groups = {}
for (var gname in group_effects) {
arrfor(array(group_effects), gname => {
var effects = group_effects[gname].effects || []
for (var e = 0; e < length(effects); e++) {
if (effects[e].type == 'mask' && effects[e].mask_group)
mask_groups[effects[e].mask_group] = true
}
}
})
// Get all sprites in this plane
var all_sprites = film2d.query({plane: plane_name})
@@ -116,9 +116,9 @@ function compile_plane(plane_config, ctx, group_effects) {
ctx.passes.push({type: 'clear', target: plane_target, color: plane_config.clear})
// Render each effect group to temp target, apply effects, composite back
for (var gname in effect_groups) {
arrfor(array(effect_groups), gname => {
var eg = effect_groups[gname]
if (length(eg.sprites) == 0) continue
if (length(eg.sprites) == 0) return
var group_target = ctx.alloc(res.width, res.height, gname + '_content')
@@ -150,7 +150,7 @@ function compile_plane(plane_config, ctx, group_effects) {
dest_size: res,
blend: 'over'
})
}
})
// Render base sprites (no effects)
if (length(base_sprites) > 0) {
@@ -249,10 +249,10 @@ function apply_effect(ctx, effect, input, size, camera, hint, current_plane, gro
compositor.execute = function(plan) {
var cache = {}
for (var key in plan.targets) {
arrfor(array(plan.targets), key => {
var spec = plan.targets[key]
cache[key] = backend.get_or_create_target(spec.width, spec.height, key)
}
})
function resolve(t) {
if (t == 'screen') return 'screen'

View File

@@ -248,7 +248,7 @@ function _render_node_inspector(imgui, node) {
for (var i = 0; i < length(node.effects); i++) {
var fx = node.effects[i]
imgui.tree(fx.type, function() {
for (var k in fx) {
arrfor(array(fx), k => {
if (k != 'type' && k != 'source') {
var v = fx[k]
if (is_number(v)) {
@@ -257,7 +257,7 @@ function _render_node_inspector(imgui, node) {
imgui.text(k + ": " + text(v))
}
}
}
})
})
}
}
@@ -358,14 +358,14 @@ function _render_pass_inspector(imgui, pass) {
if (pass.uniforms) {
imgui.text("---")
imgui.text("Uniforms:")
for (var k in pass.uniforms) {
arrfor(array(pass.uniforms), k => {
var v = pass.uniforms[k]
if (is_array(v)) {
imgui.text(" " + k + ": [" + text(v, ", ") + "]")
} else {
imgui.text(" " + k + ": " + text(v))
}
}
})
}
// Clear color
@@ -407,14 +407,14 @@ function _render_effects_panel(imgui) {
if (deff.params) {
imgui.text("Parameters:")
for (var k in deff.params) {
arrfor(array(deff.params), k => {
var p = deff.params[k]
var info = k
if (p.default != null) info += " = " + text(p.default)
if (p.type) info += " (" + p.type + ")"
if (p.required) info += " [required]"
imgui.text(" " + info)
}
})
}
})
}
@@ -465,19 +465,19 @@ function _render_targets(imgui, plan) {
imgui.text("Temporary Targets:")
if (plan.targets) {
for (var key in plan.targets) {
arrfor(array(plan.targets), key => {
var t = plan.targets[key]
imgui.text(" " + key + ": " + text(t.width) + "x" + text(t.height))
}
})
}
imgui.text("---")
imgui.text("Persistent Targets:")
if (plan.persistent_targets) {
for (var key in plan.persistent_targets) {
arrfor(array(plan.persistent_targets), key => {
var t = plan.persistent_targets[key]
imgui.text(" " + key + ": " + text(t.width) + "x" + text(t.height ))
}
})
}
})
}

View File

@@ -18,9 +18,7 @@ effects.get = function(name) {
}
effects.list = function() {
var names = []
for (var k in _effects) names.push(k)
return names
return array(_effects)
}
// Built-in effect: Bloom
@@ -367,11 +365,11 @@ effects.default_params = function(effect_type) {
if (!deff || !deff.params) return {}
var defaults = {}
for (var k in deff.params) {
arrfor(array(deff.params), k => {
if (deff.params[k].default != null) {
defaults[k] = deff.params[k].default
}
}
})
return defaults
}
@@ -380,11 +378,11 @@ effects.validate_params = function(effect_type, params) {
var deff = _effects[effect_type]
if (!deff || !deff.params) return true
for (var k in deff.params) {
arrfor(array(deff.params), k => {
if (deff.params[k].required && params[k] == null) {
return false
}
}
})
return true
}

View File

@@ -3,7 +3,6 @@ var render = use('render')
var graphics = use('graphics')
var sprite = use('sprite')
var geom = use('geometry')
var input = use('controller')
var config = use('config')
var color = use('color')
var random = use('random')

View File

@@ -1,6 +1,5 @@
// main.js
var draw = use('draw2d')
var input = use('controller')
var config = use('config')
var color = use('color')
var random = use('random')

View File

@@ -227,10 +227,8 @@ film2d.query = function(selector) {
}
// All drawables
for (var id in registry) {
var d = registry[id]
if (d && d.visible != false) result.push(d)
}
var draws = array(registry, id => registry[id])
result = array(result, filter(draws, d => d.visible != false))
return result
}
@@ -243,8 +241,9 @@ film2d.get_groups = function(id) {
// List all known groups
film2d.all_groups = function() {
var groups = []
for (var g in group_index)
arrfor(array(group_index), g => {
if (length(group_index[g]) > 0) groups.push(g)
})
return groups
}

View File

@@ -105,13 +105,13 @@ fx_graph.execute = function(backend) {
fx_graph.resolve_inputs = function(params, node_outputs) {
var resolved = {}
for (var key in params) {
arrfor(array(params), key => {
var value = params[key]
if (value && value.node_id != null)
resolved[key] = node_outputs[value.node_id]
else
resolved[key] = value
}
})
return resolved
}

View File

@@ -178,7 +178,9 @@ function create_image(path){
return makeAnim(wrapFrames(raw.frames), !!raw.loop);
def anims = {};
arrfor(Object.entries(raw), function([name, anim]) {
var keys = array(raw)
arrfor(keys, function(name) {
var anim = raw[name]
if(anim && is_array(anim.frames))
anims[name] = makeAnim(wrapFrames(anim.frames), !!anim.loop);
else if(anim && anim.surface)

View File

@@ -47,20 +47,18 @@ function create_user(index, config) {
var display_names = {}
// Merge defaults with config
for (var k in default_action_map) {
arrfor(array(default_action_map), function(k) {
action_map[k] = array(default_action_map[k])
display_names[k] = default_display_names[k]
}
})
if (config.action_map) {
for (var k in config.action_map) {
arrfor(array(config.action_map), function(k) {
var val = config.action_map[k]
action_map[k] = is_array(val) ? array(val) : [val]
}
})
}
if (config.display_names) {
for (var k in config.display_names) {
display_names[k] = config.display_names[k]
}
arrfor(array(config.display_names), k => display_names[k] = config.display_names[k])
}
var user = {
@@ -160,11 +158,11 @@ function pick_user(canon) {
if (user.active_device != canon.device_id) {
// Release all held actions when switching device
var old_down = user.router.down
for (var action in old_down) {
arrfor(array(old_down), action => {
if (old_down[action]) {
user.dispatch(action, { pressed: false, released: true, time: canon.time })
}
}
})
user.active_device = canon.device_id
if (find(user.paired_devices, canon.device_id) == null) {

View File

@@ -30,27 +30,21 @@ function make(defaults, display_names) {
}
// Copy defaults
for (var key in defaults) {
arrfor(array(defaults), function(key){
var val = defaults[key]
bindings.action_map[key] = is_array(val) ? array(val) : [val]
bindings._defaults[key] = array(bindings.action_map[key])
}
})
// Get actions that match a control
bindings.get_actions = function(control) {
var result = []
for (var action in this.action_map) {
if (find(this.action_map[action], control) != null) {
result.push(action)
}
}
return result
return filter(array(this.action_map), action => find(this.action_map[action], control) != null)
}
// Get bindings for a specific device kind
bindings.get_bindings_for_device = function(action, device_kind) {
var all = this.action_map[action] || []
return filter(all, function(control) {
return filter(all, control => {
if (device_kind == 'keyboard') {
return !starts_with(control, 'gamepad_') && !starts_with(control, 'swipe_') && !starts_with(control, 'touch')
}
@@ -139,10 +133,10 @@ function make(defaults, display_names) {
if (!this.action_map[action]) return false
// Remove from other actions
for (var act in this.action_map) {
arrfor(array(this.action_map), act => {
var idx = search(this.action_map[act], new_control)
if (idx >= 0) this.action_map[act].splice(idx, 1)
}
})
// Clear existing bindings for this device kind
var target = this.action_map[action]
@@ -184,11 +178,9 @@ function make(defaults, display_names) {
try {
if (io.exists(path)) {
var data = json.decode(io.slurp(path))
for (var key in data) {
if (this.action_map[key]) {
this.action_map[key] = data[key]
}
}
arrfor(array(data), key => {
if (this.action_map[key]) this.action_map[key] = data[key]
})
return true
}
} catch(e) {}
@@ -197,9 +189,9 @@ function make(defaults, display_names) {
// Reset to defaults
bindings.reset = function() {
for (var key in this._defaults) {
arrfor(array(this._defaults), key => {
this.action_map[key] = array(this._defaults[key])
}
})
}
return bindings

View File

@@ -52,16 +52,14 @@ function gamepad_type(device_id) {
// List all registered devices
function list() {
return Object.keys(_devices)
return array(_devices)
}
// List devices of a specific kind
function list_by_kind(kind) {
var result = []
for (var id in _devices) {
if (_devices[id].kind == kind) result.push(id)
}
return result
return filter(array(_devices), function(id) {
return _devices[id].kind == kind
})
}
return {

View File

@@ -371,26 +371,7 @@ var defaults = {
}
function make_line(props) {
var data = {}
for (var k in defaults) {
var v = defaults[k]
if (is_object(v) && !is_array(v)) {
data[k] = {}
for (var kk in v) data[k][kk] = v[kk]
} else {
data[k] = v
}
}
// Apply user props (deep merge for objects)
for (var k in props) {
var v = props[k]
if (is_object(v) && !is_array(v) && is_object(data[k])) {
for (var kk in v) data[k][kk] = v[kk]
} else {
data[k] = v
}
}
var data = object(defaults, props)
// Ensure groups is array
if (!data.groups) data.groups = []

View File

@@ -128,9 +128,7 @@ var factory = function(props) {
tint: {r: 1, g: 1, b: 1, a: 1}
}
var data = {}
for(var k in defaults) data[k] = defaults[k]
for(var k in props) data[k] = props[k]
var data = object(defaults, props)
var newparticles = meme(particles2d_proto, data)
film2d.register(newparticles)

View File

@@ -1127,9 +1127,9 @@ function _preload_textures(commands) {
})
// Load all textures
for (var path in paths) {
arrfor(array(paths, function(path) {
sdl_gpu.get_texture(path)
}
}))
}
function _execute_commands(commands, window_size) {

View File

@@ -71,28 +71,7 @@ var defaults = {
}
function make_shape(shape_type, props) {
var data = {}
for (var k in defaults) {
var v = defaults[k]
if (is_object(v) && !is_array(v)) {
data[k] = {}
for (var kk in v) data[k][kk] = v[kk]
} else {
data[k] = v
}
}
data.shape_type = shape_type
// Apply user props (deep merge for objects)
for (var k in props) {
var v = props[k]
if (is_object(v) && !is_array(v) && is_object(data[k])) {
for (var kk in v) data[k][kk] = v[kk]
} else {
data[k] = v
}
}
var data = object(defaults, props)
// Ensure groups is array
if (!data.groups) data.groups = []

View File

@@ -33,9 +33,7 @@ return function(props) {
visible: true
}
var data = {}
for (var k in defaults) data[k] = defaults[k]
for (var k in props) data[k] = props[k]
var data = object(defaults, props)
// Ensure groups is array
if (!data.groups) data.groups = []

View File

@@ -27,14 +27,14 @@ for (var i = 0; i < length(formats); i++) {
}
log.console("\nFound colorspaces:");
for (var cs in colorspaces) {
log.console(" " + cs + ": " + length(colorspaces[cs]) + " formats");
}
arrfor(array(colorspaces), function(key) {
log.console(" " + key + ": " + length(colorspaces[key]) + " formats");
})
// Try opening camera with different colorspaces
log.console("\nTrying to open camera with different colorspaces...");
for (var cs in colorspaces) {
arrfor(array(colorspaces), function(cs) {
// Get first format for this colorspace
var format = colorspaces[cs][0];
@@ -66,7 +66,7 @@ for (var cs in colorspaces) {
// Just test first 3 colorspaces
if (find(array(colorspaces), cs) >= 2) break;
}
})
log.console("\nColorspace test complete!");
$stop();

View File

@@ -43,9 +43,7 @@ return function(props) {
outline_color: null
}
var data = {}
for(var k in defaults) data[k] = defaults[k]
for(var k in props) data[k] = props[k]
var data = object(defaults, props)
var newtext = meme(text2d_proto, data)
film2d.register(newtext)

View File

@@ -54,9 +54,7 @@ return function(props) {
tint: {r: 1, g: 1, b: 1, a: 1}
}
var data = {}
for(var k in defaults) data[k] = defaults[k]
for(var k in props) data[k] = props[k]
var data = object(defaults, props)
var newtilemap = meme(tilemap, data)
film2d.register(newtilemap)

View File

@@ -42,19 +42,19 @@ var TweenProto = {
engine: null,
to: function(props, duration, start_time) {
for (var key in props) {
arrfor(array(props), key => {
var value = props[key]
if (is_object(value)) {
for (var subkey in value) {
arrfor(array(value), subkey => {
var flatKey = key + '.' + subkey
this.startVals[flatKey] = this.obj[key] ? this.obj[key][subkey] : undefined
this.endVals[flatKey] = value[subkey]
}
})
} else {
this.startVals[key] = this.obj[key]
this.endVals[key] = value
}
}
})
this.duration = duration
@@ -95,7 +95,7 @@ var TweenProto = {
var t = min(max(elapsed / this.duration, 0), 1)
var eased = this.easing(t)
for (var key in this.endVals) {
arrfor(array(this.endVals), key => {
var start = this.startVals[key]
var end = this.endVals[key]
var value = start + (end - start) * eased
@@ -113,7 +113,7 @@ var TweenProto = {
} else {
this.obj[key] = value
}
}
})
if (t == 1 && this.engine) {
this.onCompleteCallback()