Shaped recipes

master
Lindsey Handley 2017-12-22 19:45:55 -08:00
parent 4ba1cf8d4c
commit d8f057ed93
3 changed files with 101 additions and 24 deletions

View File

@ -28,6 +28,8 @@
(provide path-for)
(provide tree-map)
(provide mod-struct)
@ -44,6 +46,8 @@
(define STR_TYPE "~s")
(define INT_TYPE "~a")
(define SYM_TYPE "~a")
(define ARR_TYPE "ARR_TYPE")
;UTIL
@ -53,6 +57,12 @@
(-> list? boolean?)
(= (count identity l) (length l)))
(define (tree-map f tree)
(if (list? tree)
(map (curry tree-map f) tree)
(f tree)
))
;CONFIG
(define MINETEST_PATH "/home/thoughtstem/.minetest/")
@ -131,6 +141,7 @@
(map (lambda (x) (format type x))
arr) ",")))
(define/contract (compile-ass-arr arr type1 type2)
(-> list? any/c any/c string?)
(format

View File

@ -290,7 +290,7 @@
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 493 0 28 3 12 #"#lang racket"
255 0 -1 -1 0 503 0 28 3 12 #"#lang racket"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 17 3 14 #";Housecleaning"
@ -303,14 +303,14 @@
0 0 24 29 1 #"\n"
0 0 17 3 9 #";Features"
0 0 24 29 1 #"\n"
0 0 17 3 22 #";TODO: Support recipes"
0 0 24 29 1 #"\n"
0 0 17 3 24 #";TODO: Support particles"
0 0 24 29 1 #"\n"
0 0 17 3 19 #";TODO: Support mobs"
0 0 24 29 1 #"\n"
0 0 17 3 49 #";TODO: Support callback functions on the above..."
0 0 24 29 1 #"\n"
0 0 17 3 24 #";TODO: Support particles"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 17 3 55 #";TODO: Support building. (Functional API, not drones.)"
0 0 24 29 1 #"\n"
0 0 17 3 29 #";TODO: Active block modifiers"
@ -766,21 +766,6 @@
0 0 24 3 2 #"))"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 17 3 26 #";(define-recipe my_recipe1"
0 0 24 29 1 #"\n"
0 0 17 3 17 #"; 5 purple_block"
0 0 24 29 1 #"\n"
0 0 17 3 1 #";"
0 0 17 3 3 #" ("
0 0 17 3 4 #"list"
0 0 17 3 1 #" "
0 0 17 3 21 #"blue_block red_block)"
0 0 24 29 1 #"\n"
0 0 17 3 1 #";"
0 0 17 3 3 #" ("
0 0 17 3 4 #"list"
0 0 17 3 1 #" "
0 0 17 3 23 #"red_block blue_block))"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 3 1 #"("
@ -825,8 +810,33 @@
0 0 24 3 1 #")"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 17 3 10 #";RECIPES!!"
0 0 24 3 1 #"("
0 0 15 3 13 #"define-recipe"
0 0 24 3 1 #" "
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 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 10 #"blue_block"
0 0 24 3 1 #" "
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 9 #"red_block"
0 0 24 3 1 #" "
0 0 14 3 10 #"blue_block"
0 0 24 3 1 #")"
0 0 24 29 1 #"\n"
0 0 24 3 3 #" )"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"
0 0 24 29 1 #"\n"

View File

@ -24,12 +24,20 @@
(recipe-struct-inputs r))])
(format "recipe = ~a" (compile-arr asset-names STR_TYPE))))
(define (compile-recipe-input-shaped m r)
(let ([asset-names (tree-map
(curry asset-name m)
(recipe-struct-inputs r))])
(format "recipe = {~a}" (string-join
(map (curryr compile-arr STR_TYPE) asset-names)
",\n"))))
;minetest.register_craft({
; type = "shapeless",
; output = "mymod:diamond",
; recipe = {"mymod:diamond_fragments", "mymod:diamond_fragments", "mymod:diamond_fragments"}
;})
(define/contract (compile-recipe m r)
(define/contract (compile-shapeless-recipe m r)
(-> mod-struct? recipe-struct? string?)
(++ "-- My recipe is named " (asset-name m r) "\n"
(format
@ -41,13 +49,61 @@
(compile-recipe-output m r)
(compile-recipe-input m r))))
(define/contract (compile-shaped-recipe m r)
(-> mod-struct? recipe-struct? string?)
(++ "-- My recipe is named " (asset-name m r) "\n"
(format
" minetest.register_craft({
~a,
~a,
})\n\n"
(compile-recipe-output m r)
(compile-recipe-input-shaped m r))))
(define (is-shaped? r)
(list? (first (recipe-struct-inputs r))))
(define/contract (compile-recipe m r)
(-> mod-struct? recipe-struct? string?)
(if (is-shaped? r)
(compile-shaped-recipe m r)
(compile-shapeless-recipe m r)))
;;Unshaped version...
(define-syntax (define-recipe stx)
(syntax-case stx (make: from:)
[(_ id make: num output from: (i1 i2 i3) (i4 i5 i6) (i7 i8 i9) )
(with-syntax* ([name (symbol->string (format-symbol "~a" #'id))])
#`(begin
(define id (recipe-struct name "" num output (list (list i1 i2 i3)
(list i4 i5 i6)
(list i7 i8 i9))))
(set-my-mod! (add-recipe my-mod id)))
)]
[(_ id make: num output from: (i1 i2) (i3 i4) (i5 i6) )
(with-syntax* ([name (symbol->string (format-symbol "~a" #'id))])
#`(begin
(define id (recipe-struct name "" num output (list (list i1 i2)
(list i3 i4)
(list i5 i6))))
(set-my-mod! (add-recipe my-mod id)))
)]
[(_ id make: num output from: (i1 i2 i3) (i4 i5 i6) )
(with-syntax* ([name (symbol->string (format-symbol "~a" #'id))])
#`(begin
(define id (recipe-struct name "" num output (list (list i1 i2 i3)
(list i4 i5 i6))))
(set-my-mod! (add-recipe my-mod id)))
)]
[(_ id make: num output from: (i1 i2) (i3 i4) )
(with-syntax* ([name (symbol->string (format-symbol "~a" #'id))])
#`(begin
(define id (recipe-struct name "" num output (list (list i1 i2)
(list i3 i4))))
(set-my-mod! (add-recipe my-mod id)))
)]
[(_ id make: num output from: items ... )
(with-syntax* ([item-id (format-id stx "~a" #'id)]
[name (symbol->string (format-symbol "~a" #'id))])
(with-syntax* ([name (symbol->string (format-symbol "~a" #'id))])
#`(begin
(define id (recipe-struct name "" num output (list items ...)))
(set-my-mod! (add-recipe my-mod id)))