yaap/examples/aseprite_odin_generator.odin
Stefan Stefanov 3f1c523ad9 Major refactor:
* Removed any hotreload functionality to simplify the code-base, may introduce it back again if there's a need to redesign the UI as it was used for dynamic prototyping.
* Split the code base into two packages: generator and frontend. The 'generator' package is reponsible for the functionality of making the atlases, etc... while the frontend is pure the immediate mode UI implemented with raygui and application globals
* New build scripts, windows only for now.
2024-08-30 18:05:56 +03:00

41 lines
1.1 KiB
Odin

package cli
import ase "../vendors/aseprite"
import "core:encoding/json"
import "core:fmt"
import "core:os"
import "core:slice"
import s "core:strings"
import rl "vendor:raylib"
import stbrp "vendor:stb/rect_pack"
import gen "../src/generator"
ATLAS_SIZE :: 512
IMPORT_PATH :: "./example.aseprite"
EXPORT_PATH :: "./atlas.png"
main :: proc() {
ase_file, ase_ok := os.read_entire_file(IMPORT_PATH)
if !ase_ok {
fmt.panicf("Couldn't load file!")
}
target_dir := os.get_current_directory()
atlas: rl.Image = rl.GenImageColor(ATLAS_SIZE, ATLAS_SIZE, rl.BLANK)
atlas_entries: [dynamic]gen.AtlasEntry = make([dynamic]gen.AtlasEntry)
gen.unmarshall_aseprite_dir(target_dir, &atlas_entries)
metadata := gen.pack_atlas_entries(atlas_entries[:], &atlas, 10, 10)
json_bytes, jerr := json.marshal(metadata)
os.write_entire_file("./metadata.json", json_bytes)
sb := gen.metadata_source_code_generate(metadata[:], gen.odin_source_generator_metadata)
odin_output_str := s.to_string(sb)
os.write_entire_file("./output.odin", transmute([]byte)odin_output_str)
rl.ExportImage(atlas, EXPORT_PATH)
}