OPENSCAD := openscad
BUILD := build
PARTS := plate ink glow
LINE ?= K

.PHONY: test preview qr stls site-assets clean

test:
	mkdir -p $(BUILD)
	$(OPENSCAD) -o $(BUILD)/test.stl tests/test_model.scad

preview:
	mkdir -p $(BUILD)
	$(OPENSCAD) --imgsize=700,700 --projection=o \
	  --camera=70,70,0,0,0,0,160 --viewall \
	  -o $(BUILD)/preview.png piece.scad

qr:
	../.venv/bin/python ../scripts/gen_qr.py

stls:
	mkdir -p $(BUILD)/stl
	for p in $(PARTS); do \
	  $(OPENSCAD) -D 'PART="'$$p'"' -D 'LINE="$(LINE)"' \
	    -o $(BUILD)/stl/$$p.stl piece.scad || exit 1; \
	done
	@ls -la $(BUILD)/stl

# Publish printable assets into the website (served at /downloads/...).
# One STL set serves every line: glow color is assigned in the slicer.
SITE_DL := ../site/public/downloads

site-assets: stls
	mkdir -p $(SITE_DL)
	cp $(BUILD)/stl/plate.stl $(SITE_DL)/la-espera-plate.stl
	cp $(BUILD)/stl/ink.stl   $(SITE_DL)/la-espera-ink.stl
	cp $(BUILD)/stl/glow.stl  $(SITE_DL)/la-espera-glow.stl
	cd .. && rm -f site/public/downloads/la-espera-source.zip && \
	  zip -q -r site/public/downloads/la-espera-source.zip \
	  model scripts README.md -x "model/build/*" -x "*.DS_Store"
	@ls -la $(SITE_DL)

clean:
	rm -rf $(BUILD)
