diff --git a/.gitignore b/.gitignore index 0ea0b78..944b734 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ build/ !**/src/test/**/build/ .postgres /db-migration.sql +/thecrew-missions.json ### STS ### .apt_generated diff --git a/flake.nix b/flake.nix index 94cd09c..8d26c04 100644 --- a/flake.nix +++ b/flake.nix @@ -38,6 +38,7 @@ echo "Checking Database Migration" ${pkgs.flyway}/bin/flyway "-url=$MISAEL_DATABASE" -user=misael "-password=$MISAEL_PASSWORD" -locations="filesystem:${misael}/resources/main/db/migration/" -schemas=misael migrate + export THECREW_IMAGES_FOLDER=${thecrew-images} echo "Launching misael" ${jdk}/bin/java -jar ${misael}/misael.jar --spring.datasource.url=$MISAEL_DATABASE --spring.datasource.password=$MISAEL_PASSWORD "$@" ''; @@ -45,10 +46,18 @@ mkdir -p .postgres ${pkgs.podman}/bin/podman run -e POSTGRES_USER=misael -e POSTGRES_PASSWORD=misael-dev -e POSTGRES_DB=misael --volume ./.postgres:/var/lib/postgresql -p 127.0.0.1:5432:5432 postgres:18.4 & > .postgres/postgres.log & ''; + thecrew-images = pkgs.runCommand "thecrew-images" {} '' + mkdir $out + cd $out + export PATH=${pkgs.inkscape}/bin:$PATH + ${lib.getExe pkgs.python3} ${./src/main/resources/static/images/thecrew-make.py}\ + ${./src/main/resources/static/images/thecrew.svg}\ + ${./src/main/resources/static/images/thecrew-modifiers.svg} + ''; in { packages.${system} = { default = self.packages.${system}.misael; - misael = misael; + inherit thecrew-images misael; }; apps.${system} = { @@ -79,6 +88,8 @@ shellHook = '' echo "Starting Gradle daemon ..." gradle + export THECREW_IMAGES_FOLDER=${thecrew-images} + export THECREW_MISSIONS_FILE=$PWD/thecrew-missions.json echo "Gradle daemon started." ''; }; diff --git a/src/main/java/com/bernard/misael/TheCrewConfig.java b/src/main/java/com/bernard/misael/TheCrewConfig.java new file mode 100644 index 0000000..040b5dd --- /dev/null +++ b/src/main/java/com/bernard/misael/TheCrewConfig.java @@ -0,0 +1,16 @@ +package com.bernard.misael; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class ThecrewConfig implements WebMvcConfigurer { + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + + String imgFolder = System.getenv("THECREW_IMAGES_FOLDER"); + registry.addResourceHandler("/thecrew/**") + .addResourceLocations("file://"+imgFolder); + } +} diff --git a/src/main/java/com/bernard/misael/web/TheCrewController.java b/src/main/java/com/bernard/misael/web/TheCrewController.java new file mode 100644 index 0000000..4b27e68 --- /dev/null +++ b/src/main/java/com/bernard/misael/web/TheCrewController.java @@ -0,0 +1,36 @@ +package com.bernard.misael.web; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import org.springframework.core.io.InputStreamResource; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.util.FileCopyUtils; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +@RequestMapping("/thecrew") +public class TheCrewController { + + @GetMapping("/") + public String getTheCrewPage() { + return "thecrew.html"; + } + + @GetMapping("/missions.json") + public ResponseEntity getMissions() { + File missionsFile = new File(System.getenv("THECREW_MISSIONS_FILE")); + try { + String missionsData = FileCopyUtils.copyToString(new FileReader(missionsFile)); + return ResponseEntity.ok() + .header("Content-Type","application/json") + .body(missionsData); + } catch (IOException e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } +} diff --git a/src/main/resources/static/images/thecrew-make.py b/src/main/resources/static/images/thecrew-make.py new file mode 100644 index 0000000..e40969b --- /dev/null +++ b/src/main/resources/static/images/thecrew-make.py @@ -0,0 +1,66 @@ +import xml.etree.ElementTree +import copy +import sys +import subprocess +import pathlib + +thecrewSvgFile = sys.argv[1] +thecrewModifiersSvgFile = sys.argv[2] + +def withShownHidden(origXML,toShow,toHide,recolorize={}): + + outXML = copy.deepcopy(origXML) + + for th in toHide: + node = outXML.find(f".//{{http://www.w3.org/2000/svg}}*[@{{http://www.inkscape.org/namespaces/inkscape}}label='{th}']") + if node is None: + print(f"Could not hide node with label {th} : Not Found") + exit(1) + node.attrib['style'] = "display: none" + for ts in toShow: + node = outXML.find(f".//{{http://www.w3.org/2000/svg}}*[@{{http://www.inkscape.org/namespaces/inkscape}}label='{ts}']") + if node is None: + print(f"Could not show node with label {ts} : Not Found") + exit(1) + nodes = outXML.findall(f".//{{http://www.w3.org/2000/svg}}*[@style]") + for node in nodes: + for rc in recolorize: + node.attrib['style'] = node.attrib['style'].replace(rc,recolorize[rc]) + return outXML + +def inkscapeToPng(fi,fo): + subprocess.run(["inkscape","--export-type","png","--export-dpi","300","--export-filename",fo,fi]) + + + + +# Reading file: +origXML = xml.etree.ElementTree.parse(thecrewSvgFile) + +suits = ["Hearts","Spades","Diamonds","Clubs","Square","Circle","Triangle","Cross"] +suitColors = ["e36a6a","545454","e36a6a","545454","e87caf","0085ca","94c11e","e6b436"] +numbers = ["One","Two","Three","Four","Five","Six","Seven","Eight","Nine"] +modifiers = numbers + ["Omega","OneArrow","TwoArrow","ThreeArrow","FourArrow"] + +for s,sc in zip(suits,suitColors): + for n in numbers: + outFile = f"{n.lower()}-of-{s.lower()}.png" + toShow = [s,n] + toHide = list(set(suits+numbers) - set(toShow)) + out = withShownHidden(origXML,toShow,toHide, recolorize = { + "123456": sc + }) + out.write('card.tmp.svg') + inkscapeToPng('card.tmp.svg',outFile) + +origXML = xml.etree.ElementTree.parse(thecrewModifiersSvgFile) +for m in modifiers: + outFile = f"{m.lower()}.png" + toShow = [m] + toHide = list(set(modifiers) - set(toShow)) + out = withShownHidden(origXML,toShow,toHide) + out.write('card.tmp.svg') + inkscapeToPng('card.tmp.svg',outFile) +pathlib.Path.unlink('card.tmp.svg') +print("Done !") + diff --git a/src/main/resources/static/images/thecrew-modifiers.svg b/src/main/resources/static/images/thecrew-modifiers.svg new file mode 100644 index 0000000..1e41af9 --- /dev/null +++ b/src/main/resources/static/images/thecrew-modifiers.svg @@ -0,0 +1,230 @@ + + + + + + + diff --git a/src/main/resources/static/images/thecrew.svg b/src/main/resources/static/images/thecrew.svg new file mode 100644 index 0000000..2c60b64 --- /dev/null +++ b/src/main/resources/static/images/thecrew.svg @@ -0,0 +1,1173 @@ + + + + + + + + + + + + + + diff --git a/src/main/resources/templates/thecrew.html b/src/main/resources/templates/thecrew.html new file mode 100644 index 0000000..9eaf4ca --- /dev/null +++ b/src/main/resources/templates/thecrew.html @@ -0,0 +1,305 @@ + + + + + + + The Crew + + + +
+
+
+
+
+
+
+
+ +
+
+ + +
+ Sélectionnez les paramètres de base +
+
+
+
+
+
+
    +
    +
    + + + + + +