Ressource loader fonctionnel

This commit is contained in:
Paul Gross 2020-05-06 17:49:55 +02:00
parent 3e0d0e7efb
commit 14bcbe0347
68 changed files with 86 additions and 10 deletions

BIN
ressources/cartes/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 560 KiB

BIN
ressources/cartes/10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 541 KiB

BIN
ressources/cartes/11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 564 KiB

BIN
ressources/cartes/12.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 629 KiB

BIN
ressources/cartes/13.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 643 KiB

BIN
ressources/cartes/14.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 546 KiB

BIN
ressources/cartes/15.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 562 KiB

BIN
ressources/cartes/16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 555 KiB

BIN
ressources/cartes/17.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 598 KiB

BIN
ressources/cartes/18.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 KiB

BIN
ressources/cartes/19.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 KiB

BIN
ressources/cartes/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 549 KiB

BIN
ressources/cartes/20.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 KiB

BIN
ressources/cartes/21.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 595 KiB

BIN
ressources/cartes/22.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 570 KiB

BIN
ressources/cartes/23.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 575 KiB

BIN
ressources/cartes/24.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 578 KiB

BIN
ressources/cartes/25.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 583 KiB

BIN
ressources/cartes/26.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 638 KiB

BIN
ressources/cartes/27.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 592 KiB

BIN
ressources/cartes/28.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 645 KiB

BIN
ressources/cartes/29.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 KiB

BIN
ressources/cartes/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 537 KiB

BIN
ressources/cartes/30.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 577 KiB

BIN
ressources/cartes/31.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 577 KiB

BIN
ressources/cartes/32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 591 KiB

BIN
ressources/cartes/33.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 KiB

BIN
ressources/cartes/34.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 KiB

BIN
ressources/cartes/35.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 587 KiB

BIN
ressources/cartes/36.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 KiB

BIN
ressources/cartes/37.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 KiB

BIN
ressources/cartes/38.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 KiB

BIN
ressources/cartes/39.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 KiB

BIN
ressources/cartes/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 564 KiB

BIN
ressources/cartes/40.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 KiB

BIN
ressources/cartes/41.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 KiB

BIN
ressources/cartes/42.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 658 KiB

BIN
ressources/cartes/43.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 586 KiB

BIN
ressources/cartes/44.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 KiB

BIN
ressources/cartes/45.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 652 KiB

BIN
ressources/cartes/46.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 KiB

BIN
ressources/cartes/47.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 KiB

BIN
ressources/cartes/48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 KiB

BIN
ressources/cartes/49.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 593 KiB

BIN
ressources/cartes/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 556 KiB

BIN
ressources/cartes/50.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 KiB

BIN
ressources/cartes/51.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 653 KiB

BIN
ressources/cartes/52.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 577 KiB

BIN
ressources/cartes/53.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 629 KiB

BIN
ressources/cartes/54.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 KiB

BIN
ressources/cartes/55.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 632 KiB

BIN
ressources/cartes/56.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 645 KiB

BIN
ressources/cartes/57.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 586 KiB

BIN
ressources/cartes/58.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

BIN
ressources/cartes/59.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

BIN
ressources/cartes/6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 561 KiB

BIN
ressources/cartes/60.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

BIN
ressources/cartes/61.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

BIN
ressources/cartes/62.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 661 KiB

BIN
ressources/cartes/63.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 619 KiB

BIN
ressources/cartes/64.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 671 KiB

BIN
ressources/cartes/65.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 649 KiB

BIN
ressources/cartes/66.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 635 KiB

BIN
ressources/cartes/67.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 611 KiB

BIN
ressources/cartes/7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 560 KiB

BIN
ressources/cartes/8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 554 KiB

BIN
ressources/cartes/9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 541 KiB

View File

@ -1,17 +1,46 @@
package database;
import java.awt.Image;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import carte.Carte;
import carte.CartePiochable;
import personnage.CartePersonnage;
public class RessourceLoader {
public static final String CARTES_PERSONNAGE = "cp";
public static final String CARTES_LUMIERE = "cl";
public static final String CARTES_TENEBRE = "ct";
public static final String CARTES_VISION = "cv";
public static final String DOS_PERSONNAGE = "dp";
public static final String DOS_LUMIERE = "dl";
public static final String DOS_TENEBRE = "dt";
public static final String DOS_VISION = "dv";
private final int ID_DOS_PERSONNAGE = 60;
private final int ID_DOS_LUMIERE = 58;
private final int ID_DOS_TENEBRE= 59;
private final int ID_DOS_VISION= 61;
private Map<String, Map<Carte, Image>> ressourcesCartes;
private Map<String, Image> ressourcesDosCartes;
public RessourceLoader() {
this.ressourcesCartes = new HashMap<String, Map<Carte,Image>>();
this.ressourcesDosCartes = new HashMap<String, Image>();
}
private static Map<Integer, Carte> loadCards() throws ClassNotFoundException, IOException{
Table t = new Table();
@ -31,9 +60,9 @@ public class RessourceLoader {
return cartes;
}
private static Map<Integer, CartePiochable> getMapType(CartePiochable.Type t, Map<Integer, Carte> cartes){
private static Map<Integer, Carte> getMapType(CartePiochable.Type t, Map<Integer, Carte> cartes){
Map<Integer, CartePiochable> cartesType = new HashMap<Integer, CartePiochable>();
Map<Integer, Carte> cartesType = new HashMap<Integer, Carte>();
for(Integer i: cartes.keySet()) {
@ -51,9 +80,9 @@ public class RessourceLoader {
return cartesType;
}
private static Map<Integer, CartePersonnage> getMapPersonnage(Map<Integer, Carte> cartes){
private static Map<Integer, Carte> getMapPersonnage(Map<Integer, Carte> cartes){
Map<Integer, CartePersonnage> cartesPersonnage = new HashMap<Integer, CartePersonnage>();
Map<Integer, Carte> cartesPersonnage = new HashMap<Integer, Carte>();
for(Integer i: cartes.keySet()) {
@ -67,23 +96,70 @@ public class RessourceLoader {
return cartesPersonnage;
}
public static Object deserialize(byte[] data) throws IOException, ClassNotFoundException {
private static Object deserialize(byte[] data) throws IOException, ClassNotFoundException {
ByteArrayInputStream in = new ByteArrayInputStream(data);
ObjectInputStream is = new ObjectInputStream(in);
return is.readObject();
}
public static void main(String[] args) {
private static Image loadImage(int id) throws IOException {
String name = ""+id+".png";
String url = "ressources/cartes/"+name;
System.out.println(url);
Image picture = ImageIO.read(new File(url));
return picture;
}
private static Map<Carte, Image> getMapImageCarte(Map<Integer, Carte> cartes) throws IOException{
Map<Carte, Image> mapCarteImage = new HashMap<Carte, Image>();
for(Integer i : cartes.keySet()) {
Carte c = cartes.get(i);
Image img = loadImage(i);
mapCarteImage.put(c,img);
}
return mapCarteImage;
}
public void loadRessources() {
try {
Map<Integer, Carte> cartes = loadCards();
System.out.println(cartes);
System.out.println(getMapType(CartePiochable.Type.TENEBRE, cartes));
} catch (ClassNotFoundException | IOException e) {
Map<Integer, Carte> mapT = getMapType(CartePiochable.Type.TENEBRE, cartes);
Map<Integer, Carte> mapL = getMapType(CartePiochable.Type.LUMIERE, cartes);
Map<Integer, Carte> mapV = getMapType(CartePiochable.Type.VISION, cartes);
Map<Integer, Carte> mapP = getMapPersonnage(cartes);
Map<Carte, Image> mapIT = getMapImageCarte(mapT);
Map<Carte, Image> mapIL = getMapImageCarte(mapT);
Map<Carte, Image> mapIV = getMapImageCarte(mapT);
Map<Carte, Image> mapIP = getMapImageCarte(mapT);
this.ressourcesCartes.put(CARTES_TENEBRE, mapIT);
this.ressourcesCartes.put(CARTES_LUMIERE, mapIL);
this.ressourcesCartes.put(CARTES_LUMIERE, mapIV);
this.ressourcesCartes.put(CARTES_LUMIERE, mapIP);
this.ressourcesDosCartes.put(DOS_TENEBRE, loadImage(ID_DOS_TENEBRE));
this.ressourcesDosCartes.put(DOS_LUMIERE, loadImage(ID_DOS_LUMIERE));
this.ressourcesDosCartes.put(DOS_VISION, loadImage(ID_DOS_VISION));
this.ressourcesDosCartes.put(DOS_PERSONNAGE, loadImage(ID_DOS_PERSONNAGE));
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
RessourceLoader rl = new RessourceLoader();
rl.loadRessources();
}
}