Skip to content

Commit 9b58546

Browse files
committed
Use default output value if exist
1 parent 1fc2e44 commit 9b58546

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

src/constructor/Cable.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class Cable{
2323
this.visualizeFlow();
2424

2525
if(this._disconnecting) return this.input.default;
26-
return this.output.value;
26+
27+
let temp = this.output;
28+
return temp.value ?? temp.default;
2729
}
2830

2931
activation(enable){
@@ -124,12 +126,12 @@ class Cable{
124126
inp.emit('connect', temp);
125127
out.emit('connect', {port: out, target: inp, cable: this});
126128

127-
if(out.value !== void 0){
129+
if(out.value != null || out.default != null){
128130
inp.emit('value', temp);
129131
inp.iface.emit('port.value', temp);
130132

131133
let node = inp.iface.node;
132-
if(node.update !== void 0) {
134+
if(node.update != null) {
133135
if(node.instance._importing)
134136
node.instance.executionOrder.add(node, this);
135137
else if(node.routes.in.length === 0) {

src/constructor/Port.js

+9-15
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@ Blackprint.Engine.Port = class Port extends Blackprint.Engine.CustomEvent{
150150
// This port must use values from connected output
151151
if(port.source === 'input'){
152152
if(port._cache !== void 0) return port._cache;
153-
154-
if(port.cables.length === 0)
155-
return port.default;
153+
if(port.cables.length === 0) return port.default;
156154

157155
let portIface = port.iface;
158156

@@ -190,22 +188,17 @@ Blackprint.Engine.Port = class Port extends Blackprint.Engine.CustomEvent{
190188
cable.visualizeFlow();
191189

192190
portIface._requesting = false;
193-
if(port.feature === BP_Port.ArrayOf){
194-
port._cache = [];
195-
if(output.value != null)
196-
port._cache.push(output.value);
197-
198-
return port._cache;
199-
}
191+
if(port.feature === BP_Port.ArrayOf)
192+
return port._cache = [output.value ?? output.default];
200193

201-
return port._cache = output.value ?? port.default;
194+
return port._cache = output.value ?? port.default ?? output.default;
202195
}
203196

204197
let isNotArrayPort = port.feature !== BP_Port.ArrayOf;
205198

206199
// Return multiple data as an array
207200
var cables = port.cables;
208-
var data = [];
201+
var data = new Array(cables.length);
209202
for (var i = 0; i < cables.length; i++) {
210203
var cable = cables[i];
211204
if(cable.connected === false || cable.disabled)
@@ -229,12 +222,13 @@ Blackprint.Engine.Port = class Port extends Blackprint.Engine.CustomEvent{
229222
if(Blackprint.settings.visualizeFlow)
230223
cable.visualizeFlow();
231224

225+
let gotData = output.value ?? port.default ?? output.default;
232226
if(isNotArrayPort){
233227
portIface._requesting = false;
234-
return port._cache = output.value ?? port.default;
228+
return port._cache = gotData;
235229
}
236230

237-
data.push(output.value);
231+
data[i] = gotData;
238232
}
239233

240234
portIface._requesting = false;
@@ -246,7 +240,7 @@ Blackprint.Engine.Port = class Port extends Blackprint.Engine.CustomEvent{
246240
return port.__call ??= () => port._callAll();
247241

248242
// else type: output port, let's just return the value
249-
return port.value;
243+
return port.value ?? port.default;
250244
}
251245
};
252246

src/nodes/Fn.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,8 @@ function BPFnInit(){
755755
this.emit(`_add.${name}`, {port: inputPort});
756756

757757
inputPort.on('value', ({ cable }) => {
758-
outputPort.iface.node.output[outputPort.name] = cable.output.value;
758+
let temp = cable.output;
759+
outputPort.iface.node.output[outputPort.name] = temp.value ?? temp.default;
759760
});
760761

761762
return inputPort;

src/nodes/FnPortVar.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function BPFnVarInit(){
162162
this._listener = ({ port }) => {
163163
if(port.iface.node.routes.out != null){
164164
let { Val } = this.ref.IOutput;
165-
Val.value = port.value; // Change value without trigger node.update
165+
Val.value = port.value ?? port.default; // Change value without trigger node.update
166166

167167
let list = Val.cables;
168168
for (let i=0; i < list.length; i++) {
@@ -175,7 +175,7 @@ function BPFnVarInit(){
175175
return;
176176
}
177177

178-
this.ref.Output.Val = port.value;
178+
this.ref.Output.Val = port.value ?? port.default;
179179
};
180180

181181
port.on('value', this._listener);

0 commit comments

Comments
 (0)