Constructor
Shop()
Runs the moment the player enters the shop.
Most dialogue and behaviour of the shop should be defined here.
This includes (but is not limited to) defining most standard shop text (excluding TALK menu dialogue),
registering items, talk topics, configuring the Shopkeeper
, and defining the assets to use (i.e. background and music).
Methods
Shop:buyItem(current_item: Item, options)
Checks that the player meets the conditions to purchase an item, and then purchases it.
@param current_item
— The shop entry of the item being purchased.
Arguments:
current_item: Item, options | The shop entry of the item being purchased. |
Shop:drawBackground()
(Override) Draws a background for the shop.
Shop:drawBonuses(party_member: PartyMember, old_item: Item, bonuses: table, stat: string, x: number, y: number)
Used to draw the comparative bonus number for an item stat against a party member's current equipment.
Arguments:
party_member: PartyMember | The PartyMember class is a type of data class that stores information about a member of the party. |
old_item: Item | The Item class represents all types of item in Kristal. |
bonuses: table | |
stat: string | |
x: number | |
y: number |
Shop:enterSellMenu(sell_data: [string, string])
@param sell_data
— An entry in the sell_options table reflecting the storage to enter.
Arguments:
sell_data: [string, string] | An entry in the sell_options table reflecting the storage to enter. |
Shop:getState()
return #1:
| "MAINMENU" -- The state used when the player is in the Main menu.
| "BUYMENU" -- The state used when the player is in the Buy menu.
| "SELLMENU" -- The state used when the player is selecting the storage they wish to sell items from.
| "SELLING" -- The state used after the player has selected a storage and is now choosing items to sell.
| "TALKMENU" -- The state used when the player is selecting a topic to talk about in the Talk menu.
| "DIALOGUE" -- The state used when dialogue is occurring.
| "LEAVE" -- The state used to initiate leaving the shop.
| "LEAVING" -- The state used whilst the shop is transitioning out.
Returns:
1: string|"BUYMENU"|"DIALOGUE"|"LEAVE"|"LEAVING"...(+4) |
Shop:getVoicedText(text: string|string[])
Adds the voice
of the Shop to a set of dialogue texts.
Arguments:
text: string|string[] |
Returns:
1: string|string[] |
Shop:leave()
Leaves the shop with a fade out transition.
Shop:leaveImmediate()
Leaves the shop instantly, without a transition.
Shop:onEmote(emote: string)
(Override) Called whenever the [emote:...]
text tag is used in Shop dialogue. Sets the sprite of the shopkeeper.
@param emote
— The path to the image to set, or id of the animation to set.
Arguments:
emote: string | The path to the image to set, or id of the animation to set. |
Shop:onEnter()
(Override) Runs when the player enters the shop, after it has been fully initialised.
Shop:onLeave()
(Override) Called when the player selects to leave the shop from the main menu, happens at the same time the leaving dialogue begins.
Shop:onRemove(parent: Object)
(Override)
Arguments:
parent: Object | The base class of all objects in Kristal. |
Shop:onStateChange(old: string|"BUYMENU"|"DIALOGUE"|"LEAVE"|"LEAVING"...(+4), new: string|"BUYMENU"|"DIALOGUE"|"LEAVE"|"LEAVING"...(+4))
(Override)
old:
| "MAINMENU" -- The state used when the player is in the Main menu.
| "BUYMENU" -- The state used when the player is in the Buy menu.
| "SELLMENU" -- The state used when the player is selecting the storage they wish to sell items from.
| "SELLING" -- The state used after the player has selected a storage and is now choosing items to sell.
| "TALKMENU" -- The state used when the player is selecting a topic to talk about in the Talk menu.
| "DIALOGUE" -- The state used when dialogue is occurring.
| "LEAVE" -- The state used to initiate leaving the shop.
| "LEAVING" -- The state used whilst the shop is transitioning out.
new:
| "MAINMENU" -- The state used when the player is in the Main menu.
| "BUYMENU" -- The state used when the player is in the Buy menu.
| "SELLMENU" -- The state used when the player is selecting the storage they wish to sell items from.
| "SELLING" -- The state used after the player has selected a storage and is now choosing items to sell.
| "TALKMENU" -- The state used when the player is selecting a topic to talk about in the Talk menu.
| "DIALOGUE" -- The state used when dialogue is occurring.
| "LEAVE" -- The state used to initiate leaving the shop.
| "LEAVING" -- The state used whilst the shop is transitioning out.
Arguments:
old: string|"BUYMENU"|"DIALOGUE"|"LEAVE"|"LEAVING"...(+4) | |
new: string|"BUYMENU"|"DIALOGUE"|"LEAVE"|"LEAVING"...(+4) |
Shop:onTalk()
(Override) Called whenever the player enters the TALK submenu.
Shop:postInit()
A function that runs later than Shop:init()
, primarily setting up UI elements of the shop.
Code that needs access to variables such as the shop's background Sprite object that would otherwise go in Shop:init()
should go here.
Shop:registerItem(item: string|Item, options: (table|"bonuses"|"color"|"description"|"flag"...(+3))?)
Adds an item to the shop at the next available index.
@param item
— An Item
instance or the id of an item to add to the shop.
@param options
— An optional list of properties that can be defined for this item in the shop, overriding the default values set on the item:
@return success
— Whether the item was successfully added to the shop.
options:
| "name" -- The name of the item shown in the shop.
| "description" -- The description of the item shown in the shop
| "price" -- The price of the item in this shop
| "bonuses" -- The preview stat bonuses provided by the item (does not affect actual item stat bonuses)
| "color" -- The color of the item name text
| "flag" -- The name of a flag used to store the remaining stock of this item. Defaults to `stock_<index>_<item.id>`
| "stock" -- The default number of stock of this item. Infinite if unspecified.
Arguments:
item: string|Item | An |
options: (table|"bonuses"|"color"|"description"|"flag"...(+3))? | An optional list of properties that can be defined for this item in the shop, overriding the default values set on the item: |
Returns:
success: boolean | Whether the item was successfully added to the shop. |
Shop:registerTalk(talk: string, color: [number, number, number, number?]?)
Registers a talk topic that will appear in the TALK submenu.
@param talk
— The name of the topic.
@param color
— The color that the topic name will appear as. Defaults to white.
Arguments:
talk: string | The name of the topic. |
color: [number, number, number, number?]? | The color that the topic name will appear as. Defaults to white. |
Shop:registerTalkAfter(talk: string, index: integer, flag: string?, value: any, color: [number, number, number, number?]?)
Registers a talk topic that will appear in the TALK submenu when specific conditions are met.
By default, the new topic will appear after the current topic at index
has been chosen once.
@param talk
— The name of the topic.
@param index
— The index that will be replaced with this topic.
@param flag
— The name of the flag that will be checked against to determine when the topic should be replaced.
@param value
— The value the flag should be at for the topic to be replaced.
@param color
— The color that the topic name will appear as. Defaults to yellow.
Arguments:
talk: string | The name of the topic. |
index: integer | The index that will be replaced with this topic. |
flag: string? | The name of the flag that will be checked against to determine when the topic should be replaced. |
value: any | The value the flag should be at for the topic to be replaced. |
color: [number, number, number, number?]? | The color that the topic name will appear as. Defaults to yellow. |
Shop:replaceItem(index: integer, item: string|Item, options: (table|"bonuses"|"color"|"description"|"flag"...(+3))?)
Adds or replaces an item in the shop.
@param index
— The index in the shop which this item should appear at.
@param item
— An Item
instance or the id of an item to add to the shop.
@param options
— An optional list of properties that can be defined for this item in the shop, overriding the default values set on the item:
@return success
— Whether the item was successfully added to the shop.
options:
| "name" -- The name of the item shown in the shop.
| "description" -- The description of the item shown in the shop
| "price" -- The price of the item in this shop
| "bonuses" -- The preview stat bonuses provided by the item (does not affect actual item stat bonuses)
| "color" -- The color of the item name text
| "flag" -- The name of a flag used to store the remaining stock of this item. Defaults to `stock_<index>_<item.id>`
| "stock" -- The default number of stock of this item. Infinite if unspecified.
Arguments:
index: integer | The index in the shop which this item should appear at. |
item: string|Item | An |
options: (table|"bonuses"|"color"|"description"|"flag"...(+3))? | An optional list of properties that can be defined for this item in the shop, overriding the default values set on the item: |
Returns:
success: boolean | Whether the item was successfully added to the shop. |
Shop:replaceTalk(talk: string, index: integer, color: [number, number, number, number?]?)
Replaces one talk topic with another.
@param talk
— The name of the topic.
@param index
— The index that will be replaced with this topic.
@param color
— The color that the topic name will appear as. Defaults to yellow.
Arguments:
talk: string | The name of the topic. |
index: integer | The index that will be replaced with this topic. |
color: [number, number, number, number?]? | The color that the topic name will appear as. Defaults to yellow. |
Shop:sellItem(current_item: Item)
Arguments:
current_item: Item | The Item class represents all types of item in Kristal. |
Shop:setDialogueText(text: string|string[], no_voice: boolean?)
Arguments:
text: string|string[] | |
no_voice: boolean? |
Shop:setRightText(text: string|string[], no_voice: boolean?)
Arguments:
text: string|string[] | |
no_voice: boolean? |
Shop:setState(state: "BUYMENU"|"DIALOGUE"|"LEAVE"|"LEAVING"|"MAINMENU"...(+3), reason: any)
Changes the shop to a new state.
@param state
— The new state of the shop.
@param reason
— Additional information that the new state needs, if required:
- SELLING - The selected entry of the
sell_options
table in SELLMENU. - TALKMENU - An optional
"DIALOGUE"
string literal to indicate that the user has returned from the"DIALOGUE"
state.
state:
| "MAINMENU" -- The state used when the player is in the Main menu.
| "BUYMENU" -- The state used when the player is in the Buy menu.
| "SELLMENU" -- The state used when the player is selecting the storage they wish to sell items from.
| "SELLING" -- The state used after the player has selected a storage and is now choosing items to sell.
| "TALKMENU" -- The state used when the player is selecting a topic to talk about in the Talk menu.
| "DIALOGUE" -- The state used when dialogue is occurring.
| "LEAVE" -- The state used to initiate leaving the shop.
| "LEAVING" -- The state used whilst the shop is transitioning out.
Arguments:
state: "BUYMENU"|"DIALOGUE"|"LEAVE"|"LEAVING"|"MAINMENU"...(+3) | The new state of the shop. |
reason: any | Additional information that the new state needs, if required: |
Shop:startDialogue(text: string|string[], callback: (string|fun())?)
Starts a dialogue with the shopkeeper, setting the state to DIALOGUE
. Use this function inside of Shop:startTalk(topic)
.
@param text
— One or more lines of dialogue, supporting Text Commands. Additionally supports the command [emote:name]
which will cause the Shopkeeper's sprite to change to the sprite specified by name
and onEmote()
to run.
@param callback
— As a function, this argument is called when the dialogue finishes. If it returns true
, the shop state will not reset when the dialogue finishes. As a string, the shop is set to this state when the dialogue finishes.
Arguments:
text: string|string[] | One or more lines of dialogue, supporting Text Commands. Additionally supports the command |
callback: (string|fun())? | As a function, this argument is called when the dialogue finishes. If it returns |
Shop:startTalk(talk: string)
(Override) Runs every time the player selects a topic in the TALK menu. \
Call Shop:startDialogue()
from within this function with text appropriate to the selected topic.
@param talk
— The name of the Topic that the player selected.
Arguments:
talk: string | The name of the Topic that the player selected. |
Fields
Shop.background: string
The filepath of the background texture for this shop, relative to assets/sprites
Shop.background_sprite: Sprite
The Sprite instance used to control the background. Not defined in Shop:init()
.
Shop.hide_price: boolean
Whether item prices should be hidden (Defaults to false
)
Shop.hide_storage_text: boolean
Whether the shop should hide the text showing your remaining storage text (Defaults to false
)
Shop.items: table
A table of items that the shop offers. Should be set through Shop:registerItem()
Shop.leave_options: number, y|"left"|"right"| boolean }
A table defining what will happen when the player leaves the shop.
The keys map
(target map name), x
and y
OR marker
(target position in map), facing
, (player facing direction in map), menu
(return to main menu) can be defined for this table.
Shop.music: Music
The Music
instance used to control the shop's music
Shop.sell_options: table<[string, string]>
A table defining the options that will be displayed when in the SELL menu of the shop (State SELLMENU
).
Each entry in this table should be a two string table, defining the name of the option first,
followed by the name of the item storage that should be opened to sell from after.
Shop.sell_options_text: string, weapons
Defines the text shown when in each of the different SELL submenus.
The keys items
, weapons
, armors
, and storage
can be defined for this table.
Shop.shop_music: string
The filepath of the song to play in this shop, relative to assets/music
Shop.stat_icons: love.Image, magic
A table defining the stat icons used when previewing items in this shop.
Shop.state: string|"BUYMENU"|"DIALOGUE"|"LEAVE"|"LEAVING"...(+4)
The current state of the shop, should only be set using Shop:setState()
.
Shop.state_reason: any
The current reason for the state of the shop, should only be set using Shop:setState()
.
Shop.talk_replacements: table
A table of topics that will replace other topics once they have been chosen. Should be set through Shop:registerTalkAfter()
Shop.talks: table
A table of topics available in the TALK menu. Should be set through Shop:registerTalk()
Shop.voice: string
The filepath of the voice sound to use for the shop, relative to assets/sounds/voice
.
Undocumented
Shop.current_selecting_choice: integer
self.current_selecting will be in use... so let's just add another????????
Shop.item_current_selecting: integer
Oh my god
Shop.large_box: unknown
Construct the UI
Shop.main_current_selecting: integer
This'll be a separate variable because it keeps track of what you selected between main menu options. This can normally be done with hardcoded position sets, like in other places, but in the Spamton shop in Deltarune, SELL is replaced with BUYMORE!!!, and when you exit out of that menu, it places you on the correct menu option.
Shop.sell_current_selecting: integer
Same here too...