summaryrefslogtreecommitdiff
path: root/app/Scratchy/Syntax.hs
diff options
context:
space:
mode:
authorMikkel Thestrup <mithe24@student.sdu.dk>2025-12-25 15:21:35 +0100
committerMikkel Thestrup <mithe24@student.sdu.dk>2025-12-25 15:21:35 +0100
commitb9a23720c7ebe67f84bec0af147fca9b132525ac (patch)
tree92b914e608e63b6c1405e0c749759ab196bcb3b1 /app/Scratchy/Syntax.hs
parenta517d54e9032299e6f550759ac0bb6df3f9aa38c (diff)
downloadscratchy-b9a23720c7ebe67f84bec0af147fca9b132525ac.tar.gz
scratchy-b9a23720c7ebe67f84bec0af147fca9b132525ac.zip
Feat(Scratchy): Implemented Scratchy DSL
Sprite and Grid Actions; - NewSprite - SetColor - SetTarget - GetTarget - SetBackgroundColor - InspectCell Event Listening; - OnKeyEvent - OnTargetReached - OnTargetUpdated - OnBarrierHit Timer Operation; - After
Diffstat (limited to 'app/Scratchy/Syntax.hs')
-rw-r--r--app/Scratchy/Syntax.hs66
1 files changed, 65 insertions, 1 deletions
diff --git a/app/Scratchy/Syntax.hs b/app/Scratchy/Syntax.hs
index c77e51a..128ea01 100644
--- a/app/Scratchy/Syntax.hs
+++ b/app/Scratchy/Syntax.hs
@@ -82,6 +82,70 @@ data SProg a
------------------------------------------------------------
combine :: SProg () -> SProg () -> SProg ()
-combine = undefined -- Fill this in
+-- Base cases
+combine (Pure ()) p2 = p2
+combine p1 (Pure ()) = p1
+combine (OnKeyEvent k1 handler1 cont1) p2 =
+ OnKeyEvent k1 handler1 (combine cont1 p2)
+
+combine p1 (OnKeyEvent k2 handler2 cont2) =
+ OnKeyEvent k2 handler2 (combine p1 cont2)
+
+combine (OnTargetReached sp1 h1 c1) p2 =
+ OnTargetReached sp1 h1 (combine c1 p2)
+
+combine p1 (OnTargetReached sp2 h2 c2) =
+ OnTargetReached sp2 h2 (combine p1 c2)
+
+combine (OnTargetUpdated sp1 h1 c1) p2 =
+ OnTargetUpdated sp1 h1 (combine c1 p2)
+
+combine p1 (OnTargetUpdated sp2 h2 c2) =
+ OnTargetUpdated sp2 h2 (combine p1 c2)
+
+combine (OnBarrierHit sp1 h1 c1) p2 =
+ OnBarrierHit sp1 h1 (combine c1 p2)
+
+combine p1 (OnBarrierHit sp2 h2 c2) =
+ OnBarrierHit sp2 h2 (combine p1 c2)
+
+combine (After dur1 handler1 cont1) p2 =
+ After dur1 handler1 (combine cont1 p2)
+
+combine p1 (After dur2 handler2 cont2) =
+ After dur2 handler2 (combine p1 cont2)
+
+combine (NewSprite cell pic k1) p2 =
+ NewSprite cell pic (\sp -> combine (k1 sp) p2)
+
+combine p1 (NewSprite cell pic k2) =
+ NewSprite cell pic (combine p1 . k2)
+
+combine (SetColor sp c cont1) p2 =
+ SetColor sp c (combine cont1 p2)
+
+combine p1 (SetColor sp c cont2) =
+ SetColor sp c (combine p1 cont2)
+
+combine (SetTarget sp cell cont1) p2 =
+ SetTarget sp cell (combine cont1 p2)
+
+combine p1 (SetTarget sp cell cont2) =
+ SetTarget sp cell (combine p1 cont2)
+
+combine (GetTarget sp k1) p2 =
+ GetTarget sp (\cell -> combine (k1 cell) p2)
+
+combine p1 (GetTarget sp k2) =
+ GetTarget sp (combine p1 . k2)
+
+combine (SetBackgroundColor c cont1) p2 =
+ SetBackgroundColor c (combine cont1 p2)
+
+combine p1 (SetBackgroundColor c cont2) =
+ SetBackgroundColor c (combine p1 cont2)
+
+combine (InspectCell cell k1) p2 =
+ InspectCell cell (\result -> combine (k1 result) p2)