235
ddimport.js
235
ddimport.js
@@ -37,106 +37,186 @@ static Prompt(scene)
|
|||||||
}).render(true);
|
}).render(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static DDImport(scene, file)
|
static async DDImport(scene, file)
|
||||||
{
|
{
|
||||||
|
let level = 0;
|
||||||
scene.update({"walls" : this.GetWalls(file)});
|
if (file.world.levels[1])
|
||||||
scene.update({"lights" : this.GetLights(file)});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static GetWalls(file)
|
|
||||||
{
|
|
||||||
let walls = [];
|
|
||||||
for (let index in file.world.levels[0].walls)
|
|
||||||
{
|
{
|
||||||
if (!isNaN(index))
|
let levelOptions = "";
|
||||||
{
|
for (let level in file.world.levels)
|
||||||
let ddWalls = file.world.levels[0].walls[index]
|
levelOptions = levelOptions.concat(`<option value="${level}">${file.world.levels[level].label}</option>`)
|
||||||
let wallSet = []
|
|
||||||
let doors = ddWalls.portals.length > 0;
|
let html =
|
||||||
let ddPointString = ddWalls.points;
|
`<p>Which level do you want to import?</p>
|
||||||
let points = ddPointString.substring(18, ddPointString.length-2).split(", ").map(a => Number(a))
|
<select name = "level-selector">
|
||||||
let offsetX = canvas.dimensions.paddingX;
|
${levelOptions}
|
||||||
let offsetY = canvas.dimensions.paddingY;
|
</select>
|
||||||
let ddScale = canvas.grid.size/256
|
`
|
||||||
|
|
||||||
|
await new Dialog({
|
||||||
for(let i = 0; i < points.length-3; i+=2)
|
title: "Dungeon Draft Level Selector",
|
||||||
{
|
content : html,
|
||||||
let wall = new Wall({
|
buttons : {
|
||||||
c : [(points[i]*ddScale)+offsetX, (points[i+1]*ddScale)+offsetY, (points[i+2]*ddScale)+offsetX, (points[i+3]*ddScale)+offsetY],
|
confirm : {
|
||||||
});
|
label: "Select",
|
||||||
if (doors){
|
callback : (html) => {
|
||||||
wall.data.door = CONST.WALL_DOOR_TYPES.DOOR
|
level = JSON.parse(html.find('[name="level-selector').val())
|
||||||
|
scene.update({"walls" : this.GetWalls(file, level)});
|
||||||
}
|
scene.update({"lights" : this.GetLights(file, level)});
|
||||||
|
return;
|
||||||
wallSet.push(wall.data)
|
}
|
||||||
}
|
},
|
||||||
if (wallSet.length >=2 )
|
cancel : {
|
||||||
wallSet.push(new Wall({
|
label: "Cancel",
|
||||||
c: [wallSet[0].c[0], wallSet[0].c[1], wallSet[wallSet.length-1].c[2], wallSet[wallSet.length-1].c[3]]
|
callback : html => {return}
|
||||||
}).data)
|
}
|
||||||
walls = walls.concat(wallSet);
|
},
|
||||||
}
|
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))
|
if (!isNaN(index))
|
||||||
{
|
{
|
||||||
let ddPortals = file.world.levels[0].portals[index]
|
let ddWalls = file.world.levels[level].walls[index]
|
||||||
let ddPortalString = ddPortals.position;
|
let wallSet = []
|
||||||
let offsetX = canvas.dimensions.paddingX;
|
let ddPointString = ddWalls.points;
|
||||||
let offsetY = canvas.dimensions.paddingY;
|
let points = ddPointString.substring(18, ddPointString.length-2).split(", ").map(a => Number(a))
|
||||||
let ddScale = canvas.grid.size/256
|
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)
|
/* if (ddWalls.portals)
|
||||||
point1[0]+=offsetX;
|
{
|
||||||
point1[1]+=offsetY;
|
for(let i = 0; i < points.length-3; i+=2)
|
||||||
let point2 = duplicate(point1);
|
{
|
||||||
|
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;
|
let wall = new Wall({
|
||||||
point1[1]+=adjustY;
|
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;
|
if (wallSet.length % 2 != 0)
|
||||||
adjustY = Math.sin(ddPortals.rotation+Math.PI) * canvas.grid.size/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]]
|
||||||
point2[0]+=adjustX;
|
}).data)
|
||||||
point2[1]+=adjustY;
|
|
||||||
|
walls = walls.concat(wallSet);
|
||||||
|
}*/
|
||||||
|
for(let i = 0; i < points.length-3; i+=2)
|
||||||
let wall = new Wall({
|
{
|
||||||
c : [point1[0], point1[1], point2[0], point2[1]],
|
|
||||||
});
|
let wall = new Wall({
|
||||||
wall.data.door = CONST.WALL_DOOR_TYPES.DOOR
|
c : [(points[i]*ddScale)+offsetX, (points[i+1]*ddScale)+offsetY, (points[i+2]*ddScale)+offsetX, (points[i+3]*ddScale)+offsetY],
|
||||||
walls.push(wall.data)
|
});
|
||||||
|
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
|
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 = [];
|
let lights = [];
|
||||||
for (let index in file.world.levels[0].lights)
|
for (let index in file.world.levels[level].lights)
|
||||||
{
|
{
|
||||||
if (!isNaN(index))
|
if (!isNaN(index))
|
||||||
{
|
{
|
||||||
let ddPointString = file.world.levels[0].lights[index].position
|
let ddPointString = file.world.levels[level].lights[index].position
|
||||||
let ddLight = file.world.levels[0].lights[index]
|
let ddLight = file.world.levels[level].lights[index]
|
||||||
let points = ddPointString.substring(9, ddPointString.length-2).split(", ").map(a => Number(a))
|
let points = ddPointString.substring(9, ddPointString.length-2).split(", ").map(a => Number(a))
|
||||||
let offsetX = canvas.dimensions.paddingX;
|
let offsetX = canvas.dimensions.paddingX;
|
||||||
let offsetY = canvas.dimensions.paddingY;
|
let offsetY = canvas.dimensions.paddingY;
|
||||||
@@ -147,15 +227,14 @@ static GetLights(file)
|
|||||||
x: (points[0]*ddScale)+offsetX,
|
x: (points[0]*ddScale)+offsetX,
|
||||||
y: (points[1]*ddScale)+offsetY,
|
y: (points[1]*ddScale)+offsetY,
|
||||||
rotation: 0,
|
rotation: 0,
|
||||||
dim: ddLight.range,
|
dim: ddLight.range*2,
|
||||||
bright: ddLight.range/2,
|
bright: ddLight.range,
|
||||||
angle: 360,
|
angle: 360,
|
||||||
tintColor: "#" + ddLight.color.substring(2),
|
tintColor: "#" + ddLight.color.substring(2),
|
||||||
tintAlpha: 0.05
|
tintAlpha: 0.05
|
||||||
})
|
})
|
||||||
lights.push(light.data);
|
lights.push(light.data);
|
||||||
console.log(light.data.tintColor);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return lights;
|
return lights;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
"name": "dd-import",
|
"name": "dd-import",
|
||||||
"title": "DungeonDraft Importer",
|
"title": "DungeonDraft Importer",
|
||||||
"description": "Imports scene elements from Dungeon Draft map files",
|
"description": "Imports scene elements from Dungeon Draft map files",
|
||||||
"version": 0.2,
|
"version": 0.3,
|
||||||
"author": "Moo Man",
|
"author": "Moo Man",
|
||||||
"scripts": ["./ddimport.js"],
|
"scripts": ["./ddimport.js"],
|
||||||
"styles": ["./styles.css"],
|
"styles": ["./styles.css"],
|
||||||
"packs": [],
|
"packs": [],
|
||||||
"minimumCoreVersion": "0.4.4",
|
"minimumCoreVersion": "0.5.1",
|
||||||
"manifest": "https://raw.githubusercontent.com/moo-man/FVTT-DD-Import/master/module.json",
|
"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"
|
"download": "https://github.com/moo-man/FVTT-DD-Import/archive/master.zip"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user