Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #94

Merged
merged 28 commits into from
Mar 2, 2020
Merged

Dev #94

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
18d6bc2
Update dependencies and version to elm-0.19.1
Necried Nov 9, 2019
5837c71
Made TransitionMistakes stateless, nothing broken so far.
Necried Nov 9, 2019
a3403ba
Elm format and cleanup Mistakes.elm
Necried Nov 9, 2019
522eb71
Remove todo import
Necried Nov 9, 2019
8f4c013
encoding and decoding, v1
CSchank Nov 22, 2019
8bc94a8
versioning for machine encoding / decoding; save-load module
CSchank Nov 23, 2019
f0f102a
bump Elm release for travis
CSchank Nov 23, 2019
2104f0e
fix travis Elm version
CSchank Nov 23, 2019
44414f1
correct Elm version in travis
CSchank Nov 23, 2019
627a436
debugging travis build
CSchank Nov 23, 2019
fd31ace
debugging travis...
CSchank Nov 23, 2019
98213cb
debugging travis
CSchank Nov 23, 2019
88e3d3b
explicit versions for elm-test and elm-format in travis
CSchank Nov 23, 2019
32c482c
fix elm-test and elm-format versions
CSchank Nov 23, 2019
df5df28
debugging elm-test in travis
CSchank Nov 23, 2019
4238db5
still attempting to debug Elm build in travis
CSchank Nov 23, 2019
385b29b
run elm-format
CSchank Nov 23, 2019
a0eff44
fix tests
CSchank Nov 23, 2019
2f5d8b1
break out codec helpers into Utils.elm
CSchank Nov 24, 2019
61c415e
continuing on saving/loading, decoding / encoding of tapes
CSchank Dec 19, 2019
c6edb24
starting saving on client side
CSchank Dec 19, 2019
493b737
starting implementing autosave
CSchank Dec 21, 2019
a8d0093
enable autosave
CSchank Dec 23, 2019
2d877ea
first draft of saving/loading
CSchank Dec 24, 2019
23b7486
final draft of saving
CSchank Feb 12, 2020
0e331c1
remove debug
CSchank Feb 12, 2020
2ababf4
fix variable name
CSchank Feb 12, 2020
5ede7d9
Merge pull request #90 from CSchank/machine_codec
CSchank Mar 1, 2020
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
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
language: elm

install:
- npm install -g [email protected]
- npm install -g [email protected]
- npm install -g [email protected]
env:
global:
- secure: C9poA+wbk5f2SMct/hZe2GDGRvGofIwoGJyvWQOkSVfV016YrtDMmOrrYXjx5qBmY3mO7dejG/D7yZHUKHqQO6QmAOMyrP1Efj1xqAZwOUH8z0I82mb7xjfd0pSrT/HHxd030orVRxqfOTXawvkRHcQ9/H3oREiHgV+IccFRVpTVf8avYREV7cds7p62VNj/3uK1De/etdnDxWFWEQldkdlE1dNE/KMX6SsJGs0JMMC8ubyG5sVIaBs9XPo6DPs9jphioyCmZbVzqms8F0Wirzn4OYbLIXMkV73OywCQmRBo41i/SOHIfACfKBzTnleQ8RwuCxMr9PxGD0s8+W8r1tsWYsr5nqxj8YtW2U9BI8a2P3yYyfw95jh2xrKYiJGHvVZaE0crB8xK9V7UurvrBZs1W402mKCmw0RCqc5HGyCwT4croJb6cj6IdVLurBbomcR3iUL8JuFPPihJdCVjJddO9hEnqcwr2MzcLNXR2MXIlSGX5WPAB+D7WYsfMfJwTdO2LvvToXPUc4dujnodWKjpk/PDAiOJNSEOdyTXOP/bQn7+9B9kwngfqTXdSM/EngabpdZhjRDSLqtkxzR6/3AMWvg/X0jKPds7Z1xn8cDcshOhFuHrKD6BacbkGuN7WHtemm+JCowSn70Yl/6xIWA1bpa6suFLzbCpvKXlHgk=
Expand Down
13 changes: 8 additions & 5 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,27 @@
"source-directories": [
"src"
],
"elm-version": "0.19.0",
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"MacCASOutreach/graphicsvg": "5.1.0",
"billstclair/elm-sha256": "1.0.8",
"billstclair/elm-sha256": "1.0.9",
"elm/browser": "1.0.1",
"elm/core": "1.0.2",
"elm/html": "1.0.0",
"elm/http": "1.0.0",
"elm/json": "1.1.2",
"elm/random": "1.0.0",
"elm/svg": "1.0.1",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm-community/undo-redo": "3.0.0"
"elm-community/undo-redo": "3.0.0",
"ianmackenzie/elm-units": "2.2.0",
"rundis/elm-bootstrap": "5.2.0"
},
"indirect": {
"avh4/elm-color": "1.0.0",
"elm/regex": "1.0.0",
"elm/svg": "1.0.1",
"elm/virtual-dom": "1.0.2",
"elm-community/list-extra": "8.1.0"
}
Expand All @@ -31,4 +34,4 @@
},
"indirect": {}
}
}
}
21 changes: 21 additions & 0 deletions src/ApplicationModel.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module ApplicationModel exposing (..)

import Building
import Exporting
import SharedModel exposing (SharedModel)
import Simulating


type ApplicationState
= Building Building.Model
| Simulating Simulating.Model
| Exporting Exporting.Model


type alias ApplicationModel =
{ appState : ApplicationState
, simulatingData : Simulating.PersistentModel
, buildingData : Building.PersistentModel
, exportingData : Exporting.PersistentModel
, sharedModel : SharedModel
}
69 changes: 5 additions & 64 deletions src/Building.elm
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module Building exposing (Model, Msg(..), PersistentModel(..), editingButtons, init, initPModel, onEnter, onExit, subscriptions, update, updateArrowPos, updateStatePos, view)

import Browser.Events
import Debug
import Dict exposing (Dict)
import Environment exposing (Environment)
import GraphicSVG exposing (..)
import Helpers exposing (..)
import Json.Decode as D
import Machine exposing (..)
import Mistakes exposing (..)
import Set
import SharedModel exposing (SharedModel)
import Task
Expand Down Expand Up @@ -148,34 +148,6 @@ update env msg ( model, pModel, sModel ) =
isValidTransition =
checkTransitionValid newTrans

oldTransitionMistakes =
oldMachine.transitionMistakes

newTransitionMistakes =
if isValidTransition then
case oldTransitionMistakes of
Just setOfMistakes ->
let
newSetOfMistakes =
Set.remove newTransID setOfMistakes
in
if Set.isEmpty newSetOfMistakes then
Nothing

else
Just newSetOfMistakes

Nothing ->
Nothing

else
case oldTransitionMistakes of
Just setOfMistakes ->
Just <| Set.insert newTransID setOfMistakes

Nothing ->
Just <| Set.singleton newTransID

newDelta : Delta
newDelta =
Dict.update st
Expand Down Expand Up @@ -209,7 +181,6 @@ update env msg ( model, pModel, sModel ) =
| delta = newDelta
, transitionNames = Dict.insert newTransID newTrans oldMachine.transitionNames
, stateTransitions = Dict.insert ( st, newTransID, s1 ) newTransPos oldMachine.stateTransitions
, transitionMistakes = newTransitionMistakes
}
}
)
Expand Down Expand Up @@ -485,15 +456,11 @@ update env msg ( model, pModel, sModel ) =
, stateTransitions = newStateTransitions
, stateNames = Dict.remove stId oldMachine.stateNames
, transitionNames = Dict.diff oldMachine.transitionNames removedTransitions
, transitionMistakes = newTMistakes
}

newStateTransitions =
Dict.filter (\( _, t, _ ) _ -> not <| Dict.member t removedTransitions) oldMachine.stateTransitions

newTMistakes =
List.foldr (\tId mistakes -> tMistakeRemove (first tId) mistakes) oldMachine.transitionMistakes removedTransitionsLst

removedTransitionsLst =
List.map (\( _, t, _ ) -> ( t, () )) <| Dict.keys <| Dict.filter (\( s0, _, s1 ) _ -> s0 == stId || s1 == stId) oldMachine.stateTransitions

Expand All @@ -512,14 +479,10 @@ update env msg ( model, pModel, sModel ) =
| delta = newDelta
, stateTransitions = newStateTransitions
, transitionNames = Dict.remove tId oldMachine.transitionNames
, transitionMistakes = newTMistakes
}

newStateTransitions =
Dict.filter (\( _, tId0, _ ) _ -> tId /= tId0) oldMachine.stateTransitions

newTMistakes =
tMistakeRemove tId oldMachine.transitionMistakes
in
( ( { model | machineState = Regular }, pModel, { sModel | machine = newMachine } ), True, Cmd.none )

Expand Down Expand Up @@ -568,20 +531,9 @@ update env msg ( model, pModel, sModel ) =
isValidTransition =
checkTransitionValid newTransitions

oldTransitionMistakes =
oldMachine.transitionMistakes

newTransitionMistakes =
if isValidTransition then
tMistakeRemove tId oldTransitionMistakes

else
tMistakeAdd tId oldTransitionMistakes

newMachine =
{ oldMachine
| transitionNames = Dict.insert tId newTransitions oldMachine.transitionNames
, transitionMistakes = newTransitionMistakes
}
in
( ( { model | machineState = Regular }, pModel, { sModel | machine = newMachine } ), True, Cmd.none )
Expand Down Expand Up @@ -631,6 +583,9 @@ view env ( model, pModel, sModel ) =

winY =
toFloat <| second env.windowSize

transMistakes =
getTransitionMistakes sModel.machine
in
group
[ rect winX winY
Expand Down Expand Up @@ -665,7 +620,7 @@ view env ( model, pModel, sModel ) =

_ ->
group []
, GraphicSVG.map MachineMsg <| Machine.view env model.machineState sModel.machine Set.empty
, GraphicSVG.map MachineMsg <| Machine.view env model.machineState sModel.machine Set.empty transMistakes
, editingButtons model |> move ( winX / 2 - 30, -winY / 2 + 25 )
]

Expand Down Expand Up @@ -762,17 +717,3 @@ snapIcon =
]
|> move ( 5, -10 )
]


checkTransitionValid : Set.Set String -> Bool
checkTransitionValid set =
case Set.member "\\epsilon" set of
False ->
True

True ->
if Set.size set == 1 then
True

else
False
6 changes: 6 additions & 0 deletions src/Environment.elm
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
module Environment exposing (Environment, init)

import Time


init : Environment
init =
{ windowSize = ( 0, 0 )
, holdingShift = False
, holdingControl = False
, holdingMeta = False
, currentTime = Time.millisToPosix 1576798602274
, timeZone = Time.utc
}


Expand All @@ -15,4 +19,6 @@ type alias Environment =
, holdingShift : Bool
, holdingControl : Bool
, holdingMeta : Bool
, currentTime : Time.Posix
, timeZone : Time.Zone
}
3 changes: 2 additions & 1 deletion src/Error.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Environment exposing (Environment)
import GraphicSVG exposing (..)
import Helpers exposing (..)
import Machine exposing (Machine, StateID, TransitionID)
import Mistakes exposing (..)
import Set exposing (Set)
import SharedModel exposing (..)
import Tuple exposing (first, second)
Expand Down Expand Up @@ -57,7 +58,7 @@ machineCheck sModel =
sModel.machine

tMistakes =
sModel.machine.transitionMistakes
getTransitionMistakes mac

allTransitionLabels =
List.sort <| Set.toList <| Set.remove "\\epsilon" <| List.foldr Set.union Set.empty <| Dict.values mac.transitionNames
Expand Down
6 changes: 5 additions & 1 deletion src/Exporting.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Html as H
import Html.Attributes as A
import Json.Decode as D
import Machine exposing (..)
import Mistakes exposing (..)
import Set exposing (Set)
import Sha256 exposing (sha256)
import SharedModel exposing (..)
Expand Down Expand Up @@ -122,6 +123,9 @@ view env ( model, pModel, sModel ) =
hasErr =
contextHasError errCheck sModel.machineType

transMistakes =
getTransitionMistakes oldMachine

-- TODO: Adjust popup box size to fix custom error messages
errHover =
group
Expand All @@ -137,7 +141,7 @@ view env ( model, pModel, sModel ) =
|> move ( winX / 6 - 100, -105 )
in
group
[ (GraphicSVG.map MachineMsg <| Machine.view env Regular sModel.machine sModel.machine.start) |> move ( -winX / 6, 0 )
[ (GraphicSVG.map MachineMsg <| Machine.view env Regular sModel.machine sModel.machine.start transMistakes) |> move ( -winX / 6, 0 )
, machineSelected sModel.machineType winX winY
, text "Choose format:"
|> size 20
Expand Down
13 changes: 13 additions & 0 deletions src/Helpers.elm
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ type LatexAlign


latex w h backclr txt align =
--image (latexurl txt)
-- |> move
-- ( case align of
-- AlignLeft ->
-- 0
--
-- AlignRight ->
-- -w
--
-- AlignCentre ->
-- -w / 2
-- , 0
-- )
(html w h <|
H.div
[ style "width" "100%"
Expand Down
Loading