From 093319eeceb0715bdc6b538fad72abbbd89d0464 Mon Sep 17 00:00:00 2001 From: Faraphel Date: Thu, 7 Jul 2022 23:35:44 +0200 Subject: [PATCH] fixed the ImageLayer Operation that was not pasting the image of top of the other correctly --- .../specific/_PATCH/files/Boot/Strap/de.json | 2 +- .../specific/_PATCH/files/Boot/Strap/en.json | 6 +++--- .../specific/_PATCH/files/Boot/Strap/es.json | 2 +- .../specific/_PATCH/files/Boot/Strap/fr.json | 2 +- .../specific/_PATCH/files/Boot/Strap/ge.json | 2 +- .../specific/_PATCH/files/Boot/Strap/it.json | 2 +- source/mkw/Patch/PatchOperation.py | 21 ++++++++----------- 7 files changed, 17 insertions(+), 20 deletions(-) diff --git a/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/de.json b/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/de.json index 11d27b4..180b6f4 100644 --- a/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/de.json +++ b/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/de.json @@ -2,7 +2,7 @@ "operation": { "img-generate": { "layers": [ - {"type": "color", "color": [0, 0, 0]}, + {"type": "color", "color": [0, 0, 0, 0]}, {"type": "image", "image_path": "files/Boot/Strap/bootscreen-base.png"}, {"type": "text", "x": 0.01, "y": 0.00, "text": "Mario Kart Wii - Faraphel", "font_size": 0.04, "color": [100, 100, 100], "font_path": "files/Boot/Strap/CenturyGothicBold.ttf"}, {"type": "text", "x": 0.10, "y": 0.06, "text": "Elke track heeft een score tussen 1 en 5 sterren", "font_size": 0.045, "color": [255, 180, 0], "font_path": "files/Boot/Strap/CenturyGothicBold.ttf"}, diff --git a/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/en.json b/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/en.json index 6f633e7..578fdad 100644 --- a/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/en.json +++ b/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/en.json @@ -2,7 +2,7 @@ "operation": { "img-generate": { "layers": [ - {"type": "color", "color": [0, 0, 0]}, + {"type": "color", "color": [0, 0, 0, 0]}, {"type": "image", "image_path": "files/Boot/Strap/bootscreen-base.png"}, {"type": "text", "x": 0.01, "y": 0.00, "text": "Mario Kart Wii - Faraphel", "font_size": 0.04, "color": [100, 100, 100], "font_path": "files/Boot/Strap/CenturyGothicBold.ttf"}, {"type": "text", "x": 0.10, "y": 0.06, "text": "Every track has a score between 1 and 5 stars", "font_size": 0.045, "color": [255, 180, 0], "font_path": "files/Boot/Strap/CenturyGothicBold.ttf"}, @@ -14,8 +14,8 @@ {"type": "text", "x": 0.45, "y": 0.25, "text": "\"Boost\" mean that you will be constantly\nbe accelerating on this track", "font_size": 0.045, "color": [255, 180, 0], "font_path": "files/Boot/Strap/CenturyGothicBold.ttf"}, {"type": "text", "x": 0.45, "y": 0.40, "text": "The track's author is credited while\nthe track presentation", "font_size": 0.045, "color": [255, 180, 0], "font_path": "files/Boot/Strap/CenturyGothicBold.ttf"}, {"type": "text", "x": 0.45, "y": 0.67, "text": "The original track's game if shown\nwith the prefix", "font_size": 0.045, "color": [255, 180, 0], "font_path": "files/Boot/Strap/CenturyGothicBold.ttf"}, - {"type": "text", "x": 0.02, "y": 0.88, "text": "All score are not always correct, you can contribute to", "font_size": 0.04, "color": [128, 128, 128], "font_path": "files/Boot/Strap/CenturyGothicBold.ttf"}, - {"type": "text", "x": 0.02, "y": 0.93, "text": "the mod by giving your opinion on the discord : https://discord.gg/C66cfHBb7S", "font_size": 0.04, "color": [128, 128, 128], "font_path": "files/Boot/Strap/CenturyGothicBold.ttf"} + {"type": "text", "x": 0.02, "y": 0.88, "text": "All score are not always correct, you can contribute to the mod", "font_size": 0.04, "color": [128, 128, 128], "font_path": "files/Boot/Strap/CenturyGothicBold.ttf"}, + {"type": "text", "x": 0.02, "y": 0.93, "text": "by giving your opinion on the discord : https://discord.gg/C66cfHBb7S", "font_size": 0.04, "color": [128, 128, 128], "font_path": "files/Boot/Strap/CenturyGothicBold.ttf"} ] } } diff --git a/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/es.json b/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/es.json index 7311db4..ef039bc 100644 --- a/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/es.json +++ b/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/es.json @@ -2,7 +2,7 @@ "operation": { "img-generate": { "layers": [ - {"type": "color", "color": [0, 0, 0]}, + {"type": "color", "color": [0, 0, 0, 0]}, {"type": "image", "image_path": "files/Boot/Strap/bootscreen-base.png"}, {"type": "text", "x": 0.01, "y": 0.00, "text": "Mario Kart Wii - Faraphel", "font_size": 0.04, "color": [100, 100, 100], "font_path": "files/Boot/Strap/CenturyGothicBold.ttf"}, {"type": "text", "x": 0.10, "y": 0.06, "text": "Cada pista tiene una puntuación entre 1 y 5 estrellas", "font_size": 0.045, "color": [255, 180, 0], "font_path": "files/Boot/Strap/CenturyGothicBold.ttf"}, diff --git a/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/fr.json b/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/fr.json index aaee405..cb67c15 100644 --- a/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/fr.json +++ b/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/fr.json @@ -2,7 +2,7 @@ "operation": { "img-generate": { "layers": [ - {"type": "color", "color": [0, 0, 0]}, + {"type": "color", "color": [0, 0, 0, 0]}, {"type": "image", "image_path": "files/Boot/Strap/bootscreen-base.png"}, {"type": "text", "x": 0.01, "y": 0.00, "text": "Mario Kart Wii - Faraphel", "font_size": 0.04, "color": [100, 100, 100], "font_path": "files/Boot/Strap/CenturyGothicBold.ttf"}, {"type": "text", "x": 0.10, "y": 0.06, "text": "Chaque course possède une note allant de 1 à 5 étoiles", "font_size": 0.045, "color": [255, 180, 0], "font_path": "files/Boot/Strap/CenturyGothicBold.ttf"}, diff --git a/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/ge.json b/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/ge.json index ba6af18..22c5dc5 100644 --- a/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/ge.json +++ b/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/ge.json @@ -2,7 +2,7 @@ "operation": { "img-generate": { "layers": [ - {"type": "color", "color": [0, 0, 0]}, + {"type": "color", "color": [0, 0, 0, 0]}, {"type": "image", "image_path": "files/Boot/Strap/bootscreen-base.png"}, {"type": "text", "x": 0.01, "y": 0.00, "text": "Mario Kart Wii - Faraphel", "font_size": 0.04, "color": [100, 100, 100], "font_path": "files/Boot/Strap/CenturyGothicBold.ttf"}, {"type": "text", "x": 0.10, "y": 0.06, "text": "Jeder track hat eine Punktzahl zwischen 1 und 5 sternen", "font_size": 0.045, "color": [255, 180, 0], "font_path": "files/Boot/Strap/CenturyGothicBold.ttf"}, diff --git a/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/it.json b/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/it.json index 42201e8..5ce0a9d 100644 --- a/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/it.json +++ b/Pack/MKWFaraphel/specific/_PATCH/files/Boot/Strap/it.json @@ -2,7 +2,7 @@ "operation": { "img-generate": { "layers": [ - {"type": "color", "color": [0, 0, 0]}, + {"type": "color", "color": [0, 0, 0, 0]}, {"type": "image", "image_path": "files/Boot/Strap/bootscreen-base.png"}, {"type": "text", "x": 0.01, "y": 0.00, "text": "Mario Kart Wii - Faraphel", "font_size": 0.04, "color": [100, 100, 100], "font_path": "files/Boot/Strap/CenturyGothicBold.ttf"}, {"type": "text", "x": 0.10, "y": 0.06, "text": "Ogni traccia ha un punteggio compreso tra 1 e 5 stelle", "font_size": 0.045, "color": [255, 180, 0], "font_path": "files/Boot/Strap/CenturyGothicBold.ttf"}, diff --git a/source/mkw/Patch/PatchOperation.py b/source/mkw/Patch/PatchOperation.py index 7db6708..b15f98e 100644 --- a/source/mkw/Patch/PatchOperation.py +++ b/source/mkw/Patch/PatchOperation.py @@ -40,7 +40,7 @@ class PatchOperation: self.layers: list["Layer"] = [self.Layer(layer) for layer in layers] def patch(self, patch: "Patch", file_name: str, file_content: IO) -> (str, IO): - image = Image.open(file_content) + image = Image.open(file_content).convert("RGBA") for layer in self.layers: image = layer.patch_image(patch, image) @@ -127,7 +127,7 @@ class PatchOperation: def patch_image(self, patch: "Patch", image: Image.Image): draw = ImageDraw.Draw(image) - draw.rectangle(self.get_bbox(image), self.color) + draw.rectangle(self.get_bbox(image), fill=self.color) return image @@ -151,18 +151,15 @@ class PatchOperation: if not layer_image_path.is_relative_to(patch.path): raise PathOutsidePatch(layer_image_path, patch.path) - layer_image = Image.open( - layer_image_path.resolve() - ).resize( - self.get_bbox_size(image) - ).convert( - "RGBA" - ) + # load the image that will be pasted + layer_image = Image.open(layer_image_path.resolve()) \ + .resize(self.get_bbox_size(image)) \ + .convert("RGBA") - image.paste( + # paste onto the final image the layer with transparency support + image.alpha_composite( layer_image, - box=self.get_bbox(image), - mask=layer_image + dest=self.get_bbox(image)[:2], ) return image