Skip to content
This repository was archived by the owner on Nov 21, 2023. It is now read-only.

Commit

Permalink
adaptation for build jar
Browse files Browse the repository at this point in the history
  • Loading branch information
naulan-chrzaszcz committed Jun 26, 2022
1 parent 0ccabc1 commit 62288f7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
37 changes: 33 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.10'
id 'org.openjfx.javafxplugin' version '0.0.13'
id 'org.beryx.jlink' version '2.24.1'
}

Expand Down Expand Up @@ -29,8 +29,8 @@ application {
}

javafx {
version = '11.0.2'
modules = ['javafx.controls', 'javafx.fxml']
version = '18.0.1'
modules = ['javafx.controls', 'javafx.fxml', 'javafx.graphics']
}

dependencies {
Expand All @@ -39,6 +39,7 @@ dependencies {

testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")

}

test {
Expand All @@ -55,4 +56,32 @@ jlink {

jlinkZip {
group = 'distribution'
}
}

jar {
manifest {
attributes(
'Main-Class': 'fr.sae.terraria.Terraria',
)
}
}

task fatJar(type: Jar) {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE

manifest.from jar.manifest
classifier = 'all'

from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
} {
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
}
with jar

artifacts {
archives fatJar
}
}
5 changes: 3 additions & 2 deletions src/main/java/fr/sae/terraria/modele/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import java.io.BufferedInputStream;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -65,7 +66,7 @@ public Environment(double scaleMultiplicatorWidth, double scaleMultiplicatorHeig
this.heightTile = (int) (scaleMultiplicatorHeight * TileMaps.TILE_DEFAULT_SIZE);

this.tileMaps = new TileMaps();
this.tileMaps.load(Terraria.SRC_PATH + "maps/map_0.json");
this.tileMaps.load( "maps/map_0.json");

this.clock = new Clock();
this.previousDays = -1;
Expand Down Expand Up @@ -170,7 +171,7 @@ public static Clip playSound(String path, boolean loop)
Clip clip = null;
try {
clip = AudioSystem.getClip();
AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File(Terraria.SRC_PATH + path).toURI().toURL());
AudioInputStream inputStream = AudioSystem.getAudioInputStream(new BufferedInputStream(Terraria.class.getResourceAsStream(path)));
clip.open(inputStream);
} catch (Exception e) { e.printStackTrace(); }

Expand Down
18 changes: 12 additions & 6 deletions src/main/java/fr/sae/terraria/modele/TileMaps.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package fr.sae.terraria.modele;

import com.google.gson.stream.JsonReader;
import fr.sae.terraria.Terraria;

import java.io.FileReader;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Objects;


/**
Expand Down Expand Up @@ -38,8 +43,9 @@ public void load(final String path)
int i = 0;
int j = 0;

try (FileReader fileReader = new FileReader(path);
JsonReader jsonReader = new JsonReader(fileReader))
InputStream test = Terraria.class.getResourceAsStream(path);
Reader testR = new InputStreamReader(test);
try (JsonReader jsonReader = new JsonReader(testR))
{
jsonReader.beginObject();
// Déduit la taille de la carte.
Expand All @@ -61,9 +67,9 @@ public void load(final String path)
jsonReader.endObject();
} catch (Exception e) { e.printStackTrace(); }


try (FileReader fileReader = new FileReader(path);
JsonReader jsonReader = new JsonReader(fileReader))
test = Terraria.class.getResourceAsStream(path);
testR = new InputStreamReader(test);
try (JsonReader jsonReader = new JsonReader(testR))
{
this.maps = new int[this.h][this.w];
// Ecrit la carte dans la mémoire.
Expand Down

0 comments on commit 62288f7

Please sign in to comment.