Added link with website and tampermonkey script

This commit is contained in:
Samy Avrillon 2024-11-01 23:23:15 +01:00
parent fa7d0362c7
commit 0686ab99c5
Signed by: Mysaa
GPG Key ID: 0220AC4A3D6A328B
8 changed files with 182 additions and 53 deletions

View File

@ -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);
}

View File

@ -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";
}
}

View File

@ -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)

View File

@ -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

View File

@ -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()) {

View File

@ -1,3 +1,4 @@
spring.application.name=GrepoSimu
spring.devtools.restart.pollInterval=10s
spring.mvc.favicon.enabled=false
spring.web.resources.static-locations=classpath:/static/

View File

@ -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){
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj,null,2));
var downloadAnchorNode = document.createElement('a');
@ -43,16 +57,16 @@ function makeObject() {
orderz = ITowns.towns[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
out[townid].buildingOrders.push({
buildingTime: order.building_time,
building: order.building_type,
beginTime: order.created_at,
beginTime: order.created_at,
tearingDown: order.tear_down,
endTime: order.to_be_completed_at,
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]
@ -60,14 +74,14 @@ function makeObject() {
for(var i = 0; i<recruitments.models.length; i++) {
order = recruitments.models[i].attributes
out[townid].recruitingOrders.push({
count: order.count,
count: order.count,
beginTime: order.created_at,
kind: order.kind,
done: order.parts_done,
refund: order.refund_for_single_unit,
endTime: order.to_be_completed_at,
endTime: order.to_be_completed_at,
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++) {
order = castedPowers.models[i].attributes
out[townid].castedPowers.push({
configuration: order.configuration,
endTime: order.to_be_completed_at,
extended: order.extended,
configuration: order.configuration,
endTime: order.to_be_completed_at,
extended: order.extended,
level: order.level,
originPlayer: order.origin_player_id,
power: order.power_id
@ -91,7 +105,7 @@ function makeObject() {
order = researches.models[i].attributes
out[townid].researchOrders.push({
research: order.research_type,
beginTime: order.created_at,
beginTime: order.created_at,
endTime: order.to_be_completed_at,
refund: order.cancel_refund
})
@ -101,7 +115,7 @@ function makeObject() {
militia = MM.getModels().Militia
if(townid in militia){
out[townid].militia = {
start : militia[townid].attributes.started_at,
start : militia[townid].attributes.started_at,
end: militia[townid].attributes.finished_at
}
} else {
@ -135,6 +149,7 @@ function makeObject() {
targetId: mvt.target_town_id,
type: mvt.type,
})
}
trdz = MM.getModels().Trade
outTrd = []
for (var i in trdz) {
@ -144,7 +159,7 @@ function makeObject() {
arrival: trd.arrival_at,
dest: trd.destination_town_id,
destType: trd.destination_town_type,
gold: trd.gold,
gold: trd.gold,
stone: trd.stone,
wood: trd.wood,
iron: trd.iron,
@ -153,7 +168,6 @@ function makeObject() {
exchange: trd.in_exchange
})
}
}
fav = MM.getModels().PlayerGods[Object.keys(MM.getModels().PlayerGods)[0]].attributes
outFav = {
aphrodite: fav.aphrodite_favor,
@ -172,12 +186,32 @@ function makeObject() {
outUts.push({
orig: utz[i].getOriginTownId(),
curr: utz[i].getCurrentTownId(),
units: utz[i].getUnits(),
sameIsland: utz[i].isSameIsland()
units: utz[i].getUnits(),
sameIsland: utz[i].isSameIsland()
})
}
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)

View File

@ -1,6 +1,7 @@
package com.bernard.greposimu;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
@ -31,7 +32,10 @@ class GrepoSimuApplicationTests {
void testJsonRead() throws IOException {
System.out.println("Test de sérialisation :");
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);
}
@ -59,7 +63,10 @@ class GrepoSimuApplicationTests {
@Test
void testDifferences() throws IOException {
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(",")));
TownObjective defObjective = testObjective(gc);
/*