Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions lua/wire/client/node_editor/nodeeditor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,21 @@ function Editor:DrawCircle(x, y, radius, segments)
surface.DrawPoly(circle)
end

function getInputAmountForNode(node)
local gate = getGate(node)
local amountOfInputs = 0
if gate.compact_inputs then
inputLimit = gate.compact_inputs
for inputIdx, _ in pairs(node.connections) do
inputLimit = math.max(inputLimit, inputIdx + 1)
end
amountOfInputs = math.min(#gate.inputs, inputLimit)
else
amountOfInputs = #gate.inputs
end
return amountOfInputs
end

--------------------------------------------------------
--UNDO/REDO SYSTEM
--------------------------------------------------------
Expand Down Expand Up @@ -842,7 +857,7 @@ function Editor:GetNodeAt(x, y)
--gates
local amountOfInputs = 0
if gate.inputs then
amountOfInputs = #gate.inputs
amountOfInputs = getInputAmountForNode(node)
end
local amountOfOutputs = 1
if gate.outputs then
Expand Down Expand Up @@ -898,12 +913,14 @@ function Editor:GetNodeInputAt(x, y)

if not gate then continue end

local amountOfInputs = getInputAmountForNode(node)

if gx < node.x - self.GateSize / 2 - self.IOSize then continue end
if gx > node.x + self.GateSize / 2 + self.IOSize then continue end
if gy < node.y - self.GateSize / 2 then continue end
if gy > node.y - self.GateSize / 2 + self.GateSize * #gate.inputs then continue end
if gy > node.y - self.GateSize / 2 + self.GateSize * amountOfInputs then continue end

for inputNum, _ in pairs(gate.inputs) do
for inputNum = 1, amountOfInputs do
local ix, iy = self:NodeInputPos(node, inputNum)

if gx < ix - self.IOSize / 2 then continue end
Expand Down Expand Up @@ -1187,7 +1204,7 @@ end
function Editor:PaintGate(nodeId, node, gate)
local amountOfInputs = 0
if gate.inputs then
amountOfInputs = #gate.inputs
amountOfInputs = getInputAmountForNode(node)
end
local amountOfOutputs = 1
if gate.outputs then
Expand All @@ -1210,6 +1227,7 @@ function Editor:PaintGate(nodeId, node, gate)

if gate.inputs then
for inputNum, inputName in pairs(gate.inputs) do
if inputNum > amountOfInputs then break end
local nx = x - size / 2 - ioSize
local ny = y - ioSize / 2 + (inputNum-1) * size

Expand Down Expand Up @@ -1758,9 +1776,11 @@ function Editor:Paint()
if self.DrawingConnectionAll then
drawingConnectionFrom = {}
local ports
local amountOfInputs = getInputAmountForNode(node)
if self.DrawingFromInput then ports = gate.inputs
elseif self.DrawingFromOutput then ports = gate.outputs or { "Out" } end
for portNum, portName in pairs(ports) do
if self.DrawingFromInput and portNum > amountOfInputs then break end
drawingConnectionFrom[portNum] = portNum
end
end
Expand Down Expand Up @@ -2473,9 +2493,11 @@ function Editor:OnDrawConnectionFinished(x, y)
if self.DrawingConnectionAll then
drawingConnectionFrom = {}
local ports
local amountOfInputs = getInputAmountForNode(fromNode)
if self.DrawingFromInput then ports = fromGate.inputs
elseif self.DrawingFromOutput then ports = fromGate.outputs or { "Out" } end
for portNum, _ in pairs(ports) do
if self.DrawingFromInput and portNum > amountOfInputs then break end
drawingConnectionFrom[portNum] = portNum
end
end
Expand Down
24 changes: 9 additions & 15 deletions lua/wire/gates/string.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,16 @@ GateActions["string_concat"] = {
name = "Concatenate",
description = "Combines multiple strings together into one string.",
inputs = { "A" , "B" , "C" , "D" , "E" , "F" , "G" , "H" },
compact_inputs = 2,
inputtypes = { "STRING" , "STRING" , "STRING" , "STRING" , "STRING" , "STRING" , "STRING" , "STRING" },
outputtypes = { "STRING" },
output = function(gate, A, B, C, D, E, F, G, H)
if (A and #A or 0)
+ (B and #B or 0)
+ (C and #C or 0)
+ (D and #D or 0)
+ (E and #E or 0)
+ (F and #F or 0)
+ (G and #G or 0)
+ (H and #H or 0) > MAX_LEN
then
return false
output = function(gate, ...)
local len = 0
for _, v in ipairs({...}) do
if (v) then len = len + #v end
end
local T = {A,B,C,D,E,F,G,H}
return table.concat(T)
if len > MAX_LEN then return false end
return table.concat({...})
end,
label = function(Out)
return string.format ("concat = %q", Out)
Expand Down Expand Up @@ -349,10 +343,10 @@ GateActions["string_to_memory"] = {
if (Address == 0) then --Clk
if (gate.stringChanged) then return 1 else return 0 end
elseif (Address == 1) then --String length
return #(gate.currentString)
return #gate.currentString
else --Return string bytes
local index = Address - 1
if (index > #(gate.currentString)) then -- Check whether requested address is outside the string
if (index > #gate.currentString) then -- Check whether requested address is outside the string
return 0
else
return string.byte(gate.currentString, index)
Expand Down
Loading