#!/usr/bin/env bb (ns gen-levels (:require [babashka.fs :as fs] [clojure.pprint :as pprint] [clojure.data.xml :as xml] [clojure.string :as str] [clojure.java.io :as io])) (def walls-tsx (xml/parse (io/reader "./tiled/walls.tsx"))) (def wall-colliders (->> (:content walls-tsx) (remove string?) (filter #(= (:tag %) :tile)) (map (fn [tile] (hash-map :id (get-in tile [:attrs :id]) :boxes (->> (:content tile) (remove string?) (map :content) (flatten) (remove string?) (map :attrs) (map #(select-keys % [:x :y :height :width])) (map #(update-vals % (fn [v] (Math/round (Double/parseDouble v))))))))))) (def level-001-tmx (xml/parse (io/reader "./tiled/level_001.tmx"))) (def level-001 (let [tags (remove string? (:content level-001-tmx)) tile-nums (-> (filter #(= (:tag %) :layer) tags) first :content second :content first str/split-lines (->> (remove empty?) (map #(str/split % #",")) (map (fn [row] (map Integer/parseInt row)))))] (hash-map :tiles tile-nums :spawns (reduce (fn [acc tag] (if (= (:tag tag) :object) (conj acc (hash-map :name (get-in tag [:attrs :name]) :x (Math/round (Double/parseDouble (get-in tag [:attrs :x]))) :y (Math/round (Double/parseDouble (get-in tag [:attrs :y]))))) acc)) '() (:content (first (filter #(= (get-in % [:attrs :name]) "spawns") tags))))))) (pprint/pprint :row (ffirst (:tiles level-001))) ;; :wall-colliders wall-colliders}) ;; (fs/write-lines "level_001.lua" (pr-str '(local name "travis"))) ;; (pprint/pprint (pr-str level-001)) (fs/write-lines "../level-001.fnl" ["(local level-001" (pr-str level-001) ")\n\n" "{ :level-01 level-01 }"]) ;; (str "return " (pr-str {:tile (ffirst (:tiles level-001)) ;; :wall-colliders wall-colliders ;; :spawns (:spawns level-001)})))) ;; (defn get-config-files [] (map #(hash-map :file-name % :content (fs/read-all-lines %)) (fs/glob "." "**.hcl"))) ;; (defn gen-cron [start] (format "%d * * * *" start)) ;; (defn get-config-files [] (map #(hash-map :file-name % :content (fs/read-all-lines %)) (fs/glob "." "**.hcl"))) ;; (defn remove-build-files [files]