Added link with website and tampermonkey script

This commit is contained in:
2024-11-01 23:23:15 +01:00
parent fa7d0362c7
commit 0686ab99c5
8 changed files with 182 additions and 53 deletions
@@ -1,19 +1,36 @@
package com.bernard.greposimu;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.bernard.greposimu.model.game.GameConfig;
import com.bernard.greposimu.model.game.GrepoYaml;
import com.bernard.greposimu.model.simulator.objective.TownObjective;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature;
@SpringBootApplication
public class GrepoSimuApplication {
public static GameConfig GREPOLIS_GC;
public static Map<String, TownObjective> OBJECTIVES;
public static void main(String[] args) throws IOException {
GREPOLIS_GC = GrepoSimu.makeGameData();
File objectiveFile = new File("/home/mysaa/Documents/Projets/eclipse-workspace/GrepoSimu/src/test/resources/objectives.yml");
ObjectMapper om = new ObjectMapper(new YAMLFactory().disable(Feature.WRITE_DOC_START_MARKER));
om.registerModule(new GrepoYaml(GREPOLIS_GC));
JavaType objType = om.getTypeFactory().constructParametricType(Map.class, String.class,TownObjective.class);
OBJECTIVES = om.readValue(objectiveFile, objType);
SpringApplication.run(GrepoSimuApplication.class, args);
}
@@ -0,0 +1,67 @@
package com.bernard.greposimu.controller;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bernard.greposimu.GrepoSimuApplication;
import com.bernard.greposimu.model.game.GameConfig;
import com.bernard.greposimu.model.simulator.Ville;
import com.bernard.greposimu.model.simulator.command.Command;
import com.bernard.greposimu.model.simulator.SimulatorData;
import com.bernard.greposimu.model.simulator.objective.TownObjective;
import com.bernard.greposimu.source.JSONSourcer;
@Controller
public class SchedulerController {
Map<UUID,SimulatorData> registered = new HashMap<>();
@CrossOrigin
@PostMapping(value = "/registerScheduler", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.TEXT_PLAIN_VALUE)
//@GetMapping(value = "/registerScheduler")
public @ResponseBody String register(Model model,@RequestBody String data) {
//System.out.println(data.toString());
GameConfig gc = GrepoSimuApplication.GREPOLIS_GC;
SimulatorData sd = JSONSourcer.makeSimulationData(data.toString(),gc);
UUID uuid = UUID.randomUUID();
registered.put(uuid, sd);
return uuid.toString();
}
@GetMapping(value = "/scheduler/{uuid}")
public String simulator(Model model, @PathVariable("uuid") String uuidStr) {
UUID uuid = UUID.fromString(uuidStr);
GameConfig gc = GrepoSimuApplication.GREPOLIS_GC;
SimulatorData sd = registered.get(uuid);
TownObjective defObjective = GrepoSimuApplication.OBJECTIVES.get("defTerTown");
defObjective.setGc(gc);
StringBuilder out = new StringBuilder();
for(Ville v : sd.getVilles().values()) {
out.append("<h3>==== Ville "+v.getNom()+" ====</h3>\n");
out.append(defObjective.getDifferences(v).stream().map(Command::toString).sorted().collect(Collectors.joining("<br/>\n")));
}
model.addAttribute("content",out.toString());
return "debug";
}
}
@@ -48,7 +48,6 @@ public class SimulatorController {
return "simulator";
}
@PostMapping("/simulate")
@GetMapping("/simulate")
public String simulate(@ModelAttribute SimulatorParams params, Model model) throws IOException {
if(params == null)
@@ -123,6 +123,10 @@ public class TownObjective {
return god;
}
public void setGc(GameConfig gc) {
this.gc = gc;
}
@Override
public String toString() {
return "TownObjective [gc=" + gc + ", buildings=" + buildings + ", unitsProportions=" + unitsProportions
@@ -61,10 +61,10 @@ public class JSONSourcer {
return new UnitResources(res.wood, res.stone, res.iron,god,res.favor);
}
public static final SimulatorData makeSimulationData(File file, GameConfig gc) {
public static final SimulatorData makeSimulationData(String json, GameConfig gc) {
ObjectMapper om = new ObjectMapper();
try {
SourcedData sd = om.readValue(file, SourcedData.class);
SourcedData sd = om.readValue(json, SourcedData.class);
Map<String,Ville> villes = new HashMap<String, Ville>();
for(String idS : sd.towns.keySet()) {