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
|
action.current_gamepad_type = null
|
||||||
|
|
||||||
// Copy defaults
|
// 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])
|
action.action_map[key] = array(default_action_map[key])
|
||||||
}
|
})
|
||||||
|
|
||||||
// Swipe‐recognizer state & tuning
|
// Swipe‐recognizer state & tuning
|
||||||
var swipe = { x0:null, y0:null, t0:0 }
|
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
|
// 3) Otherwise, find all mapped actions for this input
|
||||||
var matched_actions = []
|
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) {
|
if (find(this.action_map[mapped_action], action_id) != null) {
|
||||||
matched_actions.push(mapped_action)
|
matched_actions.push(mapped_action)
|
||||||
|
|
||||||
@@ -233,7 +233,7 @@ action.on_input = function(action_id, evt)
|
|||||||
else if (evt.released)
|
else if (evt.released)
|
||||||
this.down[mapped_action] = false
|
this.down[mapped_action] = false
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
// Send all matched actions (only if we found mappings - this means it's a raw input)
|
// Send all matched actions (only if we found mappings - this means it's a raw input)
|
||||||
if (length(matched_actions) > 0) {
|
if (length(matched_actions) > 0) {
|
||||||
@@ -253,11 +253,11 @@ action.rebind_action = function(action_name, new_key) {
|
|||||||
if (!this.action_map[action_name]) return
|
if (!this.action_map[action_name]) return
|
||||||
|
|
||||||
// Remove this key from all other actions
|
// 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)
|
var idx = find(this.action_map[act], new_key)
|
||||||
if (idx != null)
|
if (idx != null)
|
||||||
this.action_map[act].splice(idx, 1)
|
this.action_map[act].splice(idx, 1)
|
||||||
}
|
})
|
||||||
|
|
||||||
// Clear existing bindings for the current device from the target action
|
// Clear existing bindings for the current device from the target action
|
||||||
var target_bindings = this.action_map[action_name]
|
var target_bindings = this.action_map[action_name]
|
||||||
@@ -300,11 +300,7 @@ action.get_current_device_binding = function(action_name) {
|
|||||||
|
|
||||||
action.save_bindings = function() {
|
action.save_bindings = function() {
|
||||||
try {
|
try {
|
||||||
var bindings_data = {}
|
io.slurpwrite('keybindings.json', json.encode(this.action_map))
|
||||||
for (var key in this.action_map) {
|
|
||||||
bindings_data[key] = this.action_map[key]
|
|
||||||
}
|
|
||||||
io.slurpwrite('keybindings.json', json.encode(bindings_data))
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
log.console("Failed to save key bindings:", e)
|
log.console("Failed to save key bindings:", e)
|
||||||
}
|
}
|
||||||
@@ -314,12 +310,7 @@ action.load_bindings = function() {
|
|||||||
try {
|
try {
|
||||||
if (io.exists('keybindings.json')) {
|
if (io.exists('keybindings.json')) {
|
||||||
var data = io.slurp('keybindings.json')
|
var data = io.slurp('keybindings.json')
|
||||||
var bindings = json.decode(data)
|
var bindings = object(json.decode(data), this.action_map)
|
||||||
for (var key in bindings) {
|
|
||||||
if (this.action_map[key]) {
|
|
||||||
this.action_map[key] = bindings[key]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
log.console("Failed to load key bindings:", e)
|
log.console("Failed to load key bindings:", e)
|
||||||
@@ -327,25 +318,19 @@ action.load_bindings = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
action.reset_to_defaults = function() {
|
action.reset_to_defaults = function() {
|
||||||
for (var key in default_action_map) {
|
this.action_map = object(default_action_map)
|
||||||
this.action_map[key] = array(default_action_map[key])
|
|
||||||
}
|
|
||||||
this.save_bindings()
|
this.save_bindings()
|
||||||
}
|
}
|
||||||
|
|
||||||
return function()
|
return function()
|
||||||
{
|
{
|
||||||
var obj = meme(action)
|
var obj = meme(action)
|
||||||
obj.action_map = {}
|
obj.action_map = object(default_action_map)
|
||||||
obj.display_names = action_display_names
|
obj.display_names = action_display_names
|
||||||
obj.is_rebinding = false
|
obj.is_rebinding = false
|
||||||
obj.rebind_target = null
|
obj.rebind_target = null
|
||||||
obj.current_device = 'keyboard'
|
obj.current_device = 'keyboard'
|
||||||
obj.current_gamepad_type = null
|
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()
|
obj.load_bindings()
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|||||||
34
clay.cm
34
clay.cm
@@ -213,7 +213,7 @@ function build_drawables(node, root_height, parent_abs_x, parent_abs_y, parent_s
|
|||||||
// --- Item Creation Helpers ---
|
// --- Item Creation Helpers ---
|
||||||
|
|
||||||
function process_configs(configs) {
|
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)
|
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})
|
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
|
// Leaf nodes
|
||||||
clay.image = function(path, ...configs) {
|
clay.image = function(path, configs) {
|
||||||
var img = graphics.texture(path)
|
var img = graphics.texture(path)
|
||||||
var c = {image: path}
|
var c = [{image: path}]
|
||||||
var final_config = process_configs(configs)
|
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}
|
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()
|
pop_node()
|
||||||
}
|
}
|
||||||
|
|
||||||
clay.text = function(str, ...configs) {
|
clay.text = function(str, configs) {
|
||||||
var c = {text: str}
|
var c = [{text: str}]
|
||||||
var final_config = process_configs(configs)
|
var final_config = process_configs(configs)
|
||||||
if (!final_config.size && !final_config.behave) {
|
if (!final_config.size && !final_config.behave) {
|
||||||
c.size = {width: 100, height: 20}
|
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()
|
pop_node()
|
||||||
}
|
}
|
||||||
|
|
||||||
clay.rectangle = function(...configs) {
|
clay.rectangle = function(configs) {
|
||||||
|
if (!is_array(configs)) configs = [configs]
|
||||||
push_node(configs, null)
|
push_node(configs, null)
|
||||||
pop_node()
|
pop_node()
|
||||||
}
|
}
|
||||||
|
|
||||||
clay.button = function(str, action, ...configs) {
|
clay.button = function(str, action, configs) {
|
||||||
var btn_config = {
|
var btn_config = [{
|
||||||
padding: 10,
|
padding: 10,
|
||||||
background_color: {r:0.3, g:0.3, b:0.4, a:1}
|
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}})
|
clay.text(str, {color: {r:1,g:1,b:1,a:1}})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
// Build set of groups used as masks (these should not be drawn directly)
|
||||||
var mask_groups = {}
|
var mask_groups = {}
|
||||||
for (var gname in group_effects) {
|
arrfor(array(group_effects), gname => {
|
||||||
var effects = group_effects[gname].effects || []
|
var effects = group_effects[gname].effects || []
|
||||||
for (var e = 0; e < length(effects); e++) {
|
for (var e = 0; e < length(effects); e++) {
|
||||||
if (effects[e].type == 'mask' && effects[e].mask_group)
|
if (effects[e].type == 'mask' && effects[e].mask_group)
|
||||||
mask_groups[effects[e].mask_group] = true
|
mask_groups[effects[e].mask_group] = true
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
// Get all sprites in this plane
|
// Get all sprites in this plane
|
||||||
var all_sprites = film2d.query({plane: plane_name})
|
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})
|
ctx.passes.push({type: 'clear', target: plane_target, color: plane_config.clear})
|
||||||
|
|
||||||
// Render each effect group to temp target, apply effects, composite back
|
// 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]
|
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')
|
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,
|
dest_size: res,
|
||||||
blend: 'over'
|
blend: 'over'
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
|
|
||||||
// Render base sprites (no effects)
|
// Render base sprites (no effects)
|
||||||
if (length(base_sprites) > 0) {
|
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) {
|
compositor.execute = function(plan) {
|
||||||
var cache = {}
|
var cache = {}
|
||||||
|
|
||||||
for (var key in plan.targets) {
|
arrfor(array(plan.targets), key => {
|
||||||
var spec = plan.targets[key]
|
var spec = plan.targets[key]
|
||||||
cache[key] = backend.get_or_create_target(spec.width, spec.height, key)
|
cache[key] = backend.get_or_create_target(spec.width, spec.height, key)
|
||||||
}
|
})
|
||||||
|
|
||||||
function resolve(t) {
|
function resolve(t) {
|
||||||
if (t == 'screen') return 'screen'
|
if (t == 'screen') return 'screen'
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ function _render_node_inspector(imgui, node) {
|
|||||||
for (var i = 0; i < length(node.effects); i++) {
|
for (var i = 0; i < length(node.effects); i++) {
|
||||||
var fx = node.effects[i]
|
var fx = node.effects[i]
|
||||||
imgui.tree(fx.type, function() {
|
imgui.tree(fx.type, function() {
|
||||||
for (var k in fx) {
|
arrfor(array(fx), k => {
|
||||||
if (k != 'type' && k != 'source') {
|
if (k != 'type' && k != 'source') {
|
||||||
var v = fx[k]
|
var v = fx[k]
|
||||||
if (is_number(v)) {
|
if (is_number(v)) {
|
||||||
@@ -257,7 +257,7 @@ function _render_node_inspector(imgui, node) {
|
|||||||
imgui.text(k + ": " + text(v))
|
imgui.text(k + ": " + text(v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -358,14 +358,14 @@ function _render_pass_inspector(imgui, pass) {
|
|||||||
if (pass.uniforms) {
|
if (pass.uniforms) {
|
||||||
imgui.text("---")
|
imgui.text("---")
|
||||||
imgui.text("Uniforms:")
|
imgui.text("Uniforms:")
|
||||||
for (var k in pass.uniforms) {
|
arrfor(array(pass.uniforms), k => {
|
||||||
var v = pass.uniforms[k]
|
var v = pass.uniforms[k]
|
||||||
if (is_array(v)) {
|
if (is_array(v)) {
|
||||||
imgui.text(" " + k + ": [" + text(v, ", ") + "]")
|
imgui.text(" " + k + ": [" + text(v, ", ") + "]")
|
||||||
} else {
|
} else {
|
||||||
imgui.text(" " + k + ": " + text(v))
|
imgui.text(" " + k + ": " + text(v))
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear color
|
// Clear color
|
||||||
@@ -407,14 +407,14 @@ function _render_effects_panel(imgui) {
|
|||||||
|
|
||||||
if (deff.params) {
|
if (deff.params) {
|
||||||
imgui.text("Parameters:")
|
imgui.text("Parameters:")
|
||||||
for (var k in deff.params) {
|
arrfor(array(deff.params), k => {
|
||||||
var p = deff.params[k]
|
var p = deff.params[k]
|
||||||
var info = k
|
var info = k
|
||||||
if (p.default != null) info += " = " + text(p.default)
|
if (p.default != null) info += " = " + text(p.default)
|
||||||
if (p.type) info += " (" + p.type + ")"
|
if (p.type) info += " (" + p.type + ")"
|
||||||
if (p.required) info += " [required]"
|
if (p.required) info += " [required]"
|
||||||
imgui.text(" " + info)
|
imgui.text(" " + info)
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -465,19 +465,19 @@ function _render_targets(imgui, plan) {
|
|||||||
|
|
||||||
imgui.text("Temporary Targets:")
|
imgui.text("Temporary Targets:")
|
||||||
if (plan.targets) {
|
if (plan.targets) {
|
||||||
for (var key in plan.targets) {
|
arrfor(array(plan.targets), key => {
|
||||||
var t = plan.targets[key]
|
var t = plan.targets[key]
|
||||||
imgui.text(" " + key + ": " + text(t.width) + "x" + text(t.height))
|
imgui.text(" " + key + ": " + text(t.width) + "x" + text(t.height))
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
imgui.text("---")
|
imgui.text("---")
|
||||||
imgui.text("Persistent Targets:")
|
imgui.text("Persistent Targets:")
|
||||||
if (plan.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]
|
var t = plan.persistent_targets[key]
|
||||||
imgui.text(" " + key + ": " + text(t.width) + "x" + text(t.height ))
|
imgui.text(" " + key + ": " + text(t.width) + "x" + text(t.height ))
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
12
effects.cm
12
effects.cm
@@ -18,9 +18,7 @@ effects.get = function(name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
effects.list = function() {
|
effects.list = function() {
|
||||||
var names = []
|
return array(_effects)
|
||||||
for (var k in _effects) names.push(k)
|
|
||||||
return names
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Built-in effect: Bloom
|
// Built-in effect: Bloom
|
||||||
@@ -367,11 +365,11 @@ effects.default_params = function(effect_type) {
|
|||||||
if (!deff || !deff.params) return {}
|
if (!deff || !deff.params) return {}
|
||||||
|
|
||||||
var defaults = {}
|
var defaults = {}
|
||||||
for (var k in deff.params) {
|
arrfor(array(deff.params), k => {
|
||||||
if (deff.params[k].default != null) {
|
if (deff.params[k].default != null) {
|
||||||
defaults[k] = deff.params[k].default
|
defaults[k] = deff.params[k].default
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
return defaults
|
return defaults
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,11 +378,11 @@ effects.validate_params = function(effect_type, params) {
|
|||||||
var deff = _effects[effect_type]
|
var deff = _effects[effect_type]
|
||||||
if (!deff || !deff.params) return true
|
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) {
|
if (deff.params[k].required && params[k] == null) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ var render = use('render')
|
|||||||
var graphics = use('graphics')
|
var graphics = use('graphics')
|
||||||
var sprite = use('sprite')
|
var sprite = use('sprite')
|
||||||
var geom = use('geometry')
|
var geom = use('geometry')
|
||||||
var input = use('controller')
|
|
||||||
var config = use('config')
|
var config = use('config')
|
||||||
var color = use('color')
|
var color = use('color')
|
||||||
var random = use('random')
|
var random = use('random')
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// main.js
|
// main.js
|
||||||
var draw = use('draw2d')
|
var draw = use('draw2d')
|
||||||
var input = use('controller')
|
|
||||||
var config = use('config')
|
var config = use('config')
|
||||||
var color = use('color')
|
var color = use('color')
|
||||||
var random = use('random')
|
var random = use('random')
|
||||||
|
|||||||
@@ -227,10 +227,8 @@ film2d.query = function(selector) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// All drawables
|
// All drawables
|
||||||
for (var id in registry) {
|
var draws = array(registry, id => registry[id])
|
||||||
var d = registry[id]
|
result = array(result, filter(draws, d => d.visible != false))
|
||||||
if (d && d.visible != false) result.push(d)
|
|
||||||
}
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,8 +241,9 @@ film2d.get_groups = function(id) {
|
|||||||
// List all known groups
|
// List all known groups
|
||||||
film2d.all_groups = function() {
|
film2d.all_groups = function() {
|
||||||
var groups = []
|
var groups = []
|
||||||
for (var g in group_index)
|
arrfor(array(group_index), g => {
|
||||||
if (length(group_index[g]) > 0) groups.push(g)
|
if (length(group_index[g]) > 0) groups.push(g)
|
||||||
|
})
|
||||||
return groups
|
return groups
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,13 +105,13 @@ fx_graph.execute = function(backend) {
|
|||||||
|
|
||||||
fx_graph.resolve_inputs = function(params, node_outputs) {
|
fx_graph.resolve_inputs = function(params, node_outputs) {
|
||||||
var resolved = {}
|
var resolved = {}
|
||||||
for (var key in params) {
|
arrfor(array(params), key => {
|
||||||
var value = params[key]
|
var value = params[key]
|
||||||
if (value && value.node_id != null)
|
if (value && value.node_id != null)
|
||||||
resolved[key] = node_outputs[value.node_id]
|
resolved[key] = node_outputs[value.node_id]
|
||||||
else
|
else
|
||||||
resolved[key] = value
|
resolved[key] = value
|
||||||
}
|
})
|
||||||
return resolved
|
return resolved
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -178,7 +178,9 @@ function create_image(path){
|
|||||||
return makeAnim(wrapFrames(raw.frames), !!raw.loop);
|
return makeAnim(wrapFrames(raw.frames), !!raw.loop);
|
||||||
|
|
||||||
def anims = {};
|
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))
|
if(anim && is_array(anim.frames))
|
||||||
anims[name] = makeAnim(wrapFrames(anim.frames), !!anim.loop);
|
anims[name] = makeAnim(wrapFrames(anim.frames), !!anim.loop);
|
||||||
else if(anim && anim.surface)
|
else if(anim && anim.surface)
|
||||||
|
|||||||
16
input.cm
16
input.cm
@@ -47,20 +47,18 @@ function create_user(index, config) {
|
|||||||
var display_names = {}
|
var display_names = {}
|
||||||
|
|
||||||
// Merge defaults with config
|
// 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])
|
action_map[k] = array(default_action_map[k])
|
||||||
display_names[k] = default_display_names[k]
|
display_names[k] = default_display_names[k]
|
||||||
}
|
})
|
||||||
if (config.action_map) {
|
if (config.action_map) {
|
||||||
for (var k in config.action_map) {
|
arrfor(array(config.action_map), function(k) {
|
||||||
var val = config.action_map[k]
|
var val = config.action_map[k]
|
||||||
action_map[k] = is_array(val) ? array(val) : [val]
|
action_map[k] = is_array(val) ? array(val) : [val]
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
if (config.display_names) {
|
if (config.display_names) {
|
||||||
for (var k in config.display_names) {
|
arrfor(array(config.display_names), k => display_names[k] = config.display_names[k])
|
||||||
display_names[k] = config.display_names[k]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var user = {
|
var user = {
|
||||||
@@ -160,11 +158,11 @@ function pick_user(canon) {
|
|||||||
if (user.active_device != canon.device_id) {
|
if (user.active_device != canon.device_id) {
|
||||||
// Release all held actions when switching device
|
// Release all held actions when switching device
|
||||||
var old_down = user.router.down
|
var old_down = user.router.down
|
||||||
for (var action in old_down) {
|
arrfor(array(old_down), action => {
|
||||||
if (old_down[action]) {
|
if (old_down[action]) {
|
||||||
user.dispatch(action, { pressed: false, released: true, time: canon.time })
|
user.dispatch(action, { pressed: false, released: true, time: canon.time })
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
user.active_device = canon.device_id
|
user.active_device = canon.device_id
|
||||||
if (find(user.paired_devices, canon.device_id) == null) {
|
if (find(user.paired_devices, canon.device_id) == null) {
|
||||||
|
|||||||
@@ -30,27 +30,21 @@ function make(defaults, display_names) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy defaults
|
// Copy defaults
|
||||||
for (var key in defaults) {
|
arrfor(array(defaults), function(key){
|
||||||
var val = defaults[key]
|
var val = defaults[key]
|
||||||
bindings.action_map[key] = is_array(val) ? array(val) : [val]
|
bindings.action_map[key] = is_array(val) ? array(val) : [val]
|
||||||
bindings._defaults[key] = array(bindings.action_map[key])
|
bindings._defaults[key] = array(bindings.action_map[key])
|
||||||
}
|
})
|
||||||
|
|
||||||
// Get actions that match a control
|
// Get actions that match a control
|
||||||
bindings.get_actions = function(control) {
|
bindings.get_actions = function(control) {
|
||||||
var result = []
|
return filter(array(this.action_map), action => find(this.action_map[action], control) != null)
|
||||||
for (var action in this.action_map) {
|
|
||||||
if (find(this.action_map[action], control) != null) {
|
|
||||||
result.push(action)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get bindings for a specific device kind
|
// Get bindings for a specific device kind
|
||||||
bindings.get_bindings_for_device = function(action, device_kind) {
|
bindings.get_bindings_for_device = function(action, device_kind) {
|
||||||
var all = this.action_map[action] || []
|
var all = this.action_map[action] || []
|
||||||
return filter(all, function(control) {
|
return filter(all, control => {
|
||||||
if (device_kind == 'keyboard') {
|
if (device_kind == 'keyboard') {
|
||||||
return !starts_with(control, 'gamepad_') && !starts_with(control, 'swipe_') && !starts_with(control, 'touch')
|
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
|
if (!this.action_map[action]) return false
|
||||||
|
|
||||||
// Remove from other actions
|
// 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)
|
var idx = search(this.action_map[act], new_control)
|
||||||
if (idx >= 0) this.action_map[act].splice(idx, 1)
|
if (idx >= 0) this.action_map[act].splice(idx, 1)
|
||||||
}
|
})
|
||||||
|
|
||||||
// Clear existing bindings for this device kind
|
// Clear existing bindings for this device kind
|
||||||
var target = this.action_map[action]
|
var target = this.action_map[action]
|
||||||
@@ -184,11 +178,9 @@ function make(defaults, display_names) {
|
|||||||
try {
|
try {
|
||||||
if (io.exists(path)) {
|
if (io.exists(path)) {
|
||||||
var data = json.decode(io.slurp(path))
|
var data = json.decode(io.slurp(path))
|
||||||
for (var key in data) {
|
arrfor(array(data), key => {
|
||||||
if (this.action_map[key]) {
|
if (this.action_map[key]) this.action_map[key] = data[key]
|
||||||
this.action_map[key] = data[key]
|
})
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
} catch(e) {}
|
} catch(e) {}
|
||||||
@@ -197,9 +189,9 @@ function make(defaults, display_names) {
|
|||||||
|
|
||||||
// Reset to defaults
|
// Reset to defaults
|
||||||
bindings.reset = function() {
|
bindings.reset = function() {
|
||||||
for (var key in this._defaults) {
|
arrfor(array(this._defaults), key => {
|
||||||
this.action_map[key] = array(this._defaults[key])
|
this.action_map[key] = array(this._defaults[key])
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return bindings
|
return bindings
|
||||||
|
|||||||
@@ -52,16 +52,14 @@ function gamepad_type(device_id) {
|
|||||||
|
|
||||||
// List all registered devices
|
// List all registered devices
|
||||||
function list() {
|
function list() {
|
||||||
return Object.keys(_devices)
|
return array(_devices)
|
||||||
}
|
}
|
||||||
|
|
||||||
// List devices of a specific kind
|
// List devices of a specific kind
|
||||||
function list_by_kind(kind) {
|
function list_by_kind(kind) {
|
||||||
var result = []
|
return filter(array(_devices), function(id) {
|
||||||
for (var id in _devices) {
|
return _devices[id].kind == kind
|
||||||
if (_devices[id].kind == kind) result.push(id)
|
})
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
21
line2d.cm
21
line2d.cm
@@ -371,26 +371,7 @@ var defaults = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function make_line(props) {
|
function make_line(props) {
|
||||||
var data = {}
|
var data = object(defaults, props)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure groups is array
|
// Ensure groups is array
|
||||||
if (!data.groups) data.groups = []
|
if (!data.groups) data.groups = []
|
||||||
|
|||||||
@@ -128,9 +128,7 @@ var factory = function(props) {
|
|||||||
tint: {r: 1, g: 1, b: 1, a: 1}
|
tint: {r: 1, g: 1, b: 1, a: 1}
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = {}
|
var data = object(defaults, props)
|
||||||
for(var k in defaults) data[k] = defaults[k]
|
|
||||||
for(var k in props) data[k] = props[k]
|
|
||||||
|
|
||||||
var newparticles = meme(particles2d_proto, data)
|
var newparticles = meme(particles2d_proto, data)
|
||||||
film2d.register(newparticles)
|
film2d.register(newparticles)
|
||||||
|
|||||||
@@ -1127,9 +1127,9 @@ function _preload_textures(commands) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Load all textures
|
// Load all textures
|
||||||
for (var path in paths) {
|
arrfor(array(paths, function(path) {
|
||||||
sdl_gpu.get_texture(path)
|
sdl_gpu.get_texture(path)
|
||||||
}
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
function _execute_commands(commands, window_size) {
|
function _execute_commands(commands, window_size) {
|
||||||
|
|||||||
23
shape2d.cm
23
shape2d.cm
@@ -71,28 +71,7 @@ var defaults = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function make_shape(shape_type, props) {
|
function make_shape(shape_type, props) {
|
||||||
var data = {}
|
var data = object(defaults, props)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure groups is array
|
// Ensure groups is array
|
||||||
if (!data.groups) data.groups = []
|
if (!data.groups) data.groups = []
|
||||||
|
|||||||
@@ -33,9 +33,7 @@ return function(props) {
|
|||||||
visible: true
|
visible: true
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = {}
|
var data = object(defaults, props)
|
||||||
for (var k in defaults) data[k] = defaults[k]
|
|
||||||
for (var k in props) data[k] = props[k]
|
|
||||||
|
|
||||||
// Ensure groups is array
|
// Ensure groups is array
|
||||||
if (!data.groups) data.groups = []
|
if (!data.groups) data.groups = []
|
||||||
|
|||||||
@@ -27,14 +27,14 @@ for (var i = 0; i < length(formats); i++) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.console("\nFound colorspaces:");
|
log.console("\nFound colorspaces:");
|
||||||
for (var cs in colorspaces) {
|
arrfor(array(colorspaces), function(key) {
|
||||||
log.console(" " + cs + ": " + length(colorspaces[cs]) + " formats");
|
log.console(" " + key + ": " + length(colorspaces[key]) + " formats");
|
||||||
}
|
})
|
||||||
|
|
||||||
// Try opening camera with different colorspaces
|
// Try opening camera with different colorspaces
|
||||||
log.console("\nTrying to open 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
|
// Get first format for this colorspace
|
||||||
var format = colorspaces[cs][0];
|
var format = colorspaces[cs][0];
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ for (var cs in colorspaces) {
|
|||||||
|
|
||||||
// Just test first 3 colorspaces
|
// Just test first 3 colorspaces
|
||||||
if (find(array(colorspaces), cs) >= 2) break;
|
if (find(array(colorspaces), cs) >= 2) break;
|
||||||
}
|
})
|
||||||
|
|
||||||
log.console("\nColorspace test complete!");
|
log.console("\nColorspace test complete!");
|
||||||
$stop();
|
$stop();
|
||||||
@@ -43,9 +43,7 @@ return function(props) {
|
|||||||
outline_color: null
|
outline_color: null
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = {}
|
var data = object(defaults, props)
|
||||||
for(var k in defaults) data[k] = defaults[k]
|
|
||||||
for(var k in props) data[k] = props[k]
|
|
||||||
|
|
||||||
var newtext = meme(text2d_proto, data)
|
var newtext = meme(text2d_proto, data)
|
||||||
film2d.register(newtext)
|
film2d.register(newtext)
|
||||||
|
|||||||
@@ -54,9 +54,7 @@ return function(props) {
|
|||||||
tint: {r: 1, g: 1, b: 1, a: 1}
|
tint: {r: 1, g: 1, b: 1, a: 1}
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = {}
|
var data = object(defaults, props)
|
||||||
for(var k in defaults) data[k] = defaults[k]
|
|
||||||
for(var k in props) data[k] = props[k]
|
|
||||||
|
|
||||||
var newtilemap = meme(tilemap, data)
|
var newtilemap = meme(tilemap, data)
|
||||||
film2d.register(newtilemap)
|
film2d.register(newtilemap)
|
||||||
|
|||||||
12
tween.cm
12
tween.cm
@@ -42,19 +42,19 @@ var TweenProto = {
|
|||||||
engine: null,
|
engine: null,
|
||||||
|
|
||||||
to: function(props, duration, start_time) {
|
to: function(props, duration, start_time) {
|
||||||
for (var key in props) {
|
arrfor(array(props), key => {
|
||||||
var value = props[key]
|
var value = props[key]
|
||||||
if (is_object(value)) {
|
if (is_object(value)) {
|
||||||
for (var subkey in value) {
|
arrfor(array(value), subkey => {
|
||||||
var flatKey = key + '.' + subkey
|
var flatKey = key + '.' + subkey
|
||||||
this.startVals[flatKey] = this.obj[key] ? this.obj[key][subkey] : undefined
|
this.startVals[flatKey] = this.obj[key] ? this.obj[key][subkey] : undefined
|
||||||
this.endVals[flatKey] = value[subkey]
|
this.endVals[flatKey] = value[subkey]
|
||||||
}
|
})
|
||||||
} else {
|
} else {
|
||||||
this.startVals[key] = this.obj[key]
|
this.startVals[key] = this.obj[key]
|
||||||
this.endVals[key] = value
|
this.endVals[key] = value
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
this.duration = duration
|
this.duration = duration
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ var TweenProto = {
|
|||||||
var t = min(max(elapsed / this.duration, 0), 1)
|
var t = min(max(elapsed / this.duration, 0), 1)
|
||||||
var eased = this.easing(t)
|
var eased = this.easing(t)
|
||||||
|
|
||||||
for (var key in this.endVals) {
|
arrfor(array(this.endVals), key => {
|
||||||
var start = this.startVals[key]
|
var start = this.startVals[key]
|
||||||
var end = this.endVals[key]
|
var end = this.endVals[key]
|
||||||
var value = start + (end - start) * eased
|
var value = start + (end - start) * eased
|
||||||
@@ -113,7 +113,7 @@ var TweenProto = {
|
|||||||
} else {
|
} else {
|
||||||
this.obj[key] = value
|
this.obj[key] = value
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
if (t == 1 && this.engine) {
|
if (t == 1 && this.engine) {
|
||||||
this.onCompleteCallback()
|
this.onCompleteCallback()
|
||||||
|
|||||||
Reference in New Issue
Block a user