Skip to content

Commit

Permalink
Merge pull request #73 from CSchank/bugfix
Browse files Browse the repository at this point in the history
Bugfix: left arrow to reset the tape
  • Loading branch information
Necried authored Mar 8, 2019
2 parents 4a3db80 + f2997f5 commit a7e9ec2
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
stages:
- test
- name: deploy
if: "(branch = master) AND (type = push)"
if: "(branch = master) AND (tag IS present)"
2 changes: 1 addition & 1 deletion elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"elm-version": "0.19.0",
"dependencies": {
"direct": {
"MacCASOutreach/graphicsvg": "6.1.0",
"MacCASOutreach/graphicsvg": "5.1.0",
"billstclair/elm-sha256": "1.0.8",
"elm/browser": "1.0.1",
"elm/core": "1.0.2",
Expand Down
15 changes: 7 additions & 8 deletions src/Building.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 (..)
Expand Down Expand Up @@ -33,7 +34,7 @@ type Msg
| SaveStateName StateID String
| SaveTransitionName TransitionID String
| AddState ( Float, Float )
| KeyPressed Int
| KeyPressed String
| ToggleSnap
| ChangeSnap Int
| NoOp
Expand All @@ -42,7 +43,7 @@ type Msg
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.batch
[ Browser.Events.onKeyDown (D.map KeyPressed (D.field "keyCode" D.int))
[ Browser.Events.onKeyDown (D.map KeyPressed (D.field "key" D.string))
]


Expand Down Expand Up @@ -425,7 +426,7 @@ update env msg ( model, pModel, sModel ) =
( ( { model | machineState = Regular }, pModel, sModel ), False, Cmd.none )

KeyPressed k ->
if k == 13 then
if k == "Enter" then
--pressed enter
case model.machineState of
EditingStateLabel sId newLbl ->
Expand Down Expand Up @@ -463,8 +464,7 @@ update env msg ( model, pModel, sModel ) =
_ ->
( ( model, pModel, sModel ), False, Cmd.none )

else if k == 68 then
--pressed delete
else if k == "d" then
case model.machineState of
SelectedState stId ->
let
Expand Down Expand Up @@ -526,14 +526,13 @@ update env msg ( model, pModel, sModel ) =
_ ->
( ( model, pModel, sModel ), False, Cmd.none )

else if k == 71 then
--pressed G
else if k == "g" then
( ( model, pModel, sModel ), False, sendMsg ToggleSnap )

else
case model.machineState of
SelectedState sId ->
if k == 70 then
if k == "f" then
let
newMachine =
{ oldMachine
Expand Down
15 changes: 9 additions & 6 deletions src/Machine.elm
Original file line number Diff line number Diff line change
Expand Up @@ -752,15 +752,18 @@ renderStates currentStates machine model env =

_ ->
group []
, rect 25 18
|> filled blank
]
|> move (getPos sId)
|> (if not env.holdingShift then
notifyMouseDownAt (StartDragging sId)
|> (case model of
EditingStateLabel _ _ ->
identity

else
notifyTap (TapState sId)
_ ->
if not env.holdingShift then
notifyMouseDownAt (StartDragging sId)

else
notifyTap (TapState sId)
)
)
stateList
28 changes: 14 additions & 14 deletions src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ type Msg
= BMsg Building.Msg
| SMsg Simulating.Msg
| EMsg Exporting.Msg
| KeyPressed Int
| KeyReleased Int
| KeyPressed String
| KeyReleased String
| WindowSize ( Int, Int )
| UrlChange Url
| UrlRequest UrlRequest
Expand Down Expand Up @@ -94,8 +94,8 @@ main =
\model ->
Sub.batch
[ Browser.Events.onResize (\w h -> WindowSize ( w, h ))
, Browser.Events.onKeyDown (D.map KeyPressed (D.field "keyCode" D.int))
, Browser.Events.onKeyUp (D.map KeyReleased (D.field "keyCode" D.int))
, Browser.Events.onKeyDown (D.map KeyPressed (D.field "key" D.string))
, Browser.Events.onKeyUp (D.map KeyReleased (D.field "key" D.string))
, Browser.Events.onVisibilityChange VisibilityChanged
, case model.appModel.present.appState of
Building m ->
Expand Down Expand Up @@ -228,30 +228,30 @@ update msg model =
( model, Cmd.none )

KeyReleased k ->
if k == 16 then
if k == "Shift" then
( { model | environment = { oldEnvironment | holdingShift = False } }, Cmd.none )

else if k == 91 then
else if k == "Meta" then
( { model | environment = { oldEnvironment | holdingMeta = False } }, Cmd.none )

else if k == 17 then
else if k == "Control" then
( { model | environment = { oldEnvironment | holdingControl = False } }, Cmd.none )

else
( model, Cmd.none )

KeyPressed k ->
if k == 16 then
if k == "Shift" then
( { model | environment = { oldEnvironment | holdingShift = True } }, Cmd.none )

else if k == 89 {- y -} || k == 90 {- z -} then
else if k == "y" || k == "z" then
let
doUndo =
(oldEnvironment.holdingControl || oldEnvironment.holdingMeta) && k == 90
(oldEnvironment.holdingControl || oldEnvironment.holdingMeta) && k == "z"

doRedo =
(oldEnvironment.holdingControl && k == 89)
|| (oldEnvironment.holdingMeta && oldEnvironment.holdingShift && k == 90)
(oldEnvironment.holdingControl && k == "y")
|| (oldEnvironment.holdingMeta && oldEnvironment.holdingShift && k == "z")
in
( { model
| appModel =
Expand All @@ -267,11 +267,11 @@ update msg model =
, Cmd.none
)

else if k == 91 then
else if k == "Meta" then
--pressed meta key
( { model | environment = { oldEnvironment | holdingMeta = True } }, Cmd.none )

else if k == 17 then
else if k == "Control" then
--pressed control
( { model | environment = { oldEnvironment | holdingControl = True } }, Cmd.none )
{- else if k == 66 then
Expand Down
86 changes: 51 additions & 35 deletions src/Simulating.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Simulating exposing (HoverError, InputTape, Model(..), Msg(..), Persisten

import Array exposing (Array)
import Browser.Events
import Debug
import Dict exposing (Dict)
import Environment exposing (Environment)
import Error exposing (..)
Expand All @@ -17,7 +18,7 @@ import Tuple exposing (first, second)

subscriptions : Model -> Sub Msg
subscriptions model =
Browser.Events.onKeyDown (D.map KeyPressed (D.field "keyCode" D.int))
Browser.Events.onKeyDown (D.map KeyPressed (D.field "key" D.string))


type alias PersistentModel =
Expand Down Expand Up @@ -51,7 +52,7 @@ type Msg
| AddNewTape
| ChangeTape Int
| ToggleStart StateID
| KeyPressed Int
| KeyPressed String
| ChangeMachine MachineType
| MachineMsg Machine.Msg
| HoverErrorEnter Int
Expand Down Expand Up @@ -166,7 +167,17 @@ renderTape model input tapeSt tapeId selectedId inputAt showButtons =
, latex (xpad * 0.9) (xpad * 0.7) "white" st AlignCentre
|> move ( 0, 10.25 )
]
|> move ( toFloat n * xpad, 0 )
|> move
( toFloat n
* xpad
+ (if not showButtons then
xpad / 2

else
0
)
, 0
)
|> notifyTap (ChangeTape tapeId)
)
input
Expand Down Expand Up @@ -325,17 +336,15 @@ update env msg ( model, pModel, sModel ) =
( ( Default tId -1 Nothing {- ??? -}, { pModel | currentStates = epsTrans oldMachine.transitionNames oldMachine.delta oldMachine.start }, sModel ), False, Cmd.none )

KeyPressed k ->
if k == 13 then
--pressed enter
if k == "Enter" then
case model of
Editing tId ->
( ( Default tId -1 Nothing, { pModel | currentStates = epsTrans oldMachine.transitionNames oldMachine.delta oldMachine.start }, sModel ), True, Cmd.none )

_ ->
( ( model, pModel, sModel ), False, Cmd.none )

else if k == 8 then
--pressed delete
else if k == "Backspace" || k == "ArrowLeft" then
case model of
Editing tapeId ->
let
Expand Down Expand Up @@ -366,97 +375,104 @@ update env msg ( model, pModel, sModel ) =
_ ->
( ( model, pModel, sModel ), False, Cmd.none )

else if k == 39 then
--right arrow key
else if k == "ArrowRight" then
case model of
Default _ _ _ ->
( ( model, pModel, sModel ), False, Task.perform identity (Task.succeed <| Step) )

_ ->
( ( model, pModel, sModel ), False, Cmd.none )

else if k == "ArrowLeft" then
case model of
Default tId _ hErr ->
( ( Default tId -1 hErr, { pModel | currentStates = sModel.machine.start }, sModel ), False, Cmd.none )

_ ->
( ( model, pModel, sModel ), False, Cmd.none )

else
case model of
Editing tapeId ->
let
charCode =
case k of
65 ->
"a" ->
0

83 ->
"s" ->
1

68 ->
"d" ->
2

70 ->
"f" ->
3

71 ->
"g" ->
4

72 ->
"h" ->
5

74 ->
"j" ->
6

75 ->
"k" ->
7

76 ->
"l" ->
8

81 ->
"q" ->
9

87 ->
"w" ->
10

69 ->
"e" ->
11

82 ->
"r" ->
12

84 ->
"t" ->
13

89 ->
"y" ->
14

85 ->
"u" ->
15

73 ->
"i" ->
16

79 ->
"o" ->
17

80 ->
"p" ->
18

90 ->
"z" ->
19

88 ->
"x" ->
20

67 ->
"c" ->
21

86 ->
"v" ->
22

66 ->
"b" ->
23

78 ->
"n" ->
24

77 ->
"m" ->
25

_ ->
Expand Down

0 comments on commit a7e9ec2

Please sign in to comment.