diff --git a/src/Component/Editor.purs b/src/Component/Editor.purs index 6316550..388e669 100644 --- a/src/Component/Editor.purs +++ b/src/Component/Editor.purs @@ -58,6 +58,8 @@ data Action | SceneMouseUp | SceneMouseDown (Vec2 Number) | SceneMouseMove (Vec2 Number) + | SelectInput NodeId Int + | SelectOutput NodeId | SelectNode NodeId | LoadNodes @@ -90,6 +92,7 @@ component = , lastMousePosition: Nothing , expression: nullExpr Nowhere , project: emptyProject $ NodeId "firstOutput" + , partialConnection: def } , render , eval: @@ -209,6 +212,10 @@ component = maybeCurrentFunction <- gets $ view _currentFunction for_ maybeCurrentFunction \currentFunction -> do modify_ $ set (_isSelected currentFunction id) true + SelectInput _ _ -> do + pure unit + SelectOutput id -> do + pure unit handleTreeOutput :: TreeC.Output -> Maybe Action handleTreeOutput = case _ of diff --git a/src/Component/Editor/Add.purs b/src/Component/Editor/Add.purs index c8111e2..a0c4bce 100644 --- a/src/Component/Editor/Add.purs +++ b/src/Component/Editor/Add.purs @@ -79,7 +79,10 @@ makeNode { edit, addNode } { isUsable, isEditable } name typeMap functionData = ] [ node (nodeInput typeMap name functionData) - { select: Nothing } + { select: Nothing + , selectOutput: Nothing + , selectInput: const Nothing + } ] , container "node-data" [ container "node-text" diff --git a/src/Component/Editor/Node.purs b/src/Component/Editor/Node.purs index 25f8953..bcb204e 100644 --- a/src/Component/Editor/Node.purs +++ b/src/Component/Editor/Node.purs @@ -40,6 +40,8 @@ type Input h a type Actions a = { select :: Maybe a + , selectInput :: Int -> Maybe a + , selectOutput :: Maybe a } output :: forall r a. Boolean -> Color -> HTML r a diff --git a/src/Component/Editor/Scene.purs b/src/Component/Editor/Scene.purs index d194c6a..b6e07a0 100644 --- a/src/Component/Editor/Scene.purs +++ b/src/Component/Editor/Scene.purs @@ -60,6 +60,8 @@ type Actions a , mouseDown :: Vec2 Number -> Maybe a , selectNode :: NodeId -> Maybe a , mouseUp :: Maybe a + , selectInput :: Tuple NodeId Int -> Maybe a + , selectOutput :: NodeId -> Maybe a } -- Errors which could arise while creating the node svg @@ -91,7 +93,13 @@ getNode :: FunctionName -> NodeId -> Project -> NodeBuild Node getNode name id = note (MissingNode id) <<< join <<< (preview $ _atProjectNode name id) createNodeComponent :: forall h a. Input -> Actions a -> Tuple NodeId NodeData -> NodeBuild (HH.HTML h a) -createNodeComponent { functionName, project, typeMap, expression, functionData, typeColors } { selectNode } (Tuple id nodeData) = do +createNodeComponent { functionName +, project +, typeMap +, expression +, functionData +, typeColors +} { selectNode, selectInput, selectOutput } (Tuple id nodeData) = do let generateLocation = DeepLocation functionName @@ -126,7 +134,10 @@ createNodeComponent { functionName, project, typeMap, expression, functionData, ] , hasOutput: not $ is _OutputNode node } - { select: selectNode id } + { select: selectNode id + , selectInput: selectInput <<< Tuple id + , selectOutput: selectOutput id + } scene :: forall h a. Input -> Actions a -> HH.HTML h a scene state@{ project diff --git a/src/Data/Editor/PartialConnection.purs b/src/Data/Editor/PartialConnection.purs index e598277..45780f9 100644 --- a/src/Data/Editor/PartialConnection.purs +++ b/src/Data/Editor/PartialConnection.purs @@ -11,6 +11,7 @@ import Data.Lens.Record (prop) import Data.Maybe (Maybe) import Data.Newtype (class Newtype) import Data.Symbol (SProxy(..)) +import Data.Tuple (Tuple) import Lunarbox.Data.Editor.Node.NodeId (NodeId) import Lunarbox.Data.Lens (newtypeIso) @@ -18,7 +19,7 @@ import Lunarbox.Data.Lens (newtypeIso) newtype PartialConnection = PartialConnection { from :: Maybe NodeId - , to :: Maybe NodeId + , to :: Maybe (Tuple NodeId Int) } -- Typeclass instances @@ -32,5 +33,5 @@ derive newtype instance defaultPartialConnection :: Default PartialConnection _from :: Lens' PartialConnection (Maybe NodeId) _from = newtypeIso <<< prop (SProxy :: _ "from") -_to :: Lens' PartialConnection (Maybe NodeId) +_to :: Lens' PartialConnection (Maybe (Tuple NodeId Int)) _to = newtypeIso <<< prop (SProxy :: _ "to") diff --git a/src/Data/Editor/State.purs b/src/Data/Editor/State.purs index 99f12fa..964e229 100644 --- a/src/Data/Editor/State.purs +++ b/src/Data/Editor/State.purs @@ -21,6 +21,9 @@ module Lunarbox.Data.Editor.State , _currentTab , _functionData , _atFunctionData + , _partialConnection + , _partialFrom + , _partialTo ) where import Prelude @@ -41,6 +44,7 @@ import Lunarbox.Data.Editor.Node (Node) import Lunarbox.Data.Editor.Node.NodeData (NodeData, _NodeDataSelected) import Lunarbox.Data.Editor.Node.NodeId (NodeId) import Lunarbox.Data.Editor.NodeGroup (NodeGroup) +import Lunarbox.Data.Editor.PartialConnection (PartialConnection, _from, _to) import Lunarbox.Data.Editor.Project (Project, _ProjectFunctions, _atProjectFunction, _atProjectNode, _projectNodeGroup) import Lunarbox.Data.Graph as G import Lunarbox.Data.Vector (Vec2) @@ -76,6 +80,7 @@ type State , lastMousePosition :: Maybe (Vec2 Number) , nodeData :: Map (Tuple FunctionName NodeId) NodeData , functionData :: Map FunctionName FunctionData + , partialConnection :: PartialConnection } -- Lenses @@ -135,3 +140,12 @@ _panelIsOpen = prop (SProxy :: _ "panelIsOpen") _currentTab :: Lens' State Tab _currentTab = prop (SProxy :: _ "currentTab") + +_partialConnection :: Lens' State PartialConnection +_partialConnection = prop (SProxy :: _ "partialConnection") + +_partialFrom :: Lens' State ((Maybe NodeId)) +_partialFrom = _partialConnection <<< _from + +_partialTo :: Lens' State (Maybe (Tuple NodeId Int)) +_partialTo = _partialConnection <<< _to