Skip to content
Dandy edited this page Nov 20, 2024 · 5 revisions

The Shop Grid mod provides an API to allow a modder to control the 2x3 grid of potions & relics in the shop. The grid is now expandable to any size, and is paginated to allow any number of items to be shown.

Install

Subscribe to this mod in the workshop:

Add this to your pom.xml:

        <dependency>
            <groupId>shopgrid</groupId>
            <artifactId>ShopGrid</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${basedir}/../lib/ShopGrid.jar</systemPath>
        </dependency>

Don't forget to add it as a dependency in ModTheSpire.json as well.

Custom Shop Item

A CustomShopItem abstraction is available to provide a common way to create items for the shop grid. This abstraction is fully compatible with the APIs from the ShopGrid class. The base abstraction should work with no modification, but you can override the purchase() function to provide custom logic that runs when the item is successfully purchased.

public override void purchase()
    super.purchase();
    // custom logic to run when purchased
}

For compatibility, the CustomShopItem wraps around both AbstractRelic and AbstractPotion to provide a standardized class for all shop items. You can use one of these constructors to take advantage of the abstraction while still using a potion or relic class.

public CustomShopItem(AbstractRelic relic) { // there's also a constructor that takes StoreRelic
    this(new StoreRelic(relic, 0, AbstractDungeon.shopScreen));
}

public CustomShopItem(AbstractPotion potion) { // there's also a constructor that takes StorePotion
    this(new StorePotion(potion, 0, AbstractDungeon.shopScreen));
}

More notable things:

  • override applyDiscounts to change how the final price is calculated by changing this.price
  • override attemptPurchase to control the condition for buying the item

Shop Grid

The shop grid can now be any number of rows and columns, and can be composed of any number of potions, relics, or custom shop items. The following functions can be used to control the shape of the ShopGrid.

  • getCurrentPage() - gets the current active page of the grid

  • setCurrentPage(Page page) - sets the current page

  • addEmptyPage() - adds an empty page

  • addDefaultPage() - adds the default sts grid page, a 2x3 page with one row of relics and one row of potions

  • `addPage(int ... rowSizes) - adds a new page with a row for each row size provided and instantiates it with items

  • addCustomPage(String modId, int ... rowSizes) - same as above, but will tag the page with modId` so it will be separated from the other pages

  • removePage(Page page) - remove the page from the grid

  • removePage(String pageId) - remove the page from the grid

  • tryAddItem(CustomShopItem item) - tries to add the item to the grid, starting with empty slots, or when full, adding a new row or page if necessary

  • tryAddItemToCustomPage(String id, CustomShopItem item) - tries to add the item to a custom page on the grid. will not add a new page when full

  • isEmpty() - true if no items left in the grid

  • gridWidth() - returns grid width (in pixels)

  • gridHeight() - returns grid height (in pixels)

  • hide() - hides the shop grid, buttons and all

Hooks

Shop Grid adds 2 hooks to subscribe to using ShopGridInitializer.subscribe(sub);

  • PostGridInitializeSubscriber: called after the grid is initialized. use to change the initial shape of the shop grid
  • PostShopInitializeSubscriber: called after the shop is initialized. use to add more pages and such

Commands

Commands were added to the dev console. You can run shop add page 0 to add an empty page in case something overlaps that shouldn't.

Clone this wiki locally