Skip to content

Commit

Permalink
major update and shared worlds connection
Browse files Browse the repository at this point in the history
  • Loading branch information
sirmmo committed Sep 12, 2022
1 parent 857ef51 commit dbf2109
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
1 change: 1 addition & 0 deletions module.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "ofm-map-canvas",
"name": "ofm-map-canvas",
"title": "FantasyMaps map canvas",
"description": "Create scenes with FantasyMaps vectors.",
Expand Down
36 changes: 22 additions & 14 deletions modules/map-canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ class MapCanvas extends Application {
Hooks.on('mapCanvasGenerateScene', () => this.updateScene(true));
Hooks.on('mapCanvasUpdateScene', this.updateScene);

Hooks.on('ofmSharedWorldUpdateScene', (args) => this.sharedUpdateScene(args));

// Register our settings
Hooks.once('init', () => {
MapCanvas.registerSettings(options).then(() => console.log("MapCanvas Settings Registered."));
Expand Down Expand Up @@ -224,6 +226,10 @@ class MapCanvas extends Application {
});
}

async sharedUpdateScene(args){
await this.imgUpdateScene.call(this, ...args);
}

async updateScene(generateNewScene = false) {
const LICENSE = game.settings.get("ofm-map-canvas", "LICENSE");
const RENDER_MODE = game.settings.get("ofm-map-canvas", "RENDER_MODE");
Expand Down Expand Up @@ -256,30 +262,29 @@ class MapCanvas extends Application {
HEIGHT *= 2;
}


const bbox = [jdoc.bounds._sw.lng, jdoc.bounds._sw.lat, jdoc.bounds._ne.lng, jdoc.bounds._ne.lat];

const vectors = await $.getJSON('https://vectors.fantasymaps.org/vectors/'+ WORLD_TO_LOAD +'?width='+WIDTH+'&height='+HEIGHT+'&bbox=['+bbox.join(',')+']&zoom='+jdoc.zoom+'&key='+LICENSE);

await this.imgUpdateScene(scene.id, sceneName, WORLD_TO_LOAD, WIDTH, HEIGHT, bbox, jdoc.zoom, LICENSE, RENDER_MODE, generateNewScene );
}
async imgUpdateScene(sceneId, sceneName, WORLD_TO_LOAD, WIDTH, HEIGHT, bbox, ZOOM, LICENSE, RENDER_MODE, generateNewScene) {
console.log('imgUpdateScene', sceneId, sceneName, WORLD_TO_LOAD, WIDTH, HEIGHT, bbox, ZOOM, LICENSE, RENDER_MODE, generateNewScene)
const vectors = await $.getJSON('https://vectors.fantasymaps.org/vectors/'+ WORLD_TO_LOAD +'?width='+WIDTH+'&height='+HEIGHT+'&bbox=['+bbox.join(',')+']&zoom='+ZOOM+'&key='+LICENSE);

console.log(vectors.tiles);



if (!generateNewScene) {
await canvas.lighting.deleteAll();
await canvas.walls.deleteAll();
await canvas.tokens.deleteAll();
await canvas.foreground.objects.destroy();
await canvas.background.objects.destroy()
await canvas.sight.resetFog();
}

//await const fileUtils = game.modules.get('foundry-file-utils');
try{
await FilePicker.createDirectory('data', 'ofm-map-canvas');
} catch(ex){ }

const url = 'https://vectors.fantasymaps.org/render/' + WORLD_TO_LOAD + '.jpeg?width='+WIDTH+'&height='+HEIGHT+'&bbox=[' + bbox.join(',') + ']&zoom=' + jdoc.zoom + '&key='+LICENSE + "&mode=" + RENDER_MODE;
const url = 'https://vectors.fantasymaps.org/render/' + WORLD_TO_LOAD + '.jpeg?width='+WIDTH+'&height='+HEIGHT+'&bbox=[' + bbox.join(',') + ']&zoom=' + ZOOM + '&key='+LICENSE + "&mode=" + RENDER_MODE;
console.log(url)
const data = await fetch(url);
console.log(data)
Expand All @@ -290,7 +295,7 @@ class MapCanvas extends Application {


let updates = {
_id: scene.id,
_id: sceneId,
width: WIDTH,
height: HEIGHT,
bgSource: 'ofm-map-canvas/'+sceneName+".jpeg",
Expand All @@ -306,10 +311,13 @@ class MapCanvas extends Application {
lights: vectors.lights,
//tokens: vectors.tokens,
tiles: vectors.tiles,
ofm: true,
ofmWorld: WORLD_TO_LOAD,
ofmBbox: bbox,
ofmLicense: LICENSE
flags:{
ofm: true,
ofmWorld: WORLD_TO_LOAD,
ofmBbox: bbox,
ofmLicense: LICENSE,
renderArgs: [sceneId, sceneName, WORLD_TO_LOAD, WIDTH, HEIGHT, bbox, ZOOM, LICENSE, RENDER_MODE, false]
}
};

//if(WORLD_TO_LOAD === 'osm'){
Expand Down

0 comments on commit dbf2109

Please sign in to comment.