Compare commits

...

3 commits

Author SHA1 Message Date
a1704f7bb5 Ignore __pycache__ 2025-06-07 18:29:09 +02:00
5bf0a7945c Add gallery of available designs
Render all the designs currently available into images showcasing them
for the purpose of displaying it on the Factorio Mod portal.
2025-06-07 18:27:20 +02:00
c9755b3576 Add python based source for designs
Copy structure of src/designs.lua to designs.py to have the metadata for
the available designs available to Python scripts.
2025-06-07 18:25:09 +02:00
8 changed files with 193 additions and 1 deletions

3
.gitignore vendored
View file

@ -1 +1,2 @@
bin
bin
__pycache__

108
assemble_image.py Normal file
View file

@ -0,0 +1,108 @@
from PIL import Image, ImageFont, ImageDraw
from designs import models
def make_image(output, items, header, render, text_width, col_width, cols, description=None, transpose=False, scale=1):
col_width += text_width
row_width = int(256 * scale)
header_height = 180
description_height = 100 if description else 0
footer_height = 80
rows = (len(items) + cols - 1) // cols
width = cols * col_width
height = header_height + description_height + rows * row_width + footer_height
font = ImageFont.truetype("FiraSans-Regular", 52)
output_im = Image.new("RGBA", (width, height))
ctx = ImageDraw.Draw(output_im)
def paste_im(model, variant, co):
im = Image.open(f"src/graphics/technology/{model}_{variant.replace('liquid', 'clear')}.png")
src = im.resize((int(256 * scale), int(256 * scale)), 1) if scale != 1 else im
output_im.paste(src, co)
im.close()
white = (255, 255, 255, 255)
def text_im(text, co):
ctx.text(co, text, font=font, fill=white, anchor="lm")
for i, item in enumerate(items):
if transpose:
col, row = i % cols, i // cols
else:
col, row = i // rows, i % rows
x, y = col * col_width, header_height + description_height + row * row_width
render(item, x, y, paste_im, text_im)
if description:
ctx.text((width / 2, header_height + description_height / 2 - 40), description, font=font, fill=white, anchor="mm")
h_font = ImageFont.truetype("FiraSans-Bold", 100)
ctx.text((width / 2, header_height / 2), header, font=h_font, fill=white, anchor="mm")
f_font = ImageFont.truetype("FiraSans-Regular", 40)
ctx.text((width - 10, height - 10), "Quality Glassware / by Hornwitser / CC BY-SA 4.0", font=f_font, fill=white, anchor="rd")
print(f"saving {output}")
output_im.save(output)
def render_model(model, x, y, paste_im, text_im):
name = model["name"]
print(f"pasting {name}")
paste_im(name, "empty", (x, y))
paste_im(name, "liquid_red", (x + 256, y))
text_im(name, (x + 512 + 10, y + 128))
make_image("images/models.png",
items = models.values(),
header = "Models",
render = render_model,
text_width = 400,
col_width = 2 * 256,
cols = 4,
)
def render_variant(variant, x, y, paste_im, text_im):
name = variant["name"]
model = variant["model"]
print(f"pasting {name}")
paste_im(model, name, (x, y))
text_im(name, (x + 256 + 10, y + 128))
make_image("images/variants.png",
items = models["sphere_hemi"]["variants"].values(),
header = "Variants",
render = render_variant,
text_width = 400,
col_width = 256,
cols = 2,
)
make_image("images/frozen.png",
items = list(v for v in models["cone_normal"]["variants"].values() if v["contents"] == "frozen"),
header = "Frozen Variants",
description = "Only the cone_normal model has frozen variants.",
render = render_variant,
text_width = 400,
col_width = 256,
cols = 2,
)
def render_design(variant, x, y, paste_im, text_im):
if not variant: return
name = variant["name"]
model = variant["model"]
print(f"pasting {name}")
paste_im(model, name, (x, y))
all_designs = [v for m in models.values() for v in m["variants"].values()]
all_designs.insert(12, None)
make_image("images/all-designs.png",
items = all_designs,
header = "All Designs",
render = render_design,
text_width = 0,
col_width = 128,
cols = len(models) + 1,
scale = 0.5,
)

82
designs.py Normal file
View file

@ -0,0 +1,82 @@
# Keep this file in sync with src/designs.lua
colors = [
"red",
"green",
"black",
"cyan",
"purple",
"yellow",
"white",
"orange",
"pink",
"blue",
"lime",
]
contents = [
"empty",
"liquid",
"frozen",
]
base_models = [
"cone_normal",
"cone_slim",
"cone_inverted",
"cylinder",
"tube_one",
"tube_two",
"tube_three",
"sphere_normal",
"sphere_tiny",
"sphere_double",
"sphere_tubed",
"sphere_hemi",
"sphere_spiked",
"hourglass",
"torus",
"klein",
"pyramid",
"cube",
"triangle",
"triangle_alt",
"pentagon",
"hexagon",
]
frozen_models = [
"cone_normal",
]
models = {}
for model in base_models:
variants = {
"empty": {
"name": "empty",
"model": model,
"contents": "empty",
},
}
for color in colors:
variants[f"liquid_{color}"] = {
"name": f"liquid_{color}",
"model": model,
"color": color,
"contents": "liquid",
}
if model in frozen_models:
for color in colors:
variants[f"frozen_{color}"] = {
"model": model,
"name": f"frozen_{color}",
"color": color,
"contents": "frozen",
}
models[model] = {
"name": model,
"variants": variants,
}

BIN
images/all-designs.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 MiB

BIN
images/frozen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 609 KiB

BIN
images/models.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

BIN
images/variants.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 541 KiB

View file

@ -1,2 +1,3 @@
bin\oxipng -o 4 --strip safe --alpha src\graphics\technology\*.png
bin\oxipng -o 4 --strip safe --alpha src\graphics\icons\*.png
bin\oxipng -o 4 --strip safe --alpha images\*.png