Skip to content

Commit

Permalink
Merge pull request #36 from avrae/limiteduse-builder
Browse files Browse the repository at this point in the history
Add LimitedUse gamedata endpoint
  • Loading branch information
zhudotexe authored Jun 2, 2021
2 parents b8eb053 + 18ee7e8 commit 4d0088a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 14 deletions.
2 changes: 2 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from blueprints.characters import characters
from blueprints.customizations import customizations
from blueprints.discord import discord
from blueprints.gamedata import gamedata
from blueprints.homebrew.items import items
from blueprints.homebrew.spells import spells
from blueprints.workshop import workshop
Expand Down Expand Up @@ -97,6 +98,7 @@ def roll():
app.register_blueprint(customizations, url_prefix="/customizations")
app.register_blueprint(bot, url_prefix="/bot")
app.register_blueprint(discord, url_prefix="/discord")
app.register_blueprint(gamedata, url_prefix="/gamedata")
app.register_blueprint(items, url_prefix="/homebrew/items")
app.register_blueprint(spells, url_prefix="/homebrew/spells")
app.register_blueprint(workshop, url_prefix="/workshop")
Expand Down
1 change: 1 addition & 0 deletions blueprints/characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def srd_attacks():
return jsonify(_items)


# ==== helpers ====
class ValidationError(Exception):
pass

Expand Down
28 changes: 28 additions & 0 deletions blueprints/gamedata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Misc endpoints to return gamedata (e.g. entitlements, limited uses)
"""
from flask import Blueprint, request

from gamedata.compendium import compendium
from lib.utils import success

gamedata = Blueprint('gamedata', __name__)


@gamedata.route("entitlements", methods=["GET"])
def get_entitlements():
"""
Gets a dict of all valid entitlements.
Query: free: bool - include free entities?
{type-id -> entitlement}
"""
if 'free' in request.args:
return success({f"{t}-{i}": sourced.to_dict() for (t, i), sourced in compendium.entitlement_lookup.items()})
return success({f"{t}-{i}": sourced.to_dict() for (t, i), sourced in compendium.entitlement_lookup.items() if
not sourced.is_free})


@gamedata.route("limiteduse", methods=["GET"])
def get_limited_use():
"""Returns a list of valid entities for use in building an AbilityReference in the automation builder."""
return success(compendium.raw_limiteduse)
13 changes: 0 additions & 13 deletions blueprints/workshop.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,19 +530,6 @@ def get_guild_subscriptions(guild_id):


# ---- other ----
@workshop.route("entitlements", methods=["GET"])
def get_entitlements():
"""
Gets a dict of all valid entitlements.
Query: free: bool - include free entities?
{type-id -> entitlement}
"""
if 'free' in request.args:
return success({f"{t}-{i}": sourced.to_dict() for (t, i), sourced in compendium.entitlement_lookup.items()})
return success({f"{t}-{i}": sourced.to_dict() for (t, i), sourced in compendium.entitlement_lookup.items() if
not sourced.is_free})


@workshop.route("tags", methods=["GET"])
def get_tags():
tags = current_app.mdb.workshop_tags.find()
Expand Down
2 changes: 2 additions & 0 deletions gamedata/compendium.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self):
self.raw_races = [] # type: list[dict]
self.raw_subraces = [] # type: list[dict]
self.raw_spells = [] # type: list[dict]
self.raw_limiteduse = [] # type: list[dict]

# models
self.backgrounds = [] # type: list[Sourced]
Expand Down Expand Up @@ -55,6 +56,7 @@ def load_all_mongodb(self, mdb):
self.raw_races = lookup.get('races', [])
self.raw_subraces = lookup.get('subraces', [])
self.raw_spells = lookup.get('spells', [])
self.raw_limiteduse = lookup.get('limiteduse', [])

def load_common(self):
self.entitlement_lookup = {}
Expand Down
7 changes: 6 additions & 1 deletion lib/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class SpellSlotReference(BaseModel):
slot: conint(ge=1, le=9)


class AbilityReference(BaseModel):
id: int
typeId: int


# ---- effects ----
class Effect(BaseModel, abc.ABC):
type: str
Expand Down Expand Up @@ -130,7 +135,7 @@ class Condition(Effect):

class UseCounter(Effect):
type: Literal['counter']
counter: Union[SpellSlotReference, str255]
counter: Union[SpellSlotReference, AbilityReference, str255]
amount: str255
allowOverflow: Optional[bool]
errorBehaviour: Optional[Literal['warn', 'raise']]
Expand Down

0 comments on commit 4d0088a

Please sign in to comment.