Added link with website and tampermonkey script
This commit is contained in:
parent
fa7d0362c7
commit
0686ab99c5
@ -1,19 +1,36 @@
|
|||||||
package com.bernard.greposimu;
|
package com.bernard.greposimu;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
import com.bernard.greposimu.model.game.GameConfig;
|
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
|
@SpringBootApplication
|
||||||
public class GrepoSimuApplication {
|
public class GrepoSimuApplication {
|
||||||
|
|
||||||
public static GameConfig GREPOLIS_GC;
|
public static GameConfig GREPOLIS_GC;
|
||||||
|
public static Map<String, TownObjective> OBJECTIVES;
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
GREPOLIS_GC = GrepoSimu.makeGameData();
|
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);
|
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";
|
return "simulator";
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/simulate")
|
|
||||||
@GetMapping("/simulate")
|
@GetMapping("/simulate")
|
||||||
public String simulate(@ModelAttribute SimulatorParams params, Model model) throws IOException {
|
public String simulate(@ModelAttribute SimulatorParams params, Model model) throws IOException {
|
||||||
if(params == null)
|
if(params == null)
|
||||||
|
|||||||
@ -123,6 +123,10 @@ public class TownObjective {
|
|||||||
return god;
|
return god;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setGc(GameConfig gc) {
|
||||||
|
this.gc = gc;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "TownObjective [gc=" + gc + ", buildings=" + buildings + ", unitsProportions=" + unitsProportions
|
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);
|
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();
|
ObjectMapper om = new ObjectMapper();
|
||||||
try {
|
try {
|
||||||
SourcedData sd = om.readValue(file, SourcedData.class);
|
SourcedData sd = om.readValue(json, SourcedData.class);
|
||||||
|
|
||||||
Map<String,Ville> villes = new HashMap<String, Ville>();
|
Map<String,Ville> villes = new HashMap<String, Ville>();
|
||||||
for(String idS : sd.towns.keySet()) {
|
for(String idS : sd.towns.keySet()) {
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
spring.application.name=GrepoSimu
|
spring.application.name=GrepoSimu
|
||||||
spring.devtools.restart.pollInterval=10s
|
spring.devtools.restart.pollInterval=10s
|
||||||
spring.mvc.favicon.enabled=false
|
spring.mvc.favicon.enabled=false
|
||||||
|
spring.web.resources.static-locations=classpath:/static/
|
||||||
@ -1,3 +1,17 @@
|
|||||||
|
// ==UserScript==
|
||||||
|
// @name GrepoSimu
|
||||||
|
// @namespace greposimu
|
||||||
|
// @version 1.0
|
||||||
|
// @author Mysaa Java
|
||||||
|
// @homepage https://greposimu.bernard.com.de
|
||||||
|
// @updateURL https://greposimu.bernard.com.de/userscript.js
|
||||||
|
// @downloadURL https://greposimu.bernard.com.de/userscript.js
|
||||||
|
// @description This script sends information on the town to greposimu
|
||||||
|
// @include https://*.grepolis.com/game/*
|
||||||
|
// @exclude view-source://*
|
||||||
|
// @icon https://greposimu.bernard.com.de/favicon.ico
|
||||||
|
// ==/UserScript==
|
||||||
|
|
||||||
function downloadObjectAsJson(exportObj, exportName){
|
function downloadObjectAsJson(exportObj, exportName){
|
||||||
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj,null,2));
|
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj,null,2));
|
||||||
var downloadAnchorNode = document.createElement('a');
|
var downloadAnchorNode = document.createElement('a');
|
||||||
@ -43,16 +57,16 @@ function makeObject() {
|
|||||||
|
|
||||||
orderz = ITowns.towns[townid].buildingOrders()
|
orderz = ITowns.towns[townid].buildingOrders()
|
||||||
out[townid].buildingOrders = []
|
out[townid].buildingOrders = []
|
||||||
for(var i = 0; i<orderz.length;i++) {
|
for(var i = 0; i<orderz.length;i++) {
|
||||||
order = orderz.models[i].attributes
|
order = orderz.models[i].attributes
|
||||||
out[townid].buildingOrders.push({
|
out[townid].buildingOrders.push({
|
||||||
buildingTime: order.building_time,
|
buildingTime: order.building_time,
|
||||||
building: order.building_type,
|
building: order.building_type,
|
||||||
beginTime: order.created_at,
|
beginTime: order.created_at,
|
||||||
tearingDown: order.tear_down,
|
tearingDown: order.tear_down,
|
||||||
endTime: order.to_be_completed_at,
|
endTime: order.to_be_completed_at,
|
||||||
refund: order.cancel_refund,
|
refund: order.cancel_refund,
|
||||||
cost: {wood: order.wood, stone: order.stone, iron: order.iron}
|
cost: {wood: order.wood, stone: order.stone, iron: order.iron}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
recruitments = ITowns.all_remaining_unit_orders.fragments[townid]
|
recruitments = ITowns.all_remaining_unit_orders.fragments[townid]
|
||||||
@ -60,14 +74,14 @@ function makeObject() {
|
|||||||
for(var i = 0; i<recruitments.models.length; i++) {
|
for(var i = 0; i<recruitments.models.length; i++) {
|
||||||
order = recruitments.models[i].attributes
|
order = recruitments.models[i].attributes
|
||||||
out[townid].recruitingOrders.push({
|
out[townid].recruitingOrders.push({
|
||||||
count: order.count,
|
count: order.count,
|
||||||
beginTime: order.created_at,
|
beginTime: order.created_at,
|
||||||
kind: order.kind,
|
kind: order.kind,
|
||||||
done: order.parts_done,
|
done: order.parts_done,
|
||||||
refund: order.refund_for_single_unit,
|
refund: order.refund_for_single_unit,
|
||||||
endTime: order.to_be_completed_at,
|
endTime: order.to_be_completed_at,
|
||||||
unit: order.unit_type,
|
unit: order.unit_type,
|
||||||
cost: {wood: order.wood, stone: order.stone, iron: order.iron, favor: order.favor}
|
cost: {wood: order.wood, stone: order.stone, iron: order.iron, favor: order.favor}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,9 +90,9 @@ function makeObject() {
|
|||||||
for(var i = 0; i<castedPowers.models.length; i++) {
|
for(var i = 0; i<castedPowers.models.length; i++) {
|
||||||
order = castedPowers.models[i].attributes
|
order = castedPowers.models[i].attributes
|
||||||
out[townid].castedPowers.push({
|
out[townid].castedPowers.push({
|
||||||
configuration: order.configuration,
|
configuration: order.configuration,
|
||||||
endTime: order.to_be_completed_at,
|
endTime: order.to_be_completed_at,
|
||||||
extended: order.extended,
|
extended: order.extended,
|
||||||
level: order.level,
|
level: order.level,
|
||||||
originPlayer: order.origin_player_id,
|
originPlayer: order.origin_player_id,
|
||||||
power: order.power_id
|
power: order.power_id
|
||||||
@ -91,7 +105,7 @@ function makeObject() {
|
|||||||
order = researches.models[i].attributes
|
order = researches.models[i].attributes
|
||||||
out[townid].researchOrders.push({
|
out[townid].researchOrders.push({
|
||||||
research: order.research_type,
|
research: order.research_type,
|
||||||
beginTime: order.created_at,
|
beginTime: order.created_at,
|
||||||
endTime: order.to_be_completed_at,
|
endTime: order.to_be_completed_at,
|
||||||
refund: order.cancel_refund
|
refund: order.cancel_refund
|
||||||
})
|
})
|
||||||
@ -101,7 +115,7 @@ function makeObject() {
|
|||||||
militia = MM.getModels().Militia
|
militia = MM.getModels().Militia
|
||||||
if(townid in militia){
|
if(townid in militia){
|
||||||
out[townid].militia = {
|
out[townid].militia = {
|
||||||
start : militia[townid].attributes.started_at,
|
start : militia[townid].attributes.started_at,
|
||||||
end: militia[townid].attributes.finished_at
|
end: militia[townid].attributes.finished_at
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -120,39 +134,39 @@ function makeObject() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
mvts = MM.getModels().MovementsUnits
|
mvts = MM.getModels().MovementsUnits
|
||||||
outMvts = []
|
outMvts = []
|
||||||
for (var i in mvts) {
|
for (var i in mvts) {
|
||||||
mvt = mvts[i].attributes
|
mvt = mvts[i].attributes
|
||||||
outMvts.push({
|
outMvts.push({
|
||||||
arrival: mvt.arrival_at,
|
arrival: mvt.arrival_at,
|
||||||
cancelableUntil: mvt.cancelable_until,
|
cancelableUntil: mvt.cancelable_until,
|
||||||
invisibleUntil: mvt.cap_of_invisibility_effective_until,
|
invisibleUntil: mvt.cap_of_invisibility_effective_until,
|
||||||
destIsAttackSpot: mvt.destination_is_attack_spot,
|
destIsAttackSpot: mvt.destination_is_attack_spot,
|
||||||
origIsAttackSpot: mvt.origin_is_attack_spot,
|
origIsAttackSpot: mvt.origin_is_attack_spot,
|
||||||
homeId: mvt.home_town_id ,
|
homeId: mvt.home_town_id ,
|
||||||
player: mvt.player_id,
|
player: mvt.player_id,
|
||||||
start: mvt.started_at,
|
start: mvt.started_at,
|
||||||
targetId: mvt.target_town_id,
|
targetId: mvt.target_town_id,
|
||||||
type: mvt.type,
|
type: mvt.type,
|
||||||
})
|
})
|
||||||
trdz = MM.getModels().Trade
|
}
|
||||||
outTrd = []
|
trdz = MM.getModels().Trade
|
||||||
for (var i in trdz) {
|
outTrd = []
|
||||||
trd = trdz[i].attributes
|
for (var i in trdz) {
|
||||||
outTrd.push({
|
trd = trdz[i].attributes
|
||||||
start: trd.started_at,
|
outTrd.push({
|
||||||
arrival: trd.arrival_at,
|
start: trd.started_at,
|
||||||
dest: trd.destination_town_id,
|
arrival: trd.arrival_at,
|
||||||
destType: trd.destination_town_type,
|
dest: trd.destination_town_id,
|
||||||
gold: trd.gold,
|
destType: trd.destination_town_type,
|
||||||
stone: trd.stone,
|
gold: trd.gold,
|
||||||
wood: trd.wood,
|
stone: trd.stone,
|
||||||
iron: trd.iron,
|
wood: trd.wood,
|
||||||
orig: trd.origin_town_id,
|
iron: trd.iron,
|
||||||
origType: trd.origin_town_type,
|
orig: trd.origin_town_id,
|
||||||
exchange: trd.in_exchange
|
origType: trd.origin_town_type,
|
||||||
})
|
exchange: trd.in_exchange
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
fav = MM.getModels().PlayerGods[Object.keys(MM.getModels().PlayerGods)[0]].attributes
|
fav = MM.getModels().PlayerGods[Object.keys(MM.getModels().PlayerGods)[0]].attributes
|
||||||
outFav = {
|
outFav = {
|
||||||
@ -172,12 +186,32 @@ function makeObject() {
|
|||||||
outUts.push({
|
outUts.push({
|
||||||
orig: utz[i].getOriginTownId(),
|
orig: utz[i].getOriginTownId(),
|
||||||
curr: utz[i].getCurrentTownId(),
|
curr: utz[i].getCurrentTownId(),
|
||||||
units: utz[i].getUnits(),
|
units: utz[i].getUnits(),
|
||||||
sameIsland: utz[i].isSameIsland()
|
sameIsland: utz[i].isSameIsland()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return {towns: out,celebrations: outCele, movements: outMvts, trades: outTrd, favors: outFav, units: outUts}
|
return {towns: out,celebrations: outCele, movements: outMvts, trades: outTrd, favors: outFav, units: outUts}
|
||||||
}
|
}
|
||||||
downloadObjectAsJson(makeObject(),"greposimu")
|
|
||||||
|
|
||||||
|
function greposimu() {
|
||||||
|
GREPOSIMURL="http://localhost:8080"
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
crossDomain: true,
|
||||||
|
contentType : "application/json; charset=utf-8",
|
||||||
|
data: JSON.stringify(makeObject()),
|
||||||
|
datatype : "application/json",
|
||||||
|
url: GREPOSIMURL+'/registerScheduler',
|
||||||
|
success: function(uuid){
|
||||||
|
window.open(GREPOSIMURL+'/scheduler/'+uuid, '_blank').focus();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function doc_keyUp(e) {
|
||||||
|
console.log("Keyup de greposimu")
|
||||||
|
if (e.keyCode == 79)
|
||||||
|
greposimu();
|
||||||
|
}
|
||||||
|
console.log("GrepoSimu loaded")
|
||||||
|
document.addEventListener('keyup', doc_keyUp, false)
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package com.bernard.greposimu;
|
package com.bernard.greposimu;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -31,7 +32,10 @@ class GrepoSimuApplicationTests {
|
|||||||
void testJsonRead() throws IOException {
|
void testJsonRead() throws IOException {
|
||||||
System.out.println("Test de sérialisation :");
|
System.out.println("Test de sérialisation :");
|
||||||
GameConfig gc = GrepoSimu.makeGameData();
|
GameConfig gc = GrepoSimu.makeGameData();
|
||||||
SimulatorData sd = JSONSourcer.makeSimulationData(new File("/home/mysaa/Downloads/greposimu.json"),gc);
|
FileInputStream fis = new FileInputStream(new File("/home/mysaa/Downloads/greposimu.json"));
|
||||||
|
String data = new String(fis.readAllBytes());
|
||||||
|
fis.close();
|
||||||
|
SimulatorData sd = JSONSourcer.makeSimulationData(data,gc);
|
||||||
//System.out.println(sd);
|
//System.out.println(sd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +63,10 @@ class GrepoSimuApplicationTests {
|
|||||||
@Test
|
@Test
|
||||||
void testDifferences() throws IOException {
|
void testDifferences() throws IOException {
|
||||||
GameConfig gc = GrepoSimu.makeGameData();
|
GameConfig gc = GrepoSimu.makeGameData();
|
||||||
SimulatorData sd = JSONSourcer.makeSimulationData(new File("/home/mysaa/Downloads/greposimu.json"),gc);
|
FileInputStream fis = new FileInputStream(new File("/home/mysaa/Downloads/greposimu.json"));
|
||||||
|
String data = new String(fis.readAllBytes());
|
||||||
|
fis.close();
|
||||||
|
SimulatorData sd = JSONSourcer.makeSimulationData(data,gc);
|
||||||
System.out.println(gc.getUnits().stream().map(Unit::getId).collect(Collectors.joining(",")));
|
System.out.println(gc.getUnits().stream().map(Unit::getId).collect(Collectors.joining(",")));
|
||||||
TownObjective defObjective = testObjective(gc);
|
TownObjective defObjective = testObjective(gc);
|
||||||
/*
|
/*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user