basic rules language for logic

master
Lindsey Handley 2017-12-27 15:27:30 -08:00
parent 6ec26648b9
commit 32aeda461a
4 changed files with 511 additions and 237 deletions

View File

@ -15,6 +15,8 @@
(provide asset-name)
(provide asset-short-name)
(provide add-behaviour)
(provide asset-struct)
(provide asset-struct?)
(provide asset-struct-name)
@ -41,6 +43,8 @@
(provide mod-struct?)
(provide mod-struct-name)
(provide add-to-more)
(provide set-my-mod!)
(provide my-mod)
@ -50,10 +54,8 @@
(provide add-lua-def)
(provide add-entity)
(provide list_)
(provide add-behaviour-to)
(provide add-behaviour)
(provide list_)
(provide variableify)
@ -119,23 +121,11 @@
(asset-struct-description a)))
(define-syntax (add-behaviour-to stx)
(syntax-case stx ()
[(_ target (key val))
(with-syntax* ([target-id (format-id stx "~a" #'target)]
[key-str (symbol->string
(format-symbol "~a" #'key))])
#`(begin
(add-behaviour target-id
(list key-str val)
my-mod)
"Added behaviour"))]))
(define (add-behaviour target kv m)
(let ([updated-target (add-to-more target kv)])
(set! my-mod
(replace-in-mod m target updated-target))))
(define (replace-in-mod m t1 t2)
(mod-struct

View File

@ -59,7 +59,7 @@
1 0 10 #"text-box%\0"
1 0 32 #"(lib \"text-snipclass.ss\" \"xml\")\0"
1 0 1 6 #"wxloc\0"
0 0 78 0 1 #"\0"
0 0 121 0 1 #"\0"
0 75 1 #"\0"
0 12 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 9
#"Standard\0"
@ -290,7 +290,137 @@
0 -1 -1 4 1 #"\0"
0 -1 1 #"\0"
1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 1 0.0 0.0 0.0 0.0 0.0 0.0 0 0 0 255
255 0 -1 -1 0 833 0 28 3 12 #"#lang racket"
255 0 -1 -1 4 32 #"widget.rkt::browser-text% basic\0"
0 70 1 #"\0"
1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0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-1 -1 -1 -1 1 0 0 0 0 1 0.0 0.0 0.0 0.0 0.0 0.0 0 0 0 255
255 0 -1 -1 4 1 #"\0"
0 -1 1 #"\0"
1.0 0 90 -1 -1 -1 -1 -1 0 0 0 0 0 1 0.0 0.0 0.0 0.0 0.0 0.0 0 0 0 255
228 225 -1 -1 0 873 0 28 3 12 #"#lang racket"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 17 3 14 #";Housecleaning"
@ -308,56 +438,6 @@
0 0 17 3 32 #"; Slideshow presentation..."
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 17 3 88
(
#";TODO: A cool language would let you define a state machine out of t"
#"he assets after they"
) 0 0 24 29 1 #"\n"
0 0 17 3 59
#"; have been defined. (Under the hood: add behaviours)"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 17 3 50 #"; use: Magic Wand --> place: Magic Block"
0 0 24 29 1 #"\n"
0 0 17 3 45 #"; punch: Magic Block --> spawn: Dragon"
0 0 24 29 1 #"\n"
0 0 17 3 50 #"; kill: Dragon --> drop: Dragon Meat"
0 0 24 29 1 #"\n"
0 0 17 3 48 #"; eat: Dragon Meat --> get: 10 health"
0 0 24 29 1 #"\n"
0 0 17 3 52 #"; use: Dragon Meat --> spawn: Zombie Dragon"
0 0 24 29 1 #"\n"
0 0 17 3 74
(
#"; kill: Zombie Dragon --> place: Zombie Dragon Bone Castle Sch"
#"ematic"
) 0 0 24 29 1 #"\n"
0 0 17 3 1 #";"
0 0 24 29 1 #"\n"
0 0 17 3 66
#"; Could probably auto generate games this way with Rosette..."
0 0 24 29 1 #"\n"
0 0 17 3 70
(
#"; Could auto-detect \"dead assets\". Asset that is never place"
#"d..."
) 0 0 24 29 1 #"\n"
0 0 17 3 45 #"; Separates Asset logic from game logic."
0 0 24 29 1 #"\n"
0 0 24 3 1 #" "
0 0 24 29 1 #"\n"
0 0 17 3 71
(
#";TODO: More hooks for causing things in-game (just on_punch works no"
#"w)."
) 0 0 24 29 1 #"\n"
0 0 17 3 77
(
#"; Can get away with not doing this for first release, it should"
#" just get"
) 0 0 24 29 1 #"\n"
0 0 17 3 25 #"; put on a TODO list"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 3 1 #"("
@ -418,8 +498,13 @@
0 0 24 3 1 #"("
0 0 15 3 7 #"require"
0 0 24 3 1 #" "
0 0 19 3 13 #"\"compiler.rkt"
0 0 19 3 1 #"\""
0 0 19 3 11 #"\"rules.rkt\""
0 0 24 3 1 #")"
0 0 24 29 1 #"\n"
0 0 24 3 1 #"("
0 0 15 3 7 #"require"
0 0 24 3 1 #" "
0 0 19 3 14 #"\"compiler.rkt\""
0 0 24 3 1 #")"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
@ -454,8 +539,7 @@
0 0 24 3 1 #" "
0 0 21 3 2 #"20"
0 0 24 3 1 #" "
0 0 19 3 1 #"\""
0 0 19 3 6 #"solid\""
0 0 19 3 7 #"\"solid\""
0 0 24 3 1 #" "
0 0 14 3 9 #"dot-color"
0 0 24 3 1 #")"
@ -607,8 +691,7 @@
0 0 15 3 11 #"define-item"
0 0 24 3 1 #" "
0 0 14 3 6 #"zelda-"
0 0 14 3 6 #"thing-"
0 0 14 3 1 #"1"
0 0 14 3 7 #"thing-1"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 19 3 18 #"\"Zelda Thingy Red\""
@ -630,8 +713,7 @@
0 0 15 3 11 #"define-item"
0 0 24 3 1 #" "
0 0 14 3 6 #"zelda-"
0 0 14 3 6 #"thing-"
0 0 14 3 1 #"2"
0 0 14 3 7 #"thing-2"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 19 3 19 #"\"Zelda Thingy Blue\""
@ -654,8 +736,7 @@
0 0 24 3 1 #" "
0 0 14 3 5 #"zelda"
0 0 14 3 1 #"-"
0 0 14 3 6 #"thing-"
0 0 14 3 1 #"3"
0 0 14 3 7 #"thing-3"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 19 3 20 #"\"Zelda Thingy Green\""
@ -676,8 +757,7 @@
0 0 24 3 1 #"("
0 0 15 3 11 #"define-item"
0 0 24 3 1 #" "
0 0 14 3 8 #"diamond-"
0 0 14 3 5 #"green"
0 0 14 3 13 #"diamond-green"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 19 3 15 #"\"Green Diamond\""
@ -692,8 +772,7 @@
0 0 24 3 1 #"("
0 0 15 3 11 #"define-item"
0 0 24 3 1 #" "
0 0 14 3 8 #"diamond-"
0 0 14 3 3 #"red"
0 0 14 3 11 #"diamond-red"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 19 3 13 #"\"Red Diamond\""
@ -709,8 +788,7 @@
0 0 24 3 1 #"("
0 0 15 3 11 #"define-item"
0 0 24 3 1 #" "
0 0 14 3 8 #"diamond-"
0 0 14 3 4 #"blue"
0 0 14 3 12 #"diamond-blue"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 19 3 14 #"\"Blue Diamond\""
@ -727,8 +805,7 @@
0 0 24 3 1 #"("
0 0 15 3 12 #"define-block"
0 0 24 3 1 #" "
0 0 14 3 4 #"red-"
0 0 14 3 5 #"block"
0 0 14 3 9 #"red-block"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 19 3 11 #"\"Red Block\""
@ -743,8 +820,7 @@
0 0 24 3 1 #"("
0 0 15 3 12 #"define-block"
0 0 24 3 1 #" "
0 0 14 3 6 #"green-"
0 0 14 3 5 #"block"
0 0 14 3 11 #"green-block"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 19 3 13 #"\"Green Block\""
@ -759,8 +835,7 @@
0 0 24 3 1 #"("
0 0 15 3 12 #"define-block"
0 0 24 3 1 #" "
0 0 14 3 5 #"blue-"
0 0 14 3 5 #"block"
0 0 14 3 10 #"blue-block"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 19 3 12 #"\"Blue Block\""
@ -775,8 +850,7 @@
0 0 24 3 1 #"("
0 0 15 3 12 #"define-block"
0 0 24 3 1 #" "
0 0 14 3 8 #"magenta-"
0 0 14 3 5 #"block"
0 0 14 3 13 #"magenta-block"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 19 3 15 #"\"Magenta Block\""
@ -791,8 +865,7 @@
0 0 24 3 1 #"("
0 0 15 3 12 #"define-block"
0 0 24 3 1 #" "
0 0 14 3 5 #"cyan-"
0 0 14 3 5 #"block"
0 0 14 3 10 #"cyan-block"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 19 3 12 #"\"Cyan Block\""
@ -807,8 +880,7 @@
0 0 24 3 1 #"("
0 0 15 3 12 #"define-block"
0 0 24 3 1 #" "
0 0 14 3 7 #"purple-"
0 0 14 3 5 #"block"
0 0 14 3 12 #"purple-block"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 19 3 14 #"\"Purple Block\""
@ -825,8 +897,7 @@
0 0 24 3 1 #"("
0 0 15 3 12 #"define-block"
0 0 24 3 1 #" "
0 0 14 3 7 #"yellow-"
0 0 14 3 5 #"block"
0 0 14 3 12 #"yellow-block"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 19 3 14 #"\"Yellow Block\""
@ -843,41 +914,35 @@
0 0 24 3 1 #"("
0 0 15 3 13 #"define-recipe"
0 0 24 3 1 #" "
0 0 14 3 3 #"my-"
0 0 14 3 7 #"recipe1"
0 0 14 3 10 #"my-recipe1"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 14 3 5 #"make:"
0 0 24 3 1 #" "
0 0 21 3 1 #"1"
0 0 24 3 1 #" "
0 0 14 3 6 #"green-"
0 0 14 3 5 #"block"
0 0 14 3 11 #"green-block"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 14 3 5 #"from:"
0 0 24 3 1 #" "
0 0 14 3 7 #"yellow-"
0 0 14 3 5 #"block"
0 0 14 3 12 #"yellow-block"
0 0 24 3 1 #" "
0 0 14 3 5 #"blue-"
0 0 14 3 5 #"block"
0 0 14 3 10 #"blue-block"
0 0 24 3 1 #")"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 3 1 #"("
0 0 15 3 13 #"define-recipe"
0 0 24 3 1 #" "
0 0 14 3 3 #"my-"
0 0 14 3 7 #"recipe2"
0 0 14 3 10 #"my-recipe2"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 14 3 5 #"make:"
0 0 24 3 1 #" "
0 0 21 3 1 #"1"
0 0 24 3 1 #" "
0 0 14 3 6 #"green-"
0 0 14 3 5 #"block"
0 0 14 3 11 #"green-block"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 14 3 5 #"from:"
@ -892,33 +957,27 @@
0 0 24 3 1 #"("
0 0 15 3 13 #"define-recipe"
0 0 24 3 1 #" "
0 0 14 3 3 #"my-"
0 0 14 3 7 #"recipe3"
0 0 14 3 10 #"my-recipe3"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 14 3 5 #"make:"
0 0 24 3 1 #" "
0 0 21 3 1 #"5"
0 0 24 3 1 #" "
0 0 14 3 7 #"purple-"
0 0 14 3 5 #"block"
0 0 14 3 12 #"purple-block"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 14 3 5 #"from:"
0 0 24 3 2 #" ("
0 0 14 3 5 #"blue-"
0 0 14 3 5 #"block"
0 0 14 3 10 #"blue-block"
0 0 24 3 1 #" "
0 0 14 3 4 #"red-"
0 0 14 3 5 #"block"
0 0 14 3 9 #"red-block"
0 0 24 3 1 #")"
0 0 24 29 1 #"\n"
0 0 24 3 9 #" ("
0 0 14 3 4 #"red-"
0 0 14 3 5 #"block"
0 0 14 3 9 #"red-block"
0 0 24 3 1 #" "
0 0 14 3 5 #"blue-"
0 0 14 3 5 #"block"
0 0 14 3 10 #"blue-block"
0 0 24 3 1 #")"
0 0 24 29 1 #"\n"
0 0 24 3 3 #" )"
@ -933,12 +992,11 @@
0 0 24 3 1 #")"
0 0 24 29 1 #"\n"
0 0 24 3 3 #" ("
0 0 14 3 9 #"particles"
0 0 24 29 1 #"\n"
0 0 24 3 4 #" ("
0 0 14 3 5 #"noise"
0 0 24 3 2 #" ("
0 0 14 3 7 #"overlay"
0 0 24 29 1 #"\n"
0 0 24 3 5 #" ("
0 0 24 3 11 #" ("
0 0 14 3 4 #"star"
0 0 24 3 1 #" "
0 0 21 3 2 #"30"
@ -948,7 +1006,7 @@
0 0 14 3 5 #"color"
0 0 24 3 1 #")"
0 0 24 29 1 #"\n"
0 0 24 3 5 #" ("
0 0 24 3 11 #" ("
0 0 14 3 4 #"star"
0 0 24 3 1 #" "
0 0 21 3 2 #"36"
@ -1404,8 +1462,7 @@
0 0 24 3 1 #"("
0 0 15 3 13 #"define-entity"
0 0 24 3 1 #" "
0 0 14 3 7 #"yellow-"
0 0 14 3 3 #"pig"
0 0 14 3 10 #"yellow-pig"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 19 3 7 #"\"Piggy\""
@ -1420,8 +1477,7 @@
0 0 24 3 1 #"("
0 0 15 3 13 #"define-entity"
0 0 24 3 1 #" "
0 0 14 3 4 #"red-"
0 0 14 3 3 #"pig"
0 0 14 3 7 #"red-pig"
0 0 24 29 1 #"\n"
0 0 24 3 2 #" "
0 0 19 3 7 #"\"Piggy\""
@ -1435,60 +1491,6 @@
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 3 1 #"("
0 0 14 3 16 #"add-behaviour-to"
0 0 24 3 1 #" "
0 0 14 3 7 #"yellow-"
0 0 14 3 5 #"block"
0 0 24 29 1 #"\n"
0 0 24 3 19 #" ("
0 0 14 3 3 #"on-"
0 0 14 3 5 #"punch"
0 0 24 29 1 #"\n"
0 0 24 3 20 #" ("
0 0 14 3 17 #"on-punch-sequence"
0 0 24 29 1 #"\n"
0 0 24 3 22 #" ("
0 0 14 3 14 #"star-particles"
0 0 24 3 1 #" "
0 0 19 3 8 #"\"yellow\""
0 0 24 3 1 #")"
0 0 24 29 1 #"\n"
0 0 24 3 22 #" ("
0 0 14 3 5 #"spawn"
0 0 24 3 1 #" "
0 0 14 3 7 #"yellow-"
0 0 14 3 3 #"pig"
0 0 24 3 4 #"))))"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 3 1 #"("
0 0 14 3 16 #"add-behaviour-to"
0 0 24 3 1 #" "
0 0 14 3 4 #"red-"
0 0 14 3 5 #"block"
0 0 24 29 1 #"\n"
0 0 24 3 19 #" ("
0 0 14 3 3 #"on-"
0 0 14 3 5 #"punch"
0 0 24 29 1 #"\n"
0 0 24 3 20 #" ("
0 0 14 3 17 #"on-punch-sequence"
0 0 24 29 1 #"\n"
0 0 24 3 22 #" ("
0 0 14 3 14 #"star-particles"
0 0 24 3 1 #" "
0 0 19 3 5 #"\"red\""
0 0 24 3 1 #")"
0 0 24 29 1 #"\n"
0 0 24 3 22 #" ("
0 0 14 3 5 #"spawn"
0 0 24 3 1 #" "
0 0 14 3 7 #"red-pig"
0 0 24 3 4 #"))))"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 3 1 #"("
0 0 15 3 6 #"define"
0 0 24 3 1 #" "
0 0 14 3 10 #"tree-schem"
@ -1660,28 +1662,180 @@
) 0 0 24 3 3 #")))"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 17 3 59
#";GAME LOGIC! (Abstracted from all the asset generation...)"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 3 1 #"("
0 0 14 3 16 #"add-behaviour-to"
0 0 14 3 9 #"game-rule"
0 0 24 29 1 #"\n"
0 0 24 3 1 #" "
0 0 14 3 3 #"on:"
0 0 24 3 1 #" "
0 0 14 3 5 #"block"
0 0 24 3 1 #" "
0 0 14 3 5 #"punch"
0 0 24 3 1 #" "
0 0 14 3 12 #"yellow-block"
0 0 24 29 1 #"\n"
0 0 24 3 1 #" "
0 0 15 3 3 #"do:"
0 0 24 3 2 #" ("
0 0 14 3 9 #"particles"
0 0 24 29 1 #"\n"
0 0 24 3 6 #" "
0 0 21 3 2 #"20"
0 0 24 29 1 #"\n"
0 0 24 3 7 #" ("
0 0 14 3 14 #"star-particles"
0 0 24 3 1 #" "
0 0 19 3 8 #"\"yellow\""
0 0 24 3 2 #"))"
0 0 24 29 1 #"\n"
0 0 24 3 6 #" ("
0 0 14 3 5 #"spawn"
0 0 24 3 1 #" "
0 0 14 3 10 #"yellow-pig"
0 0 24 3 2 #"))"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 3 1 #"("
0 0 14 3 9 #"game-rule"
0 0 24 29 1 #"\n"
0 0 24 3 1 #" "
0 0 14 3 3 #"on:"
0 0 24 3 1 #" "
0 0 14 3 5 #"block"
0 0 24 3 1 #" "
0 0 14 3 5 #"punch"
0 0 24 3 1 #" "
0 0 14 3 9 #"red-block"
0 0 24 29 1 #"\n"
0 0 24 3 1 #" "
0 0 15 3 3 #"do:"
0 0 24 3 2 #" ("
0 0 14 3 9 #"particles"
0 0 24 29 1 #"\n"
0 0 24 3 6 #" "
0 0 21 3 2 #"20"
0 0 24 29 1 #"\n"
0 0 24 3 7 #" ("
0 0 14 3 14 #"star-particles"
0 0 24 3 1 #" "
0 0 19 3 5 #"\"red\""
0 0 24 3 2 #"))"
0 0 24 29 1 #"\n"
0 0 24 3 6 #" ("
0 0 14 3 5 #"spawn"
0 0 24 3 1 #" "
0 0 14 3 7 #"red-pig"
0 0 24 3 2 #"))"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 3 1 #"("
0 0 14 3 9 #"game-rule"
0 0 24 29 1 #"\n"
0 0 24 3 1 #" "
0 0 14 3 3 #"on:"
0 0 24 3 1 #" "
0 0 14 3 5 #"block"
0 0 24 3 1 #" "
0 0 14 3 5 #"punch"
0 0 24 3 1 #" "
0 0 14 3 11 #"green-block"
0 0 24 29 1 #"\n"
0 0 24 3 19 #" ("
0 0 14 3 8 #"on-punch"
0 0 24 29 1 #"\n"
0 0 24 3 20 #" ("
0 0 14 3 17 #"on-punch-sequence"
0 0 24 29 1 #"\n"
0 0 24 3 22 #" ("
0 0 24 3 1 #" "
0 0 15 3 3 #"do:"
0 0 24 3 2 #" ("
0 0 14 3 15 #"place-schematic"
0 0 24 3 1 #" "
0 0 14 3 10 #"tree-schem"
0 0 24 3 1 #")"
0 0 24 29 1 #"\n"
0 0 24 3 22 #" ("
0 0 24 3 6 #" ("
0 0 14 3 15 #"place-schematic"
0 0 24 3 1 #" "
0 0 14 3 9 #"pig-schem"
0 0 24 3 4 #"))))"
0 0 24 3 2 #"))"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 3 1 #"("
0 0 14 3 9 #"game-rule"
0 0 24 29 1 #"\n"
0 0 24 3 1 #" "
0 0 14 3 3 #"on:"
0 0 24 3 1 #" "
0 0 14 3 4 #"item"
0 0 24 3 1 #" "
0 0 14 3 4 #"drop"
0 0 24 3 1 #" "
0 0 14 3 13 #"zelda-thing-1"
0 0 24 29 1 #"\n"
0 0 24 3 1 #" "
0 0 15 3 3 #"do:"
0 0 24 3 2 #" ("
0 0 14 3 9 #"particles"
0 0 24 29 1 #"\n"
0 0 24 3 6 #" "
0 0 21 3 2 #"50"
0 0 24 29 1 #"\n"
0 0 24 3 7 #" ("
0 0 14 3 14 #"star-particles"
0 0 24 3 1 #" "
0 0 19 3 7 #"\"green\""
0 0 24 3 2 #"))"
0 0 24 29 1 #"\n"
0 0 24 3 6 #" ("
0 0 14 3 5 #"spawn"
0 0 24 3 1 #" "
0 0 14 3 7 #"red-pig"
0 0 24 3 2 #"))"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 3 1 #"("
0 0 14 3 9 #"game-rule"
0 0 24 29 1 #"\n"
0 0 24 3 1 #" "
0 0 14 3 3 #"on:"
0 0 24 3 1 #" "
0 0 14 3 5 #"block"
0 0 24 3 1 #" "
0 0 14 3 5 #"punch"
0 0 24 3 1 #" "
0 0 14 3 10 #"blue-block"
0 0 24 29 1 #"\n"
0 0 24 3 1 #" "
0 0 15 3 3 #"do:"
0 0 24 3 2 #" ("
0 0 14 3 11 #"place-block"
0 0 24 3 1 #" "
0 0 14 3 9 #"red-block"
0 0 24 3 2 #"))"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 3 1 #"("
0 0 14 3 9 #"game-rule"
0 0 24 29 1 #"\n"
0 0 24 3 1 #" "
0 0 14 3 3 #"on:"
0 0 24 3 1 #" "
0 0 14 3 4 #"item"
0 0 24 3 1 #" "
0 0 14 3 4 #"drop"
0 0 24 3 1 #" "
0 0 14 3 10 #"blue-block"
0 0 24 29 1 #"\n"
0 0 24 3 1 #" "
0 0 15 3 3 #"do:"
0 0 24 3 2 #" ("
0 0 14 3 11 #"place-block"
0 0 24 3 1 #" "
0 0 14 3 9 #"red-block"
0 0 24 3 2 #"))"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 3 1 #" "

170
lua.rkt
View File

@ -61,14 +61,59 @@
) ) ]))
(define-syntax (define-lua-callback stx)
(syntax-case stx ()
[(_ name context )
(with-syntax* ([def-id (format-id stx "on-~a-~a-def" #'context #'name)]
[ref-id (format-id stx "on-~a-~a" #'context #'name)]
[wrapper-id (format-id stx "~a-wrapper" #'context)]
)
#`(begin
(define-lua def-id
(name wrapper-id))
;Some default code snippets
(provide ref-id)
(define (ref-id . args)
(apply (curry ref-lua def-id) args))
(define-lua particles-def
"
function(file,num,vx,vy,vz,size)
return function(pos, node, player, pointed_thing)
for i=1,num do
))]))
(define-syntax (define-lua-callbacks stx)
(syntax-case stx ()
[(_ name context ... )
#'(begin
(define-lua-callback name context)
...)]))
(define (block-punch-wrapper code)
(format
"return function(pos, node, player, pointed_thing)
~a
end"
code))
(define (item-drop-wrapper code)
(format
"return function(itemstack, dropper, pos)
~a
itemstack:take_item()
return itemstack
end"
code))
(define (particles wrapper)
(format
"function(num,file)
vx = 5
vy = 5
vz = 5
size = 10
~a
end"
(wrapper
"for i=1,num do
minetest.add_particle({
pos = pos,
velocity = {x=vx*(math.random()-.5), y=vy*(math.random()-.5), z=vz*(math.random()-.5)},
@ -80,57 +125,75 @@ function(file,num,vx,vy,vz,size)
texture = file,
playername = 'singleplayer'
})
end
end
end
")
(provide particles)
(define (particles img (num 30) (vx 2) (vy 2) (vz 2) (size 5))
(ref-lua particles-def img num vx vy vz size))
end")
))
(define-lua spawn-def
"
function(entity)
return function(pos, node, player, pointed_thing)
local new_pos = {
(define-lua-callbacks
particles
block-punch
item-drop)
(define (spawn wrapper)
(format
"function(entity)
~a
end"
(wrapper
"local new_pos = {
x=pos.x,
y=pos.y + 1,
z=pos.z
}
minetest.add_entity(new_pos, entity)
end
end
")
minetest.add_entity(new_pos, entity)")
))
(provide spawn)
(define (spawn entity)
(ref-lua spawn-def entity))
(define-lua-callbacks
spawn
block-punch
item-drop)
(define-lua place-schematic-def
"
function(path)
return function(pos, node, player, pointed_thing)
minetest.place_schematic(pos,path,'random',nil,false)
end
end
")
(define (place-schematic wrapper)
(format
"function(path)
~a
end"
(wrapper
"minetest.place_schematic(pos,path,'random',nil,false)")
))
(provide place-schematic)
(define (place-schematic schem)
(ref-lua place-schematic-def schem))
(define-lua-callbacks
place-schematic
block-punch
item-drop)
(define (place-block wrapper)
(format
"function(block)
~a
end"
(wrapper
"minetest.set_node(pos,{name=block})")
))
(define-lua-callbacks
place-block
block-punch
item-drop)
(define-lua on-punch-sequence-def
(define-lua on-block-punch-sequence-def
"
function(fs)
return function(pos, node, player, pointed_thing)
@ -139,7 +202,30 @@ function(fs)
end
")
(provide on-punch-sequence)
(define (on-punch-sequence . fs)
(ref-lua on-punch-sequence-def fs))
(provide on-block-punch-sequence)
(define (on-block-punch-sequence . fs)
(ref-lua on-block-punch-sequence-def fs))
(define-lua on-item-drop-sequence-def
"
function(fs)
return function(itemstack, dropper, pos)
for i,f in ipairs(fs) do f(itemstack, dropper, pos) end
itemstack:take_item()
return itemstack
end
end
")
(provide on-item-drop-sequence)
(define (on-item-drop-sequence . fs)
(ref-lua on-item-drop-sequence-def fs))

44
rules.rkt Normal file
View File

@ -0,0 +1,44 @@
#lang racket
(require "core.rkt")
(provide add-behaviour-to)
(provide game-rule)
(require (for-syntax racket/syntax))
(define-syntax (add-behaviour-to stx)
(syntax-case stx ()
[(_ target (key val))
(with-syntax* ([target-id (format-id stx "~a" #'target)]
[key-str (symbol->string
(format-symbol "~a" #'key))])
#`(add-behaviour target-id
(list key-str val)
my-mod))]))
(require (for-syntax racket))
(define-syntax (game-rule stx)
(syntax-case stx (on: do:)
[(_ on: kind verb subj do: effects ...)
(with-syntax* ([subj-id (format-id stx "~a" #'subj)]
[callback-id (symbol->string
(format-symbol "on-~a" #'verb))]
[sequence-id (format-id stx "on-~a-~a-sequence" #'kind #'verb)]
[effect-prefix (symbol->string (format-symbol "on-~a-~a" #'kind #'verb))]
[(prefixed-effects ...) (map (lambda (x)
(cons
(format-id stx "~a-~a"
(syntax->datum #'effect-prefix)
(syntax->datum (first (syntax->list x))))
(rest (syntax->list x))))
(syntax->list #'(effects ...)))])
#`(add-behaviour subj-id
(list callback-id (sequence-id
prefixed-effects ...
))
my-mod))]))