GRISTS = build agricultural intelligent energetic primordeal universal
RANKS = basic improved radiant

GRIST_HUE_build = 203
GRIST_HUE_agricultural = 40
GRIST_HUE_intelligent = 77
GRIST_HUE_energetic = 0
GRIST_HUE_primordeal = 280
GRIST_HUE_universal = 0

GRIST_VALUE_basic = 128
GRIST_VALUE_improved = 199
GRIST_VALUE_radiant = 255

GRIST_VALUE_basic_universal = 120
GRIST_VALUE_improved_universal = 160
GRIST_VALUE_radiant_universal = 190

GRIST_SATURATION_universal = 100

BLOCKS = kubejs/assets/malloc/textures/block
ITEMS = kubejs/assets/malloc/textures/item

TEXTURES = $(foreach element,$(GRISTS),$(foreach rank,$(RANKS), grist_$(rank)_$(element).png))

ITEM_TEXTURES = $(addprefix $(ITEMS)/,$(TEXTURES))
BLOCK_TEXTURES = $(addprefix $(BLOCKS)/,$(TEXTURES))

.PHONY: all

all: $(ITEM_TEXTURES) $(BLOCK_TEXTURES)

$(BLOCKS)/grist_basic_%.png: assets/textures/block/grist.png Makefile
	if [ $* = "universal" ]; then \
		magick $< -modulate $(GRIST_VALUE_basic_universal),$(GRIST_SATURATION_universal) $@; \
	else \
		magick $< -fill "hsv(${GRIST_HUE_${*}}, 255, $(GRIST_VALUE_basic))" -tint 100 $@; \
	fi

$(BLOCKS)/grist_improved_%.png: assets/textures/block/grist.png Makefile
	if [ $* = "universal" ]; then \
		magick $< -modulate $(GRIST_VALUE_improved_universal),$(GRIST_SATURATION_universal) $@; \
	else \
		magick $< -fill "hsv(${GRIST_HUE_${*}}, 255, $(GRIST_VALUE_improved))" -tint 100 $@; \
	fi

$(BLOCKS)/grist_radiant_%.png: assets/textures/block/grist.png Makefile
	if [ $* = "universal" ]; then \
		magick $< -modulate $(GRIST_VALUE_radiant_universal),$(GRIST_SATURATION_universal) $@; \
	else \
		magick $< -fill "hsv(${GRIST_HUE_${*}}, 255, $(GRIST_VALUE_radiant))" -tint 100 $@; \
	fi

$(ITEMS)/grist_basic_%.png: assets/textures/item/grist_basic.png Makefile
	if [ $* = "universal" ]; then \
		magick $< -modulate $(GRIST_VALUE_basic_universal),$(GRIST_SATURATION_universal) $@; \
	else \
		magick $< -fill "hsv(${GRIST_HUE_${*}}, 255, $(GRIST_VALUE_basic))" -tint 100 $@; \
	fi


$(ITEMS)/grist_improved_%.png: assets/textures/item/grist_improved.png Makefile
	if [ $* = "universal" ]; then \
		magick $< -modulate $(GRIST_VALUE_improved_universal),$(GRIST_SATURATION_universal) $@; \
	else \
		magick $< -fill "hsv(${GRIST_HUE_${*}}, 255, $(GRIST_VALUE_improved))" -tint 100 $@; \
	fi

$(ITEMS)/grist_radiant_%.png: assets/textures/item/grist_radiant.png Makefile
	if [ $* = "universal" ]; then \
		magick $< -modulate $(GRIST_VALUE_radiant_universal),$(GRIST_SATURATION_universal) $@; \
	else \
		magick $< -fill "hsv(${GRIST_HUE_${*}}, 255, $(GRIST_VALUE_radiant))" -tint 100 $@; \
	fi