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

Feature - Api Wrapper #71

Open
DawidIzydor opened this issue Feb 4, 2023 · 5 comments
Open

Feature - Api Wrapper #71

DawidIzydor opened this issue Feb 4, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@DawidIzydor
Copy link

DawidIzydor commented Feb 4, 2023

Feature: add api wrapper for easier interactions with this module through macros

I have this feature already implemented, will create a PR shortly

DawidIzydor added a commit to DawidIzydor/fvtt-party-resources that referenced this issue Feb 4, 2023
@DawidIzydor
Copy link
Author

Created PR #72

@DawidIzydor
Copy link
Author

Example usage - using PartyResources to manage cooking ingredients from the Pathfinder Kingmaker AP

new Dialog({
  title:'Add resource',
  content:`
    <form>
      <div class="form-group">
        <label>Basic ingredient</label>
        <input type='number' name='basicIngredient'></input>
      </div>
      <div class="form-group">
        <label>Special ingredient</label>
        <input type='number' name='specialIngredient'></input>
      </div>
    </form>`,
  buttons:{
    yes: {
      icon: "<i class='fas fa-check'></i>",
      label: `Apply Changes`
    }},
  default:'yes',
  close: html => {
    let basicIngredient = html.find('input[name=\'basicIngredient\']');
    if (basicIngredient.val()!== '') {
	    PartyResources.incrementByName('Basic Ingredient', Number(basicIngredient.val()));
      }
	let specialIngredient = html.find('input[name=\'specialIngredient\']');
    if (specialIngredient.val()!== '') {
	    PartyResources.incrementByName('Special Ingredient', Number(specialIngredient.val()));
    }
  }
}).render(true);```

@davelens
Copy link
Owner

davelens commented Feb 7, 2023

@DawidIzydor There already is a public-facing API, it's outlined in the FAQ.

@DawidIzydor
Copy link
Author

That's true but this wrapper makes it more intuitive to use

@davelens
Copy link
Owner

@DawidIzydor Sorry for taking this long to respond, got a lot on my plate at the moment.

I reviewed this in more detail and will redact my previous comment. incrementByName and decrementByName can be useful in itself and they're probably a good idea to incorporate in the module. Though what I don't agree with is having two API endpoints where one contains several methods the other one doesn't have. I'm fine with having window.PartyResources as an alias to window.pr.api, but I'd aggregate incrementByName, decrementByName, _getResourceId, and getByName into window.pr.api so all API methods reside in the same class. Does that make sense to you?

@davelens davelens added the enhancement New feature or request label Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants