This commit is contained in:
2020-03-22 22:40:18 +01:00
parent 71d0b65d2d
commit 04355c7a3a
2 changed files with 73 additions and 117 deletions

View File

@@ -83,9 +83,9 @@ class DDImporter {
}
static convertPointFromDDtoFVTT(point){
let offsetX = canvas.dimensions.paddingX;
let offsetY = canvas.dimensions.paddingY;
let ddScale = canvas.grid.size/256;
let offsetX = 100
let offsetY = 100
let ddScale = 2;
return [(point[0]*ddScale)+offsetX, (point[1]*ddScale)+offsetY]
}
@@ -93,135 +93,91 @@ class DDImporter {
{
let walls = [];
let ddPortalList = [];
let allwalls = [];
let alldoors = [];
for (let index in file.world.levels[level].walls)
{
if (!isNaN(index))
let wallSet = []
let ddWalls = file.world.levels[level].walls[index]
let ddPointString = ddWalls.points;
let points = ddPointString.substring(18, ddPointString.length-2).split(", ").map(a => Number(a))
points = points.concat(points.slice(0,2))
for(let i = 0; i < points.length-3; i+=2)
{
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))
points = points.concat(points.slice(0,2))
let offsetX = canvas.dimensions.paddingX;
let offsetY = canvas.dimensions.paddingY;
let ddScale = canvas.grid.size/256
if (ddWalls.portals)
{
for(let i = 0; i < points.length-3; i+=2)
{
for (let portal of ddWalls.portals){
console.log(portal);
let portalCenterPoint = portal.position.substring(8, portal.position.length-2).split(", ").map(a => Number(a))
let portalDirection = portal.direction.substring(8, portal.direction.length-2).split(", ").map(a => Number(a))
let portalPoint1 = [portalCenterPoint[0] + portal.radius*portalDirection[0], portalCenterPoint[1] + portal.radius*portalDirection[1]] ;
let portalPoint2 = [portalCenterPoint[0] - portal.radius*portalDirection[0], portalCenterPoint[1] - portal.radius*portalDirection[1]] ;
console.log(portalCenterPoint)
console.log(portalPoint1)
console.log(portalPoint2)
let portalPoint1FVTT = this.convertPointFromDDtoFVTT(portalPoint1);
let portalPoint2FVTT = this.convertPointFromDDtoFVTT(portalPoint2);
if(i == 0){
let wall = new Wall({
c : [portalPoint1FVTT[0], portalPoint1FVTT[1], portalPoint2FVTT[0], portalPoint2FVTT[1]],
});
wall.data.door = CONST.WALL_DOOR_TYPES.DOOR
walls.push(wall.data)
}
let point1 = [points[i], points[i+1]]
let point2 = [points[i+2], points[i+3]]
let line = [point1,point2]
if (this.pointIsOnLine(portalCenterPoint,line))
{
console.log('yes');
let topoint1 = this.convertPointFromDDtoFVTT(this.getNearerPoint(point1, [portalPoint1, portalPoint2]));
let topoint2 = this.convertPointFromDDtoFVTT(this.getNearerPoint(point2, [portalPoint1, portalPoint2]));
let point1fctt = this.convertPointFromDDtoFVTT(point1);
let point2fctt = this.convertPointFromDDtoFVTT(point2);
if (JSON.stringify(point1fctt)!==JSON.stringify(topoint1)){
let wall1 = new Wall({
c : [
point1fctt[0],
point1fctt[1],
topoint1[0],
topoint1[1]]
});
wallSet.push(wall1.data)
}
if (JSON.stringify(point2fctt)!==JSON.stringify(topoint2)){
let wall2 = new Wall({
c : [
point2fctt[0],
point2fctt[1],
topoint2[0],
topoint2[1]]
});
wallSet.push(wall2.data)
}
}
else{
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)
}
allwalls.push([[points[i], points[i+1]], [points[i+2], points[i+3]]])
}
for (let portal of ddWalls.portals){
let portalCenterPoint = portal.position.substring(8, portal.position.length-2).split(", ").map(a => Number(a))
let portalDirection = portal.direction.substring(8, portal.direction.length-2).split(", ").map(a => Number(a))
let portalPoint1 = [portalCenterPoint[0] + portal.radius*portalDirection[0], portalCenterPoint[1] + portal.radius*portalDirection[1]] ;
let portalPoint2 = [portalCenterPoint[0] - portal.radius*portalDirection[0], portalCenterPoint[1] - portal.radius*portalDirection[1]] ;
alldoors.push([portalPoint1, portalPoint2])
let allwalls_new = []
for (let lineindex in allwalls){
let line = allwalls[lineindex]
if (this.pointIsOnLine(portalCenterPoint,line)){
let endpoint1 = this.getNearerPoint(line[0], [portalPoint1, portalPoint2])
let endpoint2 = this.getNearerPoint(line[1], [portalPoint1, portalPoint2])
if (line[0][0] != endpoint1[0] || line[0][1] != endpoint1[1]){
allwalls_new.push([[line[0][0], line[0][1]], [endpoint1[0], endpoint1[1]]])
}
if (line[1][0] != endpoint2[0] || line[1][1] != endpoint2[1]){
allwalls_new.push([[line[1][0], line[1][1]], [endpoint2[0], endpoint2[1]]])
}
}
}
else
{
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)
else{
allwalls_new.push(line)
}
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);
allwalls = allwalls_new
}
}
// 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)
// }
// }
for (let w of allwalls){
let sp = this.convertPointFromDDtoFVTT(w[0])
let ep = this.convertPointFromDDtoFVTT(w[1])
let wall = new Wall({
c : [
sp[0],
sp[1],
ep[0],
ep[1]
]
});
walls.push(wall.data)
}
for (let w of alldoors){
let sp = this.convertPointFromDDtoFVTT(w[0])
let ep = this.convertPointFromDDtoFVTT(w[1])
let wall = new Wall({
c : [
sp[0],
sp[1],
ep[0],
ep[1]
]
});
wall.data.door = true;
walls.push(wall.data)
}
return walls
}
static pointIsOnLine(point, line)
{
var slope = (line[0][1] - line[1][1])/(line[0][0] - line[1][0])
var slopedenom = (line[0][0] - line[1][0])
var slopenom = (line[0][1] - line[1][1])
if (slopedenom == 0){
if (point[0] == line[0][0]){
if ( (point[1] < line[1][1] && point[1] > line[0][1]) ||
(point[1] > line[1][1] && point[1] < line[0][1])){
return true
}
}
return false
}
var slope = slopenom/slopedenom
var intercept = line[1][1] - slope * line[1][0]
return (point[1] == (slope * point[0] + intercept))

View File

@@ -2,7 +2,7 @@
"name": "dd-import",
"title": "DungeonDraft Importer",
"description": "Imports scene elements from Dungeon Draft map files",
"version": "0.4.12",
"version": "0.4.13",
"authors": [
{
"name": "Moo Man"