Changed the image assembly into 2D instead of vertical.

master
Jaka Perovšek 2021-11-29 17:59:45 +01:00
parent a1d5c81a06
commit a5f586f1be
5 changed files with 26 additions and 18 deletions

View File

@ -9,6 +9,7 @@ import sys
import time
import logging
import certifi
import math
from PIL import Image
from mutagen.oggvorbis import OggVorbis
from distutils.dir_util import copy_tree
@ -143,23 +144,24 @@ def fetch_and_cut_song(tape, ffmpeg_version):
def assemble_png_image(tapes, icons=False):
if icons:
img_names = [f"./source/images/{tape['identifier']}_icon.png" for tape in tapes]
images = [Image.open("./source/images/boombox_icon.png")]
else:
img_names = [f"./source/images/{tape['identifier']}.png" for tape in tapes]
images = []
images += [Image.open(x) for x in img_names]
images = [Image.open(x) for x in img_names]
widths, heights = zip(*(i.size for i in images))
total_width = max(widths)
max_height = sum(heights)
columns = int((len(images))**0.5)
rows = int(math.ceil(len(images) / columns))
total_width = max(widths) * columns
max_height = max(heights) * rows
new_im = Image.new('RGBA', (total_width, max_height))
y_offset = 0
for im in images:
new_im.paste(im, (0, y_offset))
y_offset += im.size[1]
for i, im in enumerate(images):
x_offset = max(widths) * (i % columns)
y_offset = max(heights) * math.floor(i / columns)
new_im.paste(im, (x_offset, y_offset))
if icons:
new_im.save("./build/icons.png")
@ -199,6 +201,7 @@ def prepare_images(data, config):
logging.info(f"copying other images")
shutil.copy("./source/images/boombox.png", "./build/boombox.png")
shutil.copy("./source/images/boombox_icon.png", "./build/boombox_icon.png")
shutil.copy("./source/images/PreviewImage.png", "./build/PreviewImage.png")
@ -213,6 +216,9 @@ def build_xml_code(data, config):
condition_delta = [f"{1 / use_length:0.5f}" for use_length in use_lengths]
affliction_delta = [100 / song_length for song_length in song_lengths]
columns = int((len(data))**0.5)
positions = [{"column": i % columns, "row": math.floor(i / columns)} for i in range(len(data))]
logging.info(f"creating jinja environment")
# create jinja2 environment
j2env = j2.Environment(loader=j2.FileSystemLoader(Path(".")))
@ -237,11 +243,12 @@ def build_xml_code(data, config):
output_file.write(template1.render(tapes=data, config=config,
condition_delta=condition_delta,
affliction_delta=affliction_delta,
song_lengths=song_lengths))
song_lengths=song_lengths,
positions=positions))
with open(f"./build/{config['slug']}_style.xml", "w+", encoding="utf8") as output_file:
# render the template
output_file.write(template2.render(tapes=data, config=config))
output_file.write(template2.render(tapes=data, config=config, positions=positions))
def deploy(config):

View File

@ -5,7 +5,8 @@
<UIStyle file="Mods/{{ config['name'] }}/{{ config['slug'] }}_style.xml" />
<None file="Mods/{{ config['name'] }}/icons.png" />
<None file="Mods/{{ config['name'] }}/covers.png" />
<None file="Mods/{{ config['name'] }}/boombox.png" />{% for tape in tapes %}
<None file="Mods/{{ config['name'] }}/boombox.png" />
<None file="Mods/{{ config['name'] }}/boombox_icon.png" />{% for tape in tapes %}
<None file="Mods/{{ config['name'] }}/music/{{ tape["identifier"] }}.ogg" />
<None file="Mods/{{ config['name'] }}/music/{{ tape["identifier"] }}-walkman.ogg" />{% endfor %}
<None file="Mods/{{ config['name'] }}/sound_effects/boombox_insert_cassette.ogg" />

View File

@ -198,7 +198,7 @@
</TitleText>
{% for tape in tapes %}
<{{ config['slug'] }}_cover_{{ tape.identifier }} color="255,255,255,255" textcolor="0,0,0,255">
<Sprite name="{{ config['slug'] }}_cover_{{ tape.identifier }}" texture="Mods/{{ config['name'] }}/covers.png" size="0.0, 0.0" sourcerect="0,{{ loop.index0*328 }},512,328" origin="0.5,0.5" compress="false" tile="false"/>
<Sprite name="{{ config['slug'] }}_cover_{{ tape.identifier }}" texture="Mods/{{ config['name'] }}/covers.png" size="0.0, 0.0" sourcerect="{{ 512 * positions[loop.index0]['column'] }},{{ 328 * positions[loop.index0]['row'] }},512,328" origin="0.5,0.5" compress="false" tile="false"/>
</{{ config['slug'] }}_cover_{{ tape.identifier }}>{% endfor %}
<ita_document1 color="255,255,255,255" textcolor="0,0,0,255">

View File

@ -200,7 +200,7 @@
</TitleText>
{% for tape in tapes %}
<{{ config['slug'] }}_cover_{{ tape.identifier }} color="255,255,255,255" textcolor="0,0,0,255">
<Sprite name="{{ config['slug'] }}_cover_{{ tape.identifier }}" texture="Mods/{{ config['name'] }}/covers.png" size="0.0, 0.0" sourcerect="0,{{ loop.index0*328 }},512,328" origin="0.5,0.5" compress="false" tile="false"/>
<Sprite name="{{ config['slug'] }}_cover_{{ tape.identifier }}" texture="Mods/{{ config['name'] }}/covers.png" size="0.0, 0.0" sourcerect="{{ 512 * positions[loop.index0]['column'] }},{{ 328 * positions[loop.index0]['row'] }},512,328" origin="0.5,0.5" compress="false" tile="false"/>
</{{ config['slug'] }}_cover_{{ tape.identifier }}>{% endfor %}
<InnerGlow color="255,255,255,204" hovercolor="255,255,255,204" selectedcolor="255,255,255,204">
<Sprite texture="Content/UI/InnerGlow.png" sourcerect="0,0,512,384" slice="128,128,384,256" />

View File

@ -24,7 +24,7 @@
<RequiredItem identifier="fpgacircuit" />
</Fabricate>
<Upgrade gameversion="0.9.2.0" scale="0.5" />
<InventoryIcon texture="Mods/{{ config['name'] }}/icons.png" sourcerect="0,0,64,64" origin="0.5,0.5" />
<InventoryIcon texture="Mods/{{ config['name'] }}/boombox_icon.png" sourcerect="0,0,64,64" origin="0.5,0.5" />
<Sprite texture="Mods/{{ config['name'] }}/boombox.png" sourcerect="0,0,100,60" depth="0.55" origin="0.5,0.5" />
<Body width="100" height="60" />
<LightComponent LightColor="0.0,0.85,0.0,0.7" range="4" powerconsumption="0" blinkfrequency="0" IsOn="false" canbeselected="false">
@ -78,7 +78,7 @@
<RequiredItem identifier="fpgacircuit" />
</Fabricate>
<Upgrade gameversion="0.9.2.0" scale="0.5" />
<InventoryIcon texture="Mods/{{ config['name'] }}/icons.png" sourcerect="0,0,64,64" origin="0.5,0.5" />
<InventoryIcon texture="Mods/{{ config['name'] }}/boombox_icon.png" sourcerect="0,0,64,64" origin="0.5,0.5" />
<Sprite texture="Mods/{{ config['name'] }}/boombox.png" sourcerect="0,0,100,60" depth="0.55" origin="0.5,0.5" />
<Body width="100" height="60" />
<LightComponent LightColor="0.0,0.85,0.0,0.7" range="4" powerconsumption="0" blinkfrequency="0" IsOn="false" canbeselected="false">
@ -129,8 +129,8 @@
<RequiredItem identifier="{% if config['slug'] != "sunken_tapes" %}{{ config["slug"] }}-{% endif %}cassette-blank" />
<RequiredItem identifier="fpgacircuit" />
</Fabricate>
<InventoryIcon texture="Mods/{{ config['name'] }}/icons.png" sourcerect="0,{{ loop.index0*41 + 64 }},64,41" origin="0.5,0.5" />
<Sprite texture="Mods/{{ config['name'] }}/icons.png" sourcerect="0,{{ loop.index0*41 + 64 }},64,41" depth="0.6" origin="0.5,0.5" />
<InventoryIcon texture="Mods/{{ config['name'] }}/icons.png" sourcerect="{{ 64 * positions[loop.index0]['column'] }},{{ 41 * positions[loop.index0]['row'] }},64,41" origin="0.5,0.5" />
<Sprite texture="Mods/{{ config['name'] }}/icons.png" sourcerect="{{ 64 * positions[loop.index0]['column'] }},{{ 41 * positions[loop.index0]['row'] }},64,41" depth="0.6" origin="0.5,0.5" />
<Body width="48" height="48" />
<Throwable slots="Any,RightHand,LeftHand" holdpos="5,-65" holdangle="0" handle1="0,1" throwforce="4.0" aimpos="35,-10" msg="ItemMsgPickUpSelect">
<StatusEffect type="OnImpact" target="This" Condition="-5.0" disabledeltatime="true">