forked from RealDeuce/torch
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfixes: unlinked tokens and OSE sources.
Features: API for macros, help dialogs, "Reclaiming the Wild" support.
- Loading branch information
Showing
16 changed files
with
460 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import Settings from "./settings.js"; | ||
import SourceLibrary from "./library.js"; | ||
import TorchToken from './token.js'; | ||
|
||
export default class TorchAPI { | ||
async #setup(sceneId, tokenId) { | ||
let scene = game.scenes.get(sceneId); | ||
let tokenDoc = scene.tokens.get(tokenId); | ||
let actor = game.actors.get(tokenDoc.actorId); | ||
|
||
let library = await SourceLibrary.load( | ||
game.system.id, | ||
Settings.lightRadii.bright, | ||
Settings.lightRadii.dim, | ||
Settings.inventoryItemName, | ||
Settings.gameLightSources, | ||
actor.prototypeToken.light, | ||
); | ||
return new TorchToken(tokenDoc, library); | ||
} | ||
#parmCheck2(fnname, sceneId, tokenId){ | ||
const idPattern = /[A-Za-z0-9]+/; | ||
let result; | ||
if (typeof sceneId !== "string" || !idPattern.test(sceneId)) { | ||
result = "first parm - scene id - isn't an id string"; | ||
} | ||
if (typeof tokenId !== "string" || !idPattern.test(tokenId)) { | ||
result = "second parm - token id - isn't an id string"; | ||
} | ||
if (result) { | ||
throw (`${fnname} : ${result}`); | ||
} | ||
} | ||
|
||
#parmCheck3(fnname, sceneId, tokenId, source){ | ||
const idPattern = /[A-Za-z0-9]+/; | ||
let result; | ||
if (typeof sceneId !== "string" || !idPattern.test(sceneId)) { | ||
rresult = "first parm - scene id - isn't an id string"; | ||
} | ||
if (typeof tokenId !== "string" || !idPattern.test(tokenId)) { | ||
result = "second parm - token id - isn't an id string"; | ||
} | ||
if (typeof source !== "string" || source.length < 1) { | ||
result = "third parm - source name - isn't the name of a light source"; | ||
} | ||
if (result) { | ||
throw (`${fnname} : ${result}`); | ||
} | ||
} | ||
|
||
async toggle(sceneId, tokenId) { | ||
this.#parmCheck2("toggle", sceneId, tokenId); | ||
let token = await this.#setup(sceneId, tokenId); | ||
return await token.advanceState(); | ||
}; | ||
|
||
async extinguish(sceneId, tokenId) { | ||
this.#parmCheck2("extinguish", sceneId, tokenId); | ||
let token = await this.#setup(sceneId, tokenId); | ||
return await token.forceStateOff(); | ||
} | ||
|
||
async currentSource(sceneId, tokenId) { | ||
this.#parmCheck2("currentSource", sceneId, tokenId); | ||
let token = await this.#setup(sceneId, tokenId); | ||
return await token.currentLightSource; | ||
} | ||
|
||
async currentState(sceneId, tokenId) { | ||
this.#parmCheck2("currentState", sceneId, tokenId); | ||
let token = await this.#setup(sceneId, tokenId); | ||
return await token.lightSourceState; | ||
}; | ||
|
||
async equippedSources(sceneId, tokenId) { | ||
this.#parmCheck2("equippedSources", sceneId, tokenId); | ||
let token = await this.#setup(sceneId, tokenId); | ||
return await token.ownedLightSources.map(item => item.name); | ||
} | ||
|
||
async selectSource(sceneId, tokenId, source) { | ||
this.#parmCheck3("selectSource", sceneId, tokenId, source); | ||
let token = await this.#setup(sceneId, tokenId); | ||
return await token.setCurrentLightSource(source); | ||
}; | ||
|
||
async inventory(sceneId, tokenId, source) { | ||
this.#parmCheck3("inventory", sceneId, tokenId, source); | ||
let token = await this.#setup(sceneId, tokenId); | ||
return await token.getInventory(source); | ||
} | ||
|
||
async sourceExhausted(sceneId, tokenId, source) { | ||
this.#parmCheck3("sourceExhausted", sceneId, tokenId, source); | ||
let token = await this.#setup(sceneId, tokenId); | ||
return await token.lightSourceIsExhausted(source); | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.