#lang racket (require 2htdp/image) (provide compile-mod) (require "core.rkt") ;Can be redone to return a special-compile. ; Then the compiler just compiles all the assets wrapped in special compiles... ; Then writes to the file. (define (compile-item i) (special-compile (thunk (++ "-- My item is named " (asset-name i) "\n" (format "minetest.register_craftitem(\"~a\", ~a)\n\n" (asset-name i) (compile-v (asset->hash i))))))) (define (compile-block b) (special-compile (thunk (++ "-- My block is named " (asset-name b) "\n" (format "minetest.register_node(\"~a\", ~a)\n\n" (asset-name b) (compile-v (asset->hash b))))))) (define (compile-recipe b) (special-compile (thunk (++ "-- My recipe... \n" (format "minetest.register_craft(~a)\n\n" (compile-v (asset->hash b))))))) (define (compile-entity b) (special-compile (thunk (++ "-- My entity is named " (asset-name b) "\n" (format "mobs:register_mob(~s, ~a)\n\n" (asset-name b) (compile-v (asset->hash b))))))) (define (compile-lua-def b) (special-compile (thunk (++ "-- Some lua code sent by Racket \n" (asset-struct-more b))))) (define (compile-mod m) (make-directory* (path-for m)) (make-directory* (++ (path-for m) "/textures")) (make-directory* (++ (path-for m) "/schematics")) (with-output-to-file (lua-file-for m) #:exists 'replace (lambda () (printf (++ "-- This is my mod! It's called " (mod-struct-name m) "\n\n\n")))) ;Do all defs first (map (curry append-to-file (lua-file-for m)) (map compile-v (map compile-lua-def (mod-struct-lua-defs m)))) ;Then do other assets (map (curry append-to-file (lua-file-for m)) (map compile-v (append (map compile-item (mod-struct-items m)) (map compile-block (mod-struct-blocks m)) (map compile-recipe (mod-struct-recipes m)) (map compile-entity (mod-struct-entities m)) ))) "Your mod is ready!") ; (and ; (compile-lua-defs m (mod-struct-lua-defs m)) ; (compile-blocks m (mod-struct-blocks m)) ; (compile-items m (mod-struct-items m)) ; (compile-recipes m (mod-struct-recipes m)) ; ) ;)