Skip to content

Beaver's System Interface

AngryBeaver edited this page Dec 30, 2023 · 28 revisions

actorComponentListAdd

Component can be negative

  • functionality: Add components to actor
  • return: void can throw Error e.g. when result is negative
    • Promise<void>
  • usage:
await beaversSystemInterface.actorComponentListAdd(actor, componentList);
  • bsa-x: not needed.
  • typescript
actorComponentListAdd:(actor,componentList: Component[])=>Promise<ItemChange>;

actorCurrenciesAdd

Currencies can be negative.

  • functionality: add Currencies to the actor
  • return: void but may throw an error e.g. if result is not valid.
    • Promise<void>
  • usage:
await beaversSystemInterface.actorCurrenciesAdd(actor, currencies);
  • bsa-x: optional
actorCurrenciesAdd(actor, currencies: Currencies): Promise<void> {
   ...        
}
  • default: works on systems where all currencies are items (uuid is set)

actorCurrenciesCanAdd

Currencies can be negative.

  • functionality: tests if an actor can currencies without any error e.g. result is not negative.
  • return: true if the system allows this transaction.
    • boolean
  • usage:
const canAddCurrencies = beaversSystemInterface.actorCurrenciesCanAdd(actor, currencies);
  • bsa-x: not needed.
  • typescript
actorCurrenciesCanAdd:(actor, currencies: Currencies)=>boolean;

actorCurrenciesGet

  • functionality: transforms the actor currencies into a system independent representation of currencies
  • return: system independent representation of currencies
  • usage:
const currencies = await beaversSystemInterface.actorCurrenciesGet(actor);
  • bsa-x: optional
actorCurrenciesGet(actor): Currencies {
   ...
}
  • default: works on systems where all currencies are items (uuid is set)

actorRollAbility

  • functionality: lets an actor roll on an ability
  • return: the roll
    • Promise<Roll>
  • usage:
const roll = await beaversSystemInterface.actorRollAbility(actor,abilityId);
  • bsa-x:
async actorRollAbility(actor, abilityId:string) {
  return ...
}
  • known problems: some modules change the outcome of a roll your module has to take care about that if it wants to support those modules.

actorRollSkill

  • functionality: lets an actor roll on a skill
  • return: the roll
    • Promise<Roll>
  • usage:
const roll = await beaversSystemInterface.actorRollSkill(actor,skillId);
  • bsa-x:
async actorRollSkill(actor, skillId:sting) {
  return ...
}
  • known problems: some modules change the outcome of a roll your module has to take care about that if it wants to support those modules.

actorRollTool

  • functionality: lets an actor roll on a tool
  • return: the roll
    • Promise<Roll>
  • usage:
const roll = await beaversSystemInterface.actorRollTool(actor,item);
  • bsa-x:
async actorRollTool(actor, item) {
  return ...
}
  • known problems: some modules change the outcome of a roll your module has to take care about that if it wants to support those modules.

actorSheetAddTab

  • functionality: Adds a Tab to the actorSheet
  • return: void
    • void
  • usage:
const sheet=app //provided by SheetApp sheet==app
const html //provided by SheetApp
const actor //actor of the Sheet
const tabData={
  id:string //identity of your tab
  label: string // name presentation of your tab
  html: string // html representation of your tab e.g. <i class="fa-light fa-rocket"></i>
}
const tabBody=$(await renderTemplate());( //the content of your tab usually something your rendered
await beaversSystemInterface.actorSheetAddTab(sheet, html, actor, tabData, tabBody);
  • bsa-x:
actorSheetAddTab(sheet, html, actor, tabData: { id: string, label: string, html: string }, tabBody:string): void {

}

configAbilities

  • functionality: none
  • return: a list of Abilities available
  • usage:
const abilityList= beaversSystemInterface.configAbilities;
  • bsa-x:
get configAbilities() {
 return ...
}

configCanRollAbility

  • functionality: none
  • return: true when your system knows how to roll on an ability
    • boolean
  • usage:
const canRollAbility = beaversSystemInterface.configCanRollAbility;
  • bsa-x:
get configCanRollAbility() {
 return ...
}

configCurrencies

This is for the one! main currencySystem only e.g. do not mix Dollar and Euro.

  • functionality: none
  • return: a list of Currencies available.
  • usage:
const currencyList= beaversSystemInterface.configCurrencies;
  • bsa-x: the label returened should be language dependent !
get configCurrencies() {
 return ...
}

configLootItemType

  • functionality: none
  • return: the item type that is used for loot/money/treasure items.
    • string
  • usage:
const lootItemType= beaversSystemInterface.configLootItemType;
  • bsa-x:
get configLootItemType() {
 return ...
}

configSkills

  • functionality: none
  • return: a list of Skills available
  • usage:
const skillList= beaversSystemInterface.configSkills;
  • bsa-x:
get configSkills() {
 return ...
}

componentCreate

can be also be used to clone Components

  • functionality: creates a Component from given data
  • return: Component
  • usage:
await beaversSystemInterface.componentCreate(data);
  • bsa-x: not needed
  • typescript
componentCreate:(data) => Component;

componentDefaultData

  • functionality: none
  • return: default component data for this system e.g. defines any special keys
  • usage: you mostlikley wont use it directly
componentData = mergeObject(beaversSystemInterface.componentDefaultData, data, {insertKeys: false});
  • bsa-x: optional
get componentDefaultData(): ComponentData {
  return {
                id: "invalid",
                uuid: "invalid",
                img: "invalid",
                type: "invalid",
                name: "invalid",
                quantity: 1,
                itemType: undefined,
            }
}
  • default: works on systems that do not need any additional ComponentKeys

componentFromEntity

  • functionality: creates a Component from foundry document
  • return: Component
  • usage:
const item = fromUuid(itemUuid);
await beaversSystemInterface.componentFromEntity(item );
  • bsa-x: optional
componentFromEntity(entity: any, hasJsonData: boolean = false): Component {
  const data = {
                id: entity.id,
                uuid: entity.uuid,
                img: entity.img,
                name: entity.name,
                type : entity.documentName,
                quantity: entity[beaversSystemInterface.itemQuantityAttribute] || 1,
                itemType: entity.documentName === "Item" ? entity.type : undefined,
                jsonData: hasJsonData? entity.toObject() : undefined
  }
  return beaversSystemInterface.componentCreate(data);
}
  • default: works on systems that do not need any additional ComponentKeys

componentIsSame

  • functionality: checks if two components are same not identical (e.g. uuids are not required to match)
  • return: true if they are detected the same
    • boolean
  • usage: usually this is used inside of Component.isSame
beaversSystemInterface.componenentIsSame(componentA,ComponentB);
//or simplified: componentA.isSame(componentB);
  • bsa-x: optional if you need to define a special rule
componentIsSame(a: ComponentData, b: ComponentData): boolean {
            const isSameName = a.name === b.name;
            const isSameType = a.type === b.type;
            const isSameItemType = a.itemType === b.itemType;
            return isSameName && isSameType && isSameItemType;
}
  • default: two components are identical when they match in name, type and itemType

currenciesToLowestValue

  • functionality: transform Currencies to number representation of lowest value.
  • return: void
    • void
  • usage:
await beaversSystemInterface.currenciesToLowestValue(currencies);
  • bsa-x: not needed
  • typescript
currenciesToLowestValue: (currencies: Currencies)=>number;

currencyToCurrencies

  • functionality: transform number representation of lowest value Currency to Currencies
  • return: Currencies upcasted to the highest Currency value possible
  • usage:
await beaversSystemInterface.currenciesToLowestValue(currencies);
  • bsa-x: not needed
  • typescript
currencyToCurrencies: (lowestValue: number)=>Currencies;

itemListComponentFind

  • functionality: find a component in a List of Items
  • return: Matching Components in List and acuumulated quantity
    • {components:Component[],quantity:number}
  • usage:
await beaversSystemInterface.itemListComponentFind(itemList, component: ComponentData);
  • bsa-x: not needed.
  • typescript
itemListComponentFind:(itemList,component: ComponentData)=>{components:Component[],quantity:number};

itemPriceAttribute

  • functionality: none
  • return: attribute path to find price on item
    • string
  • usage:
const price = item[beaversSystemInterface.itemPriceAttribute];
  • bsa-x:
get itemQuantityAttribute(): string {
  ...
}

itemSheetReplaceContent

  • functionality: replace the main content in an item sheet
  • return: void
    • void
  • usage:
const app //provided by SheetApp
const html //provided by SheetApp
const element= $(await renderTemplate());( //the content of your sheet
beaversSystemInterface.itemSheetReplaceContent(app, html, element);
  • bsa-x: optional
itemSheetReplaceContent(app, html, element): void {
   html.find(".sheet-body").empty();
   html.find(".sheet-body").append(element);
}

itemQuantityAttribute

  • functionality: none
  • return: attribute path to find quantity on item
    • string
  • usage:
const price = item[beaversSystemInterface.itemQuantityAttribute];
  • bsa-x:
get itemQuantityAttribute(): string {
  ...
}

uuidToDocument

  • functionality: get the Document to an uuid //same as fromUuid() but works on Compendiums too
  • return: entity
    • Promise<foundry.abstract.Document<any, any>>
  • usage:
const entity = await beaversSystemInterface.uuidToDocument(uuid);
  • bsa-x: not needed
  • typescript
 uuidToDocument: (string)=>Promise<foundry.abstract.Document<any, any>>

objectAttributeGet

  • functionality: gets an attribute on an object (works also for doted attributes)
  • return: attributeValue
    • any
  • usage:
const entity = { system: {quantity: 10}};
const value = beaversSystemInterface(entity,"system.quantity"); //10
  • bsa-x: not needed
  • typescript
objectAttributeGet:(obj:any, attribute:string, fallback?:string)=>any,

objectAttributeSet

  • functionality: sets an attribute on an object (works also for doted attributes). This is similar to setProperties default Helper of foundry except this will also create the required path while foundry helpe stops on first unknown attribute and only create this.

  • return: void

    • void
  • usage:

const entity = { a: {b: "c"}};
beaversSystemInterface(entity,"a.d","e"); // {a:{b:"c",d:"e"}}
  • bsa-x: not needed
  • typescript
objectAttributeSet:(obj:any, attribute:string, value)=>void,

tokenMovementCreate (v2.1.4)

  • functionality: creates a tokenMovementInstance to controll the movement of a token. With this your token moves smoothly around. e.g. it does not teleport the token instantly to the next grid and it does not wait for the token to acutally move visible to the next grid it stores your movement activity while the token visually moves to that position how ever long it takes to do this.
  • return: TokenMovementInstance
    • TokenMovementInstance
  • usage:
const tokenMovement = beaversSystemInterface.tokenMovementCreate("#uuidOfAnActor");
tokenMovement.move(1,1);
  • bsa-x: not needed
  • typescript
tokenMovementCreate:(actorId:string)=>TokenMovementInstance,

uiDialogSelect

  • functionality: promts for a selection choice
  • return: choice
    • Promise<string>
  • usage:
const selection = await beaversSystemInterface.uiDialogSelect({
    choices:[
    {text:"Carpenter's Tools:8",img:".."},
    {text:"Cartographer's Tools:8",img:".."},
    {text:"Weaver's Tools:8",img:".."},
    {text:"Alchemist's Supplies:8",img:".."}
  ]
});

img.png

  • bsa-x: not needed
  • typescript
uiDialogSelect: (data: SelectData)=>Promise<string>;

see also customElement beavers-selection