Skip to content

Commit

Permalink
Added populate, clear, and setTileState public methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
zeel01 committed Aug 26, 2021
1 parent 88280cd commit bbc6c97
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"notifications": {
"warn": {
"unmatchedUnits": "The source and target scenes do not share the same distance units, the scale factor may not be accurate.",
"noResize": "Scene Tiler tiles can not be resized."
"noResize": "Scene Tiler tiles can not be resized.",
"notaSceneTile": "This Tile is not a Scene Tile"
}
},
"console": {
Expand Down
33 changes: 31 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,36 @@ When coordinates are omitted, the tile will be placed in the center of the scene
#### Example

```js
await SceneTiler.create(game.scenes.getName("Tile Source Test"), { populate: true, rotation: 45 })
let tile = await SceneTiler.create(game.scenes.getName("Tile Source Test"), { populate: true, rotation: 45 })
```

Creates a tile from "Tile Source Test" at the center of the scene, rotated 45 degrees, and instantly populates it.
Creates a tile from "Tile Source Test" at the center of the scene, rotated 45 degrees, and instantly populates it.

### `populate(tile)` & `clear(tile)`

These methods accept a `Tile` object with Scene Tiler flags and populate or clear it with the objects from the source scene.

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| tile | `Tile` | The tile to populate or clear. |

#### Example

```js
let tile = await SceneTiler.create(game.scenes.getName("Tile Source Test"), { populate: false })

await SceneTiler.populate(tile);
```

### `setTileState(tile, state)`

Sets the populated/cleared state of a tile. Similar to `populate` and `clear` but accepts a second Boolean parameter. When `state` is true, the tile will be locked and populated. When `state` is false, the tile will be unlocked and cleared.

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| tile | `Tile` | The tile to populate or clear. |
| state | `Boolean` | Whether or not to populate the tile with the objects from the source scene. |
51 changes: 50 additions & 1 deletion scene-tiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,55 @@ class SceneTiler {
}


/**
* Populates a tile with placeables from a scene.
*
* @static
* @param {TileDocument} tile - A Scene Tiler tile.
* @return {Promise<TileDocument>} The tile that was updated
* @memberof SceneTiler
*/
static async populate(tile) {
return await this.setTileState(tile, true);
}


/**
* Clears the tile of all placeables.
*
* @static
* @param {TileDocument} tile - A Scene Tiler tile.
* @return {Promise<TileDocument>} The tile that was updated
* @memberof SceneTiler
*/
static async clear(tile) {
return await this.setTileState(tile, false);
}


/**
* Set the populated/cleared state of a tile.
*
* If state is true, populates the tile.
* If state is false, clears the tile.
*
* @static
* @param {TileDocument} tile - A Scene Tiler tile.
* @param {Boolean} state - Whether to populate or clear the tile
* @return {Promise<TileDocument>} The tile that was updated
* @memberof SceneTiler
*/
static async setTileState(tile, state) {
if (tile.data.flags["scene-tiler"]?.scene)
return await tile.update({ locked: state });
else {
const message = game.i18n.localize("scene-tiler.notifications.warn.notaSceneTile");
console.warn(message);
ui.notifications.warn(message);
}
}


/**
* @typedef {Object} dropData - A set of data generated when dropping something onto the scene
* @property {String} id - The ID of the entity that was dropped
Expand Down Expand Up @@ -238,7 +287,7 @@ class SceneTiler {
* @param {Number} [rotation=0] - The rotation of the tile
* @param {Boolean} [centered=true] - If true, the tile position is shifted to be relative to the center of the tile
* @param {Number} [locked=false] - Whether or not to create the tile in a locked state. Only do this if the tile is being deployed immediately.
* @return {TileDocument} The data of the tile that was created
* @return {Promise<TileDocument>} The data of the tile that was created
* @memberof SceneTiler
*/
static async createTile(source, uuid, x, y, rotation = 0, centered = true, locked = false) {
Expand Down

0 comments on commit bbc6c97

Please sign in to comment.