Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add api wrapper for easier macro usage #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/init.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ModuleSettings from "./settings.mjs";
import ResourcesApi from "./resources_api.mjs";
import PartyResources from "./resources_api_wrapper.mjs";
import DashboardDirections from "./dashboard_directions.mjs";
import ResourceNotifications from "./resource_notifications.mjs"
import ResourcesDashboard from "./apps/resources_dashboard.mjs"
Expand All @@ -16,6 +17,7 @@ Hooks.once('init', () => {

loadTemplates(templates())
ModuleSettings.register()
window.PartyResources = PartyResources
})

Hooks.once('ready', () => {
Expand Down
33 changes: 33 additions & 0 deletions src/resources_api_wrapper.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export default class PartyResources{
static getById(id){
return window.pr.api.get(id);
}

static _getResourceId(name){
return window.pr.api.resources().resources.find(r=>r.name == name)?.id;
}

static getByName(name){
return PartyResources.getById(this._getResourceId(name));
}

static incrementById(id, amount){
window.pr.api.increment(id, amount);
}

static decrementById(id, amount){
window.pr.api.decrement(id, amount);
}

static incrementByName(name, amount){
PartyResources.incrementById(_getResourceId(name), amount);
}

static decrementByName(name, amount){
PartyResources.decrementById(_getResourceId(name), amount);
}

static getResources(){
return window.pr.api.resources().resources;
}
}