Skip to content

Commit

Permalink
new levels, added board port diagrams
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchStevens committed Jan 16, 2024
1 parent a4c6514 commit 4a3ee11
Show file tree
Hide file tree
Showing 26 changed files with 475 additions and 194 deletions.
1 change: 0 additions & 1 deletion dist/less/board-component.less
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
}

& #screen-background {
fill: #8AF85B;
}

& #screen-border {
Expand Down
10 changes: 10 additions & 0 deletions dist/less/default.less
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,14 @@ span.green { color: @green }
& #title {
font-size: 20px;
}
}

.clearfix {
overflow: auto;
}

.clearfix::after {
content: "";
clear: both;
display: table;
}
11 changes: 0 additions & 11 deletions dist/less/fonts.less
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
@font-face {
font-family: monogram;
src: url(./fonts/monogram.ttf);
}

@font-face {
font-family: retro-computer;
src: url(./fonts/retro_computer_personal_use.ttf);
}


@font-face {
font-family: boxxy;
src: url(./fonts/boxxy.bdf);
}
50 changes: 49 additions & 1 deletion dist/less/sidebar-component.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#sidebar-component {
& > * {
display: inline-flex;
justify-content: space-between;
width: 100%;
}

& .port { color:red; }
& .direction { color:darkgoldenrod; }

Expand All @@ -10,7 +16,49 @@

& > div {
border: lightgray 2px solid;
//padding: lightgray 2px solid;
}
}

& .completion-status {
height: 100px;
}
}


.board-port-diagram {
@red: #f85b5b;
@green: #8af85b;
@grey: #8c7777;

width: 100px;
stroke: black;
fill: black;
flex: none;




& g[data-port-mismatch='port-expected'] {
stroke: @grey;
fill: @grey;
marker { fill: @grey; }
}

& g[data-port-mismatch='no-port-expected'], g[data-port-mismatch='incorrect-port-type'] {
stroke: @red;
fill: @red;
marker { fill: @red; }
}

& g[data-port-mismatch='incorrect-capacity'] {
& text {
stroke: @red;
}
}

& g[data-port-mismatch='no-mismatch'] {
stroke: @green;
fill: @green;
marker { fill: @green; }
}
}
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"compile-css-watch": "nodemon --watch dist/less/* --exec 'npm run compile-css'",
"build": "spago bundle-app --main Main --to dist/abed.js",
"build-watch": "npm run compile-css-watch & npm run build -- --watch",
"build-prod": "spago -x prod.dhall build && purs-backend-es bundle-app --no-build --minify --to dist/abed.js && npm run compile-css",
"build-prod": "spago -x prod.dhall build && purs-backend-es bundle-app --no-build --minify --to dist/abed.js && npm run compile-css",
"test": "spago -x test.dhall test --purs-args '-g sourcemaps'",
"test-watch": "npm run test -- --watch"
},
Expand All @@ -16,9 +16,10 @@
"less": "^4.2.0",
"nodemon": "^3.0.1",
"purescript": "^0.15.14",
"spago": "^0.21.0",
"purs-backend-es": "^1.4.2"
"purs-backend-es": "^1.4.2",
"spago": "^0.21.0"
},
"dependencies": {
"driver.js": "^1.3.1"
}
}
2 changes: 1 addition & 1 deletion packages.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ let upstream =
sha256:f91d36c7e4793fe4d7e042c57fef362ff3f9e9ba88454cd38686701e30bf545a
in upstream
with halogen-svg-elems.repo = "https://github.com/MitchStevens/purescript-halogen-svg-elems.git"
with halogen-svg-elems.version = "a3ad0435165c483f04e8bbbeb604f98d938947e3"
with halogen-svg-elems.version = "df7b35f"
14 changes: 7 additions & 7 deletions src/Component/Board.purs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import Debug (trace)
import Effect.Aff.Class (class MonadAff)
import Effect.Class (class MonadEffect, liftEffect)
import Effect.Class.Console (log, logShow)
import Game.Board (Board(..), _pieces, _size, addBoardPath, addPiece, buildEvaluableBoard, capacityRipple, decreaseSize, evalBoardM, evalWithPortInfo, getBoardPort, getPieceInfo, increaseSize, pieceDropped, removePiece, rotatePieceBy, runEvaluableM, toLocalInputs)
import Game.Board (Board(..), _pieces, _size, addBoardPath, addPiece, buildEvaluableBoard, capacityRipple, decreaseSize, evalBoardM, evalWithPortInfo, getBoardPortEdge, getPieceInfo, increaseSize, pieceDropped, removePiece, rotatePieceBy, runEvaluableM, toLocalInputs)
import Game.Capacity (maxValue)
import Game.Direction (CardinalDirection, allDirections)
import Game.Direction as Direction
Expand Down Expand Up @@ -218,7 +218,7 @@ component = mkComponent { eval , initialState , render }
--updateStore (BoardEvent (RemovedPiece loc (name piece)))
pure Nothing
GetMouseOverLocation f -> do
maybeDst <- gets (_.mouseOverLocation)
maybeDst <- gets (_.isMouseOverLocation)
pure (f <$> maybeDst)
SetGoalPorts boardPorts -> do
lift $ debug (tag "boardPorts" (show boardPorts)) "Set goal ports on board"
Expand Down Expand Up @@ -258,7 +258,7 @@ component = mkComponent { eval , initialState , render }
PieceOutput (Piece.Dropped src) -> do
lift $ debug M.empty ("Piece dropped at " <> show src)
-- when a piece is dropped, it can be dropped over a new location or outside the game board
maybeDst <- gets (_.mouseOverLocation)
maybeDst <- gets (_.isMouseOverLocation)
eitherPiece <- liftBoardM (pieceDropped src maybeDst)
case eitherPiece of
Left boardError -> do
Expand Down Expand Up @@ -343,14 +343,14 @@ component = mkComponent { eval , initialState , render }
-- can these events be simplified? do we need all of them?
LocationOnDragEnter loc dragEvent -> do
liftEffect $ preventDefault (toEvent dragEvent)
modify_ (_ { mouseOverLocation = Just loc } )
modify_ (_ { isMouseOverLocation = Just loc } )
LocationOnDragOver loc dragEvent -> do
liftEffect $ preventDefault (toEvent dragEvent)
LocationOnDrop loc dragEvent -> do
modify_ (_ { mouseOverLocation = Just loc } )
modify_ (_ { isMouseOverLocation = Just loc } )
liftEffect $ preventDefault (toEvent dragEvent)
LocationOnDragLeave _ -> do
modify_ (_ { mouseOverLocation = Nothing } )
modify_ (_ { isMouseOverLocation = Nothing } )
GlobalOnKeyDown ke -> do
case key ke of
"z" -> when (ctrlKey ke) (handleAction Undo)
Expand All @@ -363,7 +363,7 @@ component = mkComponent { eval , initialState , render }

BoardPortOnMouseEnter dir -> do
modify_ (_ { isMouseOverBoardPort = Just dir })
relativeEdge <- evalState (getBoardPort dir) <$> use _board
relativeEdge <- evalState (getBoardPortEdge dir) <$> use _board
signals <- gets (_.lastEvalWithPortInfo)
let focus = { info: _, relativeEdge } <$> M.lookup relativeEdge signals
tell slot.multimeter unit (\_ -> Multimeter.NewFocus focus)
Expand Down
14 changes: 7 additions & 7 deletions src/Component/Board/Types.purs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Data.TraversableWithIndex (forWithIndex)
import Data.Tuple (Tuple(..))
import Data.Zipper (Zipper)
import Data.Zipper as Z
import Game.Board (Board(..), BoardError, BoardM, RelativeEdge, getBoardPort, runBoardM, standardBoard)
import Game.Board (Board(..), BoardError, BoardM, RelativeEdge, getBoardPortEdge, runBoardM, standardBoard)
import Game.Direction (CardinalDirection)
import Game.Location (Location(..))
import Game.Piece (Piece(..))
Expand All @@ -46,11 +46,10 @@ import Web.HTML.Event.DragEvent (DragEvent)
import Web.UIEvent.KeyboardEvent (KeyboardEvent)
import Web.UIEvent.MouseEvent (MouseEvent)

type Input = Maybe Board
type Input = { board ::Board }

type State =
{ boardHistory :: Zipper Board -- todo: limit the number of boards in this data structure
, mouseOverLocation :: Maybe Location
, inputs :: Map CardinalDirection Signal
, outputs :: Map CardinalDirection Signal
, lastEvalWithPortInfo :: Map RelativeEdge PortInfo
Expand All @@ -60,6 +59,7 @@ type State =
, locations :: Array Location
}
, isMouseOverBoardPort :: Maybe CardinalDirection
, isMouseOverLocation :: Maybe Location
}

data Query a
Expand Down Expand Up @@ -105,14 +105,14 @@ type Slots =
)

initialState :: Input -> State
initialState maybeBoard =
{ boardHistory: Z.singleton (fromMaybe standardBoard maybeBoard)
, mouseOverLocation: Nothing
initialState { board } =
{ boardHistory: Z.singleton board
, boardPorts: M.empty
, inputs: M.empty
, outputs: M.empty
, lastEvalWithPortInfo: M.empty
, isCreatingWire: Nothing
, isMouseOverLocation: Nothing
, isMouseOverBoardPort: Nothing
}

Expand All @@ -138,7 +138,7 @@ boardPortInfo = do
boardPorts <- gets (_.boardPorts)
board <- use _board
forWithIndex boardPorts \dir port -> do
let relEdge = evalState (getBoardPort dir) board
let relEdge = evalState (getBoardPortEdge dir) board
gets (_.lastEvalWithPortInfo >>> M.lookup relEdge >>> fromMaybe { connected: false, port, signal: Signal 0})

liftBoardM :: forall m a. MonadState State m => BoardM a -> m (Either BoardError (Tuple a Board))
Expand Down
18 changes: 18 additions & 0 deletions src/Component/Lesson/Tutorial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { driver } from "driver.js";

export const addPieceLesson = () => {
const idPiece = document.querySelector("div[data-avilable-piece='id-piece']")
const pieceLocation = document.querySelector("div[data-location='(0,1)']")

const driver = driver({
steps:
[ { element: idPiece, popover: { title: "Mouse down on the piece" }}
, { element: pieceLocation, popover: { title: "Drag the piece to the board" }}
]
})

idPiece.addEventListener("mousedown", () => driver.moveNext(), { once: true})
pieceLocation.addEventListener("onDrop", () => driver.moveNext(), { once: true})

return driver.drive()
}
25 changes: 25 additions & 0 deletions src/Component/Lesson/Tutorial.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Component.Lesson.Tutorial where

import Prelude

import Effect (Effect)

{-
lessons:
addPiece
removePiece
movePiece
create path
using multimeter
changing capacity
toggleing input ports
increasing/decreasing input ports
runnning tests
undo/redo
-}


foreign import addPieceLesson :: Effect Unit
Loading

0 comments on commit 4a3ee11

Please sign in to comment.