diff --git a/hunks/view.js b/hunks/view.js index d2e52c9e677d2ea587a7f418546bc1647138a2d3..4357872e8d2e6a73c5969321e6b672b332d64c0a 100644 --- a/hunks/view.js +++ b/hunks/view.js @@ -392,30 +392,35 @@ function View() { return def } // end update + let rmAllWires = (pdef) => { + for(let cn of pdef.conn){ + let rci = cn.conn.findIndex((cand) => { + return (cand === pdef) + }) + cn.conn.splice(rci, 1) + } + pdef.conn = [] + } + + // this is one of the most awkward bits of the protocol / stack, + // we assume the thing has more or less completely changed, but + // it may have just added an input / output / state object. + // because of link-reconn-issues, we also assume all existing links are gone, + // and the manager is responsible for reporting back to us all existing wires ... let replaceDef = (spec) => { - throw new Error('you need to rewrite this') - console.warn(`REPLACE DEF at ${spec.ind} in ${this.name} has name ${spec.name}`) let od = defs[spec.ind] // as a rule, when we replace defs, we unhook everything. - // the manager is responsible for following up by sending us - // links that are still alive, - // console.log('the od', od) - // so first rm those links (this won't properly be tested until program loading, i'd bet) - console.warn("old use of defs-as-virtual-hunks, prep 4 err") - // same as above, should update local topology, set update flag for next render? - // this should include a step to completely remove the old definition... - for (let ip in od.inputs) { - od.inputs[ip].disconnectAll() + for (let ip of od.inputs) { + rmAllWires(ip) } - for (let op in od.outputs) { - od.outputs[op].disconnectAll() + for (let op of od.outputs) { + rmAllWires(op) } - // here's the hack / suggestion: - let nd = spec // and replace it in the list, - defs[spec.ind] = nd + defs[spec.ind] = spec + setCompleteRedraw() // occasionally useful, - return nd + return spec } /* --------------------------- ---------------------------- */ @@ -1172,7 +1177,7 @@ function View() { try { let gateway = route[0].entrance // the first link, let gatelist = gateway.states[2].value - gatelist += `, at_${gateway.outputs.length}_(${type})` + gatelist += `, at_${gateway.outputs.length} (${type})` await gateway.context.requestStateChange(gateway.states[2], gatelist) // cover interiors, for (let p = 0; p < route.length - 1; p++) { @@ -1180,17 +1185,17 @@ function View() { let entrance = route[p + 1].entrance let context = route[p].exit.context let exl = exit.states[3].value - exl += `, at_${exit.outputs.length}_(${type})` + exl += `, at_${exit.outputs.length} (${type})` await context.requestStateChange(exit.states[3], exl) let enl = entrance.states[2].value - enl += `, at_${entrance.inputs.length}_(${type})` + enl += `, at_${entrance.inputs.length} (${type})` await context.requestStateChange(entrance.states[3], enl) await context.requestAddLink(exit.outputs[exit.outputs.length - 1], entrance.inputs[entrance.inputs.length - 1]) } // cover exit case let porthole = route[route.length - 1].exit let portlist = porthole.states[3].value - portlist += `, at_${porthole.outputs.length}_(${type})` + portlist += `, at_${porthole.outputs.length} (${type})` await ipdef.context.requestStateChange(porthole.states[3], portlist) await ipdef.context.requestAddLink(porthole.outputs[porthole.outputs.length - 1], ipdef) // to avoid piping data into the void, we can do this last -> diff --git a/view/blocks.js b/view/blocks.js index 5dc046ca958e7212ab4032705c1f088a662a9f0e..98a9e77a6bf7bc44705d6c51a5dd46257c92e256 100644 --- a/view/blocks.js +++ b/view/blocks.js @@ -516,7 +516,6 @@ let repositionDef = (def) => { // clip to bounds, plus some margin... let wr = getBlockStackRightWidth(def.blocks) let wl = getBlockStackLeftWidth(def.blocks) - console.log(wl) let h = getBlockStackHeight(def.blocks) // cover bottom left: if(def.position.x + wr > bw) def.position.x = bw - wr