Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
feat: basic types and stuff for PartialConnections
Browse files Browse the repository at this point in the history
  • Loading branch information
prescientmoon committed Apr 23, 2020
1 parent 9ea094d commit f3f8fbf
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/Component/Editor.purs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ data Action
| SceneMouseUp
| SceneMouseDown (Vec2 Number)
| SceneMouseMove (Vec2 Number)
| SelectInput NodeId Int
| SelectOutput NodeId
| SelectNode NodeId
| LoadNodes

Expand Down Expand Up @@ -90,6 +92,7 @@ component =
, lastMousePosition: Nothing
, expression: nullExpr Nowhere
, project: emptyProject $ NodeId "firstOutput"
, partialConnection: def
}
, render
, eval:
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/Component/Editor/Add.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Editor/Node.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions src/Component/Editor/Scene.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/Data/Editor/PartialConnection.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ 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)

-- This is a data structure used to store data about the current connection the user is working on
newtype PartialConnection
= PartialConnection
{ from :: Maybe NodeId
, to :: Maybe NodeId
, to :: Maybe (Tuple NodeId Int)
}

-- Typeclass instances
Expand All @@ -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")
14 changes: 14 additions & 0 deletions src/Data/Editor/State.purs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ module Lunarbox.Data.Editor.State
, _currentTab
, _functionData
, _atFunctionData
, _partialConnection
, _partialFrom
, _partialTo
) where

import Prelude
Expand All @@ -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)
Expand Down Expand Up @@ -76,6 +80,7 @@ type State
, lastMousePosition :: Maybe (Vec2 Number)
, nodeData :: Map (Tuple FunctionName NodeId) NodeData
, functionData :: Map FunctionName FunctionData
, partialConnection :: PartialConnection
}

-- Lenses
Expand Down Expand Up @@ -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

0 comments on commit f3f8fbf

Please sign in to comment.