/** * Default wall types (walls can be other combinations of vision/movement restriction too) * @readonly * @enum {number} */ var FOUNDRY_DOOR_TYPES = { WALL: 0, TERRAIN: 1, INVISIBLE: 2, ETHEREAL: 3, DOOR: 4, SECRETDOOR: 5, OTHER: -1 }; /** * Determine what default wall type a Wall object matches, if any * @param {object} wall - the wall to query * @return {number} wall_type - a member of FOUNDRY_DOOR_TYPES */ function determineWallType(wall) { let move = wall.data.move; let sense = wall.data.sense; let door = wall.data.door; if (move === CONST.WALL_MOVEMENT_TYPES.NORMAL && sense === CONST.WALL_SENSE_TYPES.NORMAL && door === CONST.WALL_DOOR_TYPES.NONE) { return FOUNDRY_DOOR_TYPES.WALL; } else if (move === CONST.WALL_MOVEMENT_TYPES.NORMAL && sense === CONST.WALL_SENSE_TYPES.LIMITED && door === CONST.WALL_DOOR_TYPES.NONE) { return FOUNDRY_DOOR_TYPES.TERRAIN; } else if (move === CONST.WALL_MOVEMENT_TYPES.NORMAL && sense === CONST.WALL_SENSE_TYPES.NONE && door === CONST.WALL_DOOR_TYPES.NONE) { return FOUNDRY_DOOR_TYPES.INVISIBLE; } else if (move === CONST.WALL_MOVEMENT_TYPES.NONE && sense === CONST.WALL_SENSE_TYPES.NORMAL && door === CONST.WALL_DOOR_TYPES.NONE) { return FOUNDRY_DOOR_TYPES.ETHEREAL } else if (move === CONST.WALL_MOVEMENT_TYPES.NORMAL && sense === CONST.WALL_SENSE_TYPES.NORMAL && door === CONST.WALL_DOOR_TYPES.DOOR) { return FOUNDRY_DOOR_TYPES.DOOR; } else if (move === CONST.WALL_MOVEMENT_TYPES.NORMAL && sense === CONST.WALL_SENSE_TYPES.NORMAL && door === CONST.WALL_DOOR_TYPES.SECRET) { return FOUNDRY_DOOR_TYPES.SECRETDOOR; } else { return FOUNDRY_DOOR_TYPES.OTHER; } } /** @constant {string} */ MODULENAME = "foundry-walls-to-drawing"; /** @constant {string} */ WALLCOLOUR = "#111111"; /** @constant {number} */ WALLWIDTH = "4"; /** @constant {string} */ TERRAINCOLOUR = "#116611"; /** @constant {string} */ INVISIBLECOLOUR = "#006666"; /** @constant {string} */ ETHEREALCOLOUR = "#CC00CC"; /** @constant {string} */ //DOORCOLOUR = "#CC9900"; DOORCOLOUR = "#3333FF"; /** @constant {string} */ SECRETDOORCOLOUR = "#CC0000"; /** constant {string} */ let BLACK = "#000000"; /** * Set up configuration options * */ Hooks.on("init", () => { game.settings.register(MODULENAME, "cvWallColour", { name: "Converted Wall Colour", default: WALLCOLOUR, type: String, scope: "client", config: true, hint: "Enter a hexadecimal colour, eg #FF0000 for red" }); game.settings.register(MODULENAME, "cvTerrainColour", { name: "Converted Terrain Wall Colour", default: TERRAINCOLOUR, type: String, scope: "client", config: true, hint: "Enter a hexadecimal colour, eg #FF0000 for red" }); game.settings.register(MODULENAME, "cvInvisibleColour", { name: "Converted Invisible Wall Colour", default: INVISIBLECOLOUR, type: String, scope: "client", config: true, hint: "This only takes effect if rendering invisible walls" }); game.settings.register(MODULENAME, "cvEtherealColour", { name: "Converted Ethereal Wall Colour", default: ETHEREALCOLOUR, type: String, scope: "client", config: true, hint: "This only takes effect if rendering ethereal walls" }); game.settings.register(MODULENAME, "cvDoorColour", { name: "Converted Door Colour", default: DOORCOLOUR, type: String, scope: "client", config: true, hint: "This only takes effect if rendering secret doors" }); game.settings.register(MODULENAME, "cvSecretDoorColour", { name: "Converted Secret Door Colour", default: SECRETDOORCOLOUR, type: String, scope: "client", config: true, hint: "This only takes effect if rendering doors" }); game.settings.register(MODULENAME, "cvWallWidth", { name: "Converted Wall Width", default: WALLWIDTH, type: Number, scope: "client", config: true, hint: "Enter a decimal width" }); }); /** * Add 'Convert to walls' button in Walls Layer Tools * */ Hooks.on('getSceneControlButtons', controls => { cvWallColour = game.settings.get(MODULENAME, "cvWallColour"); cvTerrainColour = game.settings.get(MODULENAME, "cvTerrainColour"); cvInvisibleColour = game.settings.get(MODULENAME, "cvInvisibleColour"); cvEtherealColour = game.settings.get(MODULENAME, "cvEtherealColour"); cvDoorColour = game.settings.get(MODULENAME, "cvDoorColour"); cvSecretDoorColour = game.settings.get(MODULENAME, "cvSecretDoorColour"); cvWallWidth = game.settings.get(MODULENAME, "cvWallWidth"); let walls = controls.find(e => e.name === "walls"); walls.tools.push( { "name": "convert-to-draw", "icon": "far fa-square", "title": "Convert selected to Drawing", "onClick": () => { cvWalls = []; var wallRenderColour = BLACK; canvas.walls.controlled.forEach(function(wall) { switch(determineWallType(wall)) { case FOUNDRY_DOOR_TYPES.WALL: wallRenderColour = cvWallColour; break; case FOUNDRY_DOOR_TYPES.TERRAIN: wallRenderColour = cvTerrainColour; break; case FOUNDRY_DOOR_TYPES.INVISIBLE: wallRenderColour = cvInvisibleColour; break case FOUNDRY_DOOR_TYPES.ETHEREAL: wallRenderColour = cvEtherealColour; break; case FOUNDRY_DOOR_TYPES.DOOR: wallRenderColour = cvDoorColour; break; case FOUNDRY_DOOR_TYPES.SECRETDOOR: wallRenderColour = cvSecretDoorColour; break; case FOUNDRY_DOOR_TYPES.OTHER: wallRenderColour = BLACK; break } cvWalls.push({ type: CONST.DRAWING_TYPES.POLYGON, author: game.user._id, x: 0, y: 0, height: 100, strokeWidth: cvWallWidth, strokeColor: wallRenderColour, points: [ [wall.coords[0], wall.coords[1]], [wall.coords[2], wall.coords[3]] ] }); }); Drawing.create(cvWalls); ui.controls.controls.find(e => e.name === "walls").activeTool = "select"; ui.controls.render(); } }); });