|
|
|
@@ -1,16 +1,11 @@
|
|
|
|
|
package com.bernard.murder.game;
|
|
|
|
|
|
|
|
|
|
import static com.bernard.murder.ParseUtils.mappingKeys;
|
|
|
|
|
import static com.bernard.murder.ParseUtils.mappingStringKeys;
|
|
|
|
|
import static com.bernard.murder.ParseUtils.parseTimeLength;
|
|
|
|
|
import static com.bernard.murder.ParseUtils.sequenceStream;
|
|
|
|
|
|
|
|
|
|
import static com.bernard.murder.ParseUtils.watch;
|
|
|
|
|
|
|
|
|
|
import static com.bernard.murder.YamlUtils.getMapping;
|
|
|
|
|
import static com.bernard.murder.YamlUtils.isMapping;
|
|
|
|
|
import static com.bernard.murder.YamlUtils.getSequence;
|
|
|
|
|
import static com.bernard.murder.YamlUtils.isSequence;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileWriter;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
@@ -48,13 +43,13 @@ public class GameCreator {
|
|
|
|
|
YamlInput input = Yaml.createYamlInput(toread);
|
|
|
|
|
YamlMapping globalMap = input.readYamlMapping();
|
|
|
|
|
|
|
|
|
|
YamlMapping yjoueurs = getMapping(globalMap.value("joueurs"));
|
|
|
|
|
YamlMapping yjoueurs = globalMap.yamlMapping("joueurs");
|
|
|
|
|
|
|
|
|
|
// Pour pouvoir créer les objets et les espaces personnels
|
|
|
|
|
Set<String> playerNames = mappingKeys(yjoueurs).stream().map(n -> n.toString()).collect(Collectors.toSet());
|
|
|
|
|
Set<String> playerNames = mappingStringKeys(yjoueurs).stream().map(n -> n.toString()).collect(Collectors.toSet());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
YamlMapping yactions = getMapping(globalMap.value("actions"));
|
|
|
|
|
YamlMapping yactions = globalMap.yamlMapping("actions");
|
|
|
|
|
Set<Action> actions = yactions.keys()
|
|
|
|
|
.stream()
|
|
|
|
|
.map(n -> new Action(n.asScalar().value(), parseTimeLength(yactions.string(n))))
|
|
|
|
@@ -62,35 +57,40 @@ public class GameCreator {
|
|
|
|
|
Map<String,Set<Action>> persActions = playerNames.stream()
|
|
|
|
|
.collect(Collectors.toMap(Function.identity(), s -> actions.stream().map(Action::clone).collect(Collectors.toSet())));
|
|
|
|
|
|
|
|
|
|
YamlSequence yinventory = getSequence(globalMap.value("inventaire"));
|
|
|
|
|
YamlSequence yinventory = globalMap.yamlSequence("inventaire");
|
|
|
|
|
|
|
|
|
|
Set<String> objets = StreamSupport.stream(Spliterators.spliteratorUnknownSize(yinventory.iterator(),Spliterator.ORDERED),false)
|
|
|
|
|
.map(n ->n.asScalar().value())
|
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
Map<String,Set<Objet>> persObjets = playerNames.stream()
|
|
|
|
|
.collect(Collectors.toMap(Function.identity(),p -> objets.stream().map(o ->new Objet(String.format(o,p))).collect(Collectors.toSet())));
|
|
|
|
|
|
|
|
|
|
YamlSequence ystatus = getSequence(globalMap.value("status"));
|
|
|
|
|
Map<String,Set<Objet>> persObjets =
|
|
|
|
|
playerNames.stream()
|
|
|
|
|
.collect(Collectors.toMap(
|
|
|
|
|
Function.identity(),
|
|
|
|
|
p -> objets.stream()
|
|
|
|
|
.map(o ->new Objet(String.format(o,p)))
|
|
|
|
|
.collect(Collectors.toSet())
|
|
|
|
|
));
|
|
|
|
|
YamlSequence ystatus = globalMap.yamlSequence("status");
|
|
|
|
|
Set<Status> status = sequenceStream(ystatus).map(n -> new Status(n.asScalar().value())).collect(Collectors.toSet());
|
|
|
|
|
|
|
|
|
|
YamlMapping yespaces = getMapping(globalMap.value("espaces"));
|
|
|
|
|
YamlMapping yespaces = globalMap.yamlMapping("espaces");
|
|
|
|
|
|
|
|
|
|
Map<String, Map<Objet, Integer>> objetsDansEspaces = yespaces.keys().stream().collect(Collectors.toMap(
|
|
|
|
|
n -> n.asScalar().value(),
|
|
|
|
|
n-> parseHiddenObjects(getSequence(yespaces.value(n)))
|
|
|
|
|
n-> parseHiddenObjects(yespaces.yamlSequence(n))
|
|
|
|
|
));
|
|
|
|
|
Set<Piece> espaceObjets = yespaces.keys().stream()
|
|
|
|
|
.map(n -> new Piece(n.asScalar().value(), objetsDansEspaces.get(n.asScalar().value())))
|
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
|
|
|
|
YamlMapping yespacesPersos = getMapping(globalMap.value("espacesPersos"));
|
|
|
|
|
YamlMapping yespacesPersos = globalMap.yamlMapping("espacesPersos");
|
|
|
|
|
|
|
|
|
|
Map<String,Set<Piece>> persespacesPersos = playerNames.stream().collect(Collectors.toMap(
|
|
|
|
|
Function.identity(),
|
|
|
|
|
p -> yespacesPersos.keys().stream()
|
|
|
|
|
.map(e -> new Piece(
|
|
|
|
|
String.format(e.asScalar().value(), p),
|
|
|
|
|
parseHiddenObjects(getSequence(yespacesPersos.value(e)),p)
|
|
|
|
|
parseHiddenObjects(yespacesPersos.yamlSequence(e),p)
|
|
|
|
|
))
|
|
|
|
|
.collect(Collectors.toSet())
|
|
|
|
|
));
|
|
|
|
@@ -99,32 +99,33 @@ public class GameCreator {
|
|
|
|
|
for(YamlNode pn : yjoueurs.keys()) {
|
|
|
|
|
String pname = pn.asScalar().value();
|
|
|
|
|
persActions.get(pname).addAll(
|
|
|
|
|
getMapping(getMapping(yjoueurs.value(pn)).value("actions")).keys()
|
|
|
|
|
yjoueurs.yamlMapping(pn).yamlMapping("actions").keys()
|
|
|
|
|
.stream()
|
|
|
|
|
.map(n -> new Action(n.asScalar().value(), parseTimeLength(getMapping(getMapping(yjoueurs.value(pn)).value("actions")).string(n))))
|
|
|
|
|
.map(n -> new Action(n.asScalar().value(), parseTimeLength(yjoueurs.yamlMapping(pn).yamlMapping("actions").string(n))))
|
|
|
|
|
.collect(Collectors.toSet())
|
|
|
|
|
);
|
|
|
|
|
persObjets.get(pname).addAll(
|
|
|
|
|
StreamSupport.stream(Spliterators.spliteratorUnknownSize(getSequence(getMapping(yjoueurs.value(pn)).value("inventaire")).iterator(),Spliterator.ORDERED),false)
|
|
|
|
|
StreamSupport.stream(Spliterators.spliteratorUnknownSize(yjoueurs.yamlMapping(pn).yamlSequence("inventaire").iterator(),Spliterator.ORDERED),false)
|
|
|
|
|
.map(n -> n.asScalar().value())
|
|
|
|
|
.map(o -> new Objet(o))
|
|
|
|
|
.collect(Collectors.toSet())
|
|
|
|
|
);
|
|
|
|
|
if(isMapping(getMapping(yjoueurs.value(pn)).value("espacePerso")))
|
|
|
|
|
|
|
|
|
|
if(yjoueurs.yamlMapping(pn).value("espacePerso").type()==Node.MAPPING)
|
|
|
|
|
// Plusieurs espaces
|
|
|
|
|
getMapping(getMapping(yjoueurs.value(pn)).value("espacePerso")).keys().forEach(n ->
|
|
|
|
|
yjoueurs.yamlMapping(pn).yamlMapping("espacePerso").keys().forEach(n ->
|
|
|
|
|
persespacesPersos.get(pname)
|
|
|
|
|
.stream()
|
|
|
|
|
.filter(p -> p.getNom().contentEquals(n.asScalar().value()))
|
|
|
|
|
.findAny()
|
|
|
|
|
.orElseGet(() -> new Piece(n.asScalar().value()))
|
|
|
|
|
.insertObjects(parseHiddenObjects(getSequence(getMapping(getMapping(yjoueurs.value(pn)).value("espacePerso")).value(n))))
|
|
|
|
|
.insertObjects(parseHiddenObjects(yjoueurs.yamlMapping(pn).yamlMapping("espacePerso").yamlSequence(n)))
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
else
|
|
|
|
|
((persespacesPersos.get(pname).isEmpty())?
|
|
|
|
|
Stream.of(new Piece(String.format("Espace de %s",pname))):persespacesPersos.get(pname).stream())
|
|
|
|
|
.forEach(p -> p.insertObjects(parseHiddenObjects(getSequence(getMapping(yjoueurs.value(pn)).value("espacePerso")))));
|
|
|
|
|
.forEach(p -> p.insertObjects(parseHiddenObjects(yjoueurs.yamlMapping(pn).yamlSequence("espacePerso"))));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@@ -137,8 +138,8 @@ public class GameCreator {
|
|
|
|
|
persActions.get(p),
|
|
|
|
|
status.stream().filter(st -> sequenceStream(ystatus)
|
|
|
|
|
.filter(n -> n instanceof YamlMapping)
|
|
|
|
|
.filter(n -> getMapping(n).string(st.getName())!=null)
|
|
|
|
|
.filter(n -> getMapping(getMapping(n).value(st.getName())).string("onStart").contentEquals("true"))
|
|
|
|
|
.filter(n -> n.asMapping().string(st.getName())!=null)
|
|
|
|
|
.filter(n -> (n.asMapping().yamlMapping(st.getName())).string("onStart").contentEquals("true"))
|
|
|
|
|
.findAny().isPresent())
|
|
|
|
|
.collect(Collectors.toSet()),
|
|
|
|
|
persespacesPersos.get(p)
|
|
|
|
@@ -203,50 +204,50 @@ public class GameCreator {
|
|
|
|
|
YamlInput input = Yaml.createYamlInput(f);
|
|
|
|
|
YamlMapping globalMap = input.readYamlMapping();
|
|
|
|
|
|
|
|
|
|
YamlSequence ystatus = getSequence(globalMap.value("status"));
|
|
|
|
|
YamlSequence ystatus = globalMap.yamlSequence("status");
|
|
|
|
|
Set<Status> status = sequenceStream(ystatus).map(n -> new Status(n.asScalar().value())).collect(Collectors.toSet());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
YamlMapping yespaces = getMapping(globalMap.value("pieces"));
|
|
|
|
|
YamlMapping yespaces = globalMap.yamlMapping("pieces");
|
|
|
|
|
Map<String, Map<Objet, Integer>> objetsDansEspaces = yespaces.keys().stream().collect(Collectors.toMap(
|
|
|
|
|
n -> watch(watch(n).asScalar().value()),
|
|
|
|
|
n-> parseHiddenObjects(getSequence(yespaces.value(n)))
|
|
|
|
|
n-> parseHiddenObjects(yespaces.yamlSequence(n))
|
|
|
|
|
));
|
|
|
|
|
Set<Piece> espaceObjets = yespaces.keys().stream()
|
|
|
|
|
.map(n -> new Piece(n.asScalar().value(), objetsDansEspaces.get(n.asScalar().value())))
|
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
YamlMapping yjoueurs = getMapping(globalMap.value("personnages"));
|
|
|
|
|
YamlMapping yjoueurs = globalMap.yamlMapping("personnages");
|
|
|
|
|
|
|
|
|
|
Set<Personnage> personnages = new HashSet<Personnage>();
|
|
|
|
|
for(YamlNode pn : yjoueurs.keys()) {
|
|
|
|
|
String pname = pn.asScalar().value();
|
|
|
|
|
|
|
|
|
|
Set<Action> actions = getMapping(getMapping(yjoueurs.value(pn)).value("actions")).keys()
|
|
|
|
|
Set<Action> actions = yjoueurs.yamlMapping(pn).yamlMapping("actions").keys()
|
|
|
|
|
.stream()
|
|
|
|
|
.map(n -> new Action(n.asScalar().value(), Long.parseLong(getMapping(getMapping(getMapping(yjoueurs.value(pn)).value("actions")).value(n)).string("basetime")),
|
|
|
|
|
Long.parseLong(getMapping(getMapping(getMapping(yjoueurs.value(pn)).value("actions")).value(n)).string("triggerTime"))))
|
|
|
|
|
.map(n -> new Action(n.asScalar().value(), Long.parseLong(yjoueurs.yamlMapping(pn).yamlMapping("actions").yamlMapping(n).string("basetime")),
|
|
|
|
|
Long.parseLong(yjoueurs.yamlMapping(pn).yamlMapping("actions").yamlMapping(n).string("triggerTime"))))
|
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
|
|
|
|
Set<Objet> inventaire =
|
|
|
|
|
StreamSupport.stream(Spliterators.spliteratorUnknownSize(getSequence(getMapping(yjoueurs.value(pn)).value("inventaire")).iterator(),Spliterator.ORDERED),false)
|
|
|
|
|
StreamSupport.stream(Spliterators.spliteratorUnknownSize(yjoueurs.yamlMapping(pn).yamlSequence("inventaire").iterator(),Spliterator.ORDERED),false)
|
|
|
|
|
.map(n ->n.asScalar().value())
|
|
|
|
|
.map(o ->new Objet(o))
|
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
|
|
|
|
Set<Piece> espacesPerso = getMapping(getMapping(yjoueurs.value(pn)).value("espacePerso")).keys().stream().map(n ->
|
|
|
|
|
new Piece(n.asScalar().value(), parseHiddenObjects(getSequence(getMapping(getMapping(yjoueurs.value(pn)).value("espacePerso")).value(n))))).collect(Collectors.toSet());
|
|
|
|
|
Set<Piece> espacesPerso = yjoueurs.yamlMapping(pn).yamlMapping("espacePerso").keys().stream().map(n ->
|
|
|
|
|
new Piece(n.asScalar().value(), parseHiddenObjects(yjoueurs.yamlMapping(pn).yamlMapping("espacePerso").yamlSequence(n)))).collect(Collectors.toSet());
|
|
|
|
|
|
|
|
|
|
Set<Status> persoStatus = status.stream().filter(
|
|
|
|
|
s -> !isSequence(getMapping(yjoueurs.value(pn)).value("status"))?false:getSequence(getMapping(yjoueurs.value(pn)).value("status")).values().stream().anyMatch(n -> n.asScalar().value().equals(s.getName()))
|
|
|
|
|
s -> (yjoueurs.yamlMapping(pn).value("status").type()!=Node.SEQUENCE)?false:yjoueurs.yamlMapping(pn).yamlSequence("status").values().stream().anyMatch(n -> n.asScalar().value().equals(s.getName()))
|
|
|
|
|
).collect(Collectors.toSet());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
personnages.add(new Personnage(pname, inventaire, actions, persoStatus, espacesPerso));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
YamlMapping minelsMap = getMapping(globalMap.value("minels"));
|
|
|
|
|
YamlMapping minelsMap = globalMap.yamlMapping("minels");
|
|
|
|
|
|
|
|
|
|
return new QuicksavedPartie(new Partie(personnages, status, espaceObjets),minelsMap);
|
|
|
|
|
|
|
|
|
|