Merge pull request #1 from moo-man/dev

Level select
This commit is contained in:
Russell
2020-03-16 09:49:21 -05:00
committed by GitHub
2 changed files with 159 additions and 80 deletions

View File

@@ -37,59 +37,151 @@ static Prompt(scene)
}).render(true); }).render(true);
} }
static DDImport(scene, file) static async DDImport(scene, file)
{ {
let level = 0;
if (file.world.levels[1])
{
let levelOptions = "";
for (let level in file.world.levels)
levelOptions = levelOptions.concat(`<option value="${level}">${file.world.levels[level].label}</option>`)
let html =
`<p>Which level do you want to import?</p>
<select name = "level-selector">
${levelOptions}
</select>
`
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)});
}
scene.update({"walls" : this.GetWalls(file)});
scene.update({"lights" : this.GetLights(file)});
} }
static GetWalls(file) static GetWalls(file, level)
{ {
let walls = []; let walls = [];
for (let index in file.world.levels[0].walls) let ddPortalList = [];
for (let index in file.world.levels[level].walls)
{ {
if (!isNaN(index)) if (!isNaN(index))
{ {
let ddWalls = file.world.levels[0].walls[index] let ddWalls = file.world.levels[level].walls[index]
let wallSet = [] let wallSet = []
let doors = ddWalls.portals.length > 0;
let ddPointString = ddWalls.points; let ddPointString = ddWalls.points;
let points = ddPointString.substring(18, ddPointString.length-2).split(", ").map(a => Number(a)) let points = ddPointString.substring(18, 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;
let ddScale = canvas.grid.size/256 let ddScale = canvas.grid.size/256
/* if (ddWalls.portals)
{
for(let i = 0; i < points.length-3; i+=2) 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)))
{
}
else if (this.pointIsOnLine([portalPoints[2], portalPoints[3]], point1.concat(point2)))
{
}
let wall = new Wall({ let wall = new Wall({
c : [(points[i]*ddScale)+offsetX, (points[i+1]*ddScale)+offsetY, (points[i+2]*ddScale)+offsetX, (points[i+3]*ddScale)+offsetY], 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) wallSet.push(wall.data)
} }
if (wallSet.length >=2 )
if (wallSet.length % 2 != 0)
wallSet.push(new Wall({ 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]] c: [wallSet[0].c[0], wallSet[0].c[1], wallSet[wallSet.length-1].c[2], wallSet[wallSet.length-1].c[3]]
}).data) }).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); 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)
// }
// }
for (let index in file.world.levels[0].portals) return walls
{ }
if (!isNaN(index))
{ static pointIsOnLine(point, line)
let ddPortals = file.world.levels[0].portals[index] {
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 ddPortalString = ddPortals.position;
let offsetX = canvas.dimensions.paddingX; let offsetX = canvas.dimensions.paddingX;
let offsetY = canvas.dimensions.paddingY; let offsetY = canvas.dimensions.paddingY;
@@ -113,30 +205,18 @@ static GetWalls(file)
point2[0]+=adjustX; point2[0]+=adjustX;
point2[1]+=adjustY; point2[1]+=adjustY;
return point1, point2
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 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,14 +227,13 @@ 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;

View File

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