From 60fabfb0a4b4970fc6139fc228d6d1cb952c67f0 Mon Sep 17 00:00:00 2001 From: Russell Date: Wed, 11 Mar 2020 09:04:32 -0500 Subject: [PATCH 1/2] Level select --- ddimport.js | 235 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 157 insertions(+), 78 deletions(-) diff --git a/ddimport.js b/ddimport.js index e90ba69..84da1f8 100644 --- a/ddimport.js +++ b/ddimport.js @@ -37,106 +37,186 @@ static Prompt(scene) }).render(true); } -static DDImport(scene, file) +static async DDImport(scene, file) { - - scene.update({"walls" : this.GetWalls(file)}); - scene.update({"lights" : this.GetLights(file)}); - -} - -static GetWalls(file) -{ - let walls = []; - for (let index in file.world.levels[0].walls) + let level = 0; + if (file.world.levels[1]) { - if (!isNaN(index)) - { - let ddWalls = file.world.levels[0].walls[index] - let wallSet = [] - let doors = ddWalls.portals.length > 0; - let ddPointString = ddWalls.points; - let points = ddPointString.substring(18, ddPointString.length-2).split(", ").map(a => Number(a)) - let offsetX = canvas.dimensions.paddingX; - let offsetY = canvas.dimensions.paddingY; - let ddScale = canvas.grid.size/256 - - - for(let i = 0; i < points.length-3; i+=2) - { - let wall = new Wall({ - c : [(points[i]*ddScale)+offsetX, (points[i+1]*ddScale)+offsetY, (points[i+2]*ddScale)+offsetX, (points[i+3]*ddScale)+offsetY], - }); - if (doors){ - wall.data.door = CONST.WALL_DOOR_TYPES.DOOR - - } - - wallSet.push(wall.data) - } - if (wallSet.length >=2 ) - wallSet.push(new Wall({ - c: [wallSet[0].c[0], wallSet[0].c[1], wallSet[wallSet.length-1].c[2], wallSet[wallSet.length-1].c[3]] - }).data) - walls = walls.concat(wallSet); - } + let levelOptions = ""; + for (let level in file.world.levels) + levelOptions = levelOptions.concat(``) + + let html = + `

Which level do you want to import?

+ + ` + + await new Dialog({ + title: "Dungeon Draft Level Selector", + content : html, + buttons : { + confirm : { + label: "Select", + callback : (html) => { + level = JSON.parse(html.find('[name="level-selector').val()) + scene.update({"walls" : this.GetWalls(file, level)}); + scene.update({"lights" : this.GetLights(file, level)}); + return; + } + }, + cancel : { + label: "Cancel", + callback : html => {return} + } + }, + default: "confirm" + }).render(true); + } + else + { + scene.update({"walls" : this.GetWalls(file, level)}); + scene.update({"lights" : this.GetLights(file, level)}); } - - for (let index in file.world.levels[0].portals) + +} + +static GetWalls(file, level) +{ + let walls = []; + let ddPortalList = []; + for (let index in file.world.levels[level].walls) { if (!isNaN(index)) { - let ddPortals = file.world.levels[0].portals[index] - let ddPortalString = ddPortals.position; - let offsetX = canvas.dimensions.paddingX; - let offsetY = canvas.dimensions.paddingY; - let ddScale = canvas.grid.size/256 + let ddWalls = file.world.levels[level].walls[index] + let wallSet = [] + let ddPointString = ddWalls.points; + let points = ddPointString.substring(18, ddPointString.length-2).split(", ").map(a => Number(a)) + let offsetX = canvas.dimensions.paddingX; + let offsetY = canvas.dimensions.paddingY; + let ddScale = canvas.grid.size/256 - let point1 = ddPortalString.substring(9, ddPortalString.length-2).split(", ").map(a => Number(a)*ddScale) - point1[0]+=offsetX; - point1[1]+=offsetY; - let point2 = duplicate(point1); + /* if (ddWalls.portals) + { + for(let i = 0; i < points.length-3; i+=2) + { + let point1 = [(points[i]*ddScale)+offsetX, (points[i+1]*ddScale)+offsetY] + let point2 = [(points[i+2]*ddScale)+offsetX, (points[i+3]*ddScale)+offsetY] + let portal = ddWalls.portals[0]; + let portalPoints = this.findDoorPoints(portal); + if (this.pointIsOnLine([portalPoints[0], portalPoints[1]], point1.concat(point2))) + { - let adjustX = Math.cos(ddPortals.rotation) * canvas.grid.size/2; - let adjustY = Math.sin(ddPortals.rotation) * canvas.grid.size/2; + } + else if (this.pointIsOnLine([portalPoints[2], portalPoints[3]], point1.concat(point2))) + { + + } - point1[0]+=adjustX; - point1[1]+=adjustY; + let wall = new Wall({ + c : [(points[i]*ddScale)+offsetX, (points[i+1]*ddScale)+offsetY, (points[i+2]*ddScale)+offsetX, (points[i+3]*ddScale)+offsetY], + }); + wallSet.push(wall.data) + } - adjustX = Math.cos(ddPortals.rotation+Math.PI) * canvas.grid.size/2; - adjustY = Math.sin(ddPortals.rotation+Math.PI) * canvas.grid.size/2; - - point2[0]+=adjustX; - point2[1]+=adjustY; - - - - let wall = new Wall({ - c : [point1[0], point1[1], point2[0], point2[1]], - }); - wall.data.door = CONST.WALL_DOOR_TYPES.DOOR - walls.push(wall.data) + if (wallSet.length % 2 != 0) + wallSet.push(new Wall({ + c: [wallSet[0].c[0], wallSet[0].c[1], wallSet[wallSet.length-1].c[2], wallSet[wallSet.length-1].c[3]] + }).data) + + walls = walls.concat(wallSet); + }*/ + for(let i = 0; i < points.length-3; i+=2) + { + + let wall = new Wall({ + c : [(points[i]*ddScale)+offsetX, (points[i+1]*ddScale)+offsetY, (points[i+2]*ddScale)+offsetX, (points[i+3]*ddScale)+offsetY], + }); + wallSet.push(wall.data) + } + if (wallSet.length % 2 != 0) + wallSet.push(new Wall({ + c: [wallSet[0].c[0], wallSet[0].c[1], wallSet[wallSet.length-1].c[2], wallSet[wallSet.length-1].c[3]] + }).data) + + walls = walls.concat(wallSet); } - } + + } + + + // ddPortalList = ddPortalList.concat(file.world.levels[level].portals) + // for (let index in ddPortalList) + // { + // if (!isNaN(index)) + // { + // let ddPortal = ddPortalList[index] + // let point1, point2 = this.findDoorPoints(ddPortal) + // let wall = new Wall({ + // c : [point1[0], point1[1], point2[0], point2[1]], + // }); + // wall.data.door = CONST.WALL_DOOR_TYPES.DOOR + // walls.push(wall.data) + + // } + // } return walls } -static GetLights(file) +static pointIsOnLine(point, line) +{ + slope = (line[1] - line[3])/(line[0] - line[2]) + intercept = line[3] - slope * line[2] + + return (point[1] == (slope * point[0] + intercept)) +} + +static findDoorPoints(ddPortal) +{ + let ddPortalString = ddPortals.position; + let offsetX = canvas.dimensions.paddingX; + let offsetY = canvas.dimensions.paddingY; + let ddScale = canvas.grid.size/256 + + let point1 = ddPortalString.substring(9, ddPortalString.length-2).split(", ").map(a => Number(a)*ddScale) + point1[0]+=offsetX; + point1[1]+=offsetY; + let point2 = duplicate(point1); + + + let adjustX = Math.cos(ddPortals.rotation) * canvas.grid.size/2; + let adjustY = Math.sin(ddPortals.rotation) * canvas.grid.size/2; + + point1[0]+=adjustX; + point1[1]+=adjustY; + + adjustX = Math.cos(ddPortals.rotation+Math.PI) * canvas.grid.size/2; + adjustY = Math.sin(ddPortals.rotation+Math.PI) * canvas.grid.size/2; + + point2[0]+=adjustX; + point2[1]+=adjustY; + + return point1, point2 +} + +static GetLights(file, level) { let lights = []; - for (let index in file.world.levels[0].lights) + for (let index in file.world.levels[level].lights) { if (!isNaN(index)) { - let ddPointString = file.world.levels[0].lights[index].position - let ddLight = file.world.levels[0].lights[index] + let ddPointString = file.world.levels[level].lights[index].position + let ddLight = file.world.levels[level].lights[index] let points = ddPointString.substring(9, ddPointString.length-2).split(", ").map(a => Number(a)) let offsetX = canvas.dimensions.paddingX; let offsetY = canvas.dimensions.paddingY; @@ -147,15 +227,14 @@ static GetLights(file) x: (points[0]*ddScale)+offsetX, y: (points[1]*ddScale)+offsetY, rotation: 0, - dim: ddLight.range, - bright: ddLight.range/2, + dim: ddLight.range*2, + bright: ddLight.range, angle: 360, tintColor: "#" + ddLight.color.substring(2), tintAlpha: 0.05 }) lights.push(light.data); - console.log(light.data.tintColor); - } + } } return lights; } From 45cef77a90d459f626eaa92bb8b0589506cd02dc Mon Sep 17 00:00:00 2001 From: Russell Date: Mon, 16 Mar 2020 09:48:13 -0500 Subject: [PATCH 2/2] Update module.json --- module.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module.json b/module.json index 388c415..f5b9991 100644 --- a/module.json +++ b/module.json @@ -2,12 +2,12 @@ "name": "dd-import", "title": "DungeonDraft Importer", "description": "Imports scene elements from Dungeon Draft map files", - "version": 0.2, + "version": 0.3, "author": "Moo Man", "scripts": ["./ddimport.js"], "styles": ["./styles.css"], "packs": [], - "minimumCoreVersion": "0.4.4", + "minimumCoreVersion": "0.5.1", "manifest": "https://raw.githubusercontent.com/moo-man/FVTT-DD-Import/master/module.json", "download": "https://github.com/moo-man/FVTT-DD-Import/archive/master.zip" }