sf2.map
The story map: map pages for your battles, and the buttons and colours around them. Register a page while your mod loads, then reveal, lock or focus entries as the story moves on. Get sf2 with local sf2 = require("sf2").
sf2.map.register
Section titled “sf2.map.register”Create a map page for your battles.
Signature: sf2.map.register { id, art?, start?, underworld?, before?, secret? }
Parameters
| Parameter | Type | Required |
|---|---|---|
definition |
MapPage |
Required |
Fields of MapPage
| Field | Type | Required | Meaning |
|---|---|---|---|
id |
string |
Required | — |
art |
string|SpriteHandle |
Optional | Existing map art name, or a sprite handle for your own map picture. |
start |
boolean |
Optional | — |
underworld |
boolean |
Optional | Place the page on the Underworld (raid) map; cannot be the start zone. |
before |
string|PageHandle |
Optional | Story page this page goes directly in front of on the map, such as “core:zones/zone_1” for the left of Act 1. Story pages only. |
secret |
boolean |
Optional | Hide the page from the page strip and never open the map on it; shown even with no battles. Story pages only. |
Returns: A page handle.
When: During loading, before its battles.
local page = sf2.map.register { id = "training", art = "Map1.1" }local abyss = sf2.map.register { id = "abyss", art = sf2.assets.sprite("sprites/maps/abyss"), underworld = true,}
-- A hidden page to the left of Act 1: an empty stretch, then the page with the battle.local gap = sf2.map.register { id = "gap", art = sf2.assets.sprite("sprites/maps/void"), before = "core:zones/zone_1", secret = true,}local hideout = sf2.map.register { id = "hideout", art = sf2.assets.sprite("sprites/maps/hideout"), before = gap, secret = true,}art is existing map art or a sprite handle; the page ID is not the art filename. Story backgrounds in act order are "Map1.1", "Map1.2", "Map1.3", "Map2.4", "Map2.5", "Map2.6", "Map3.7"; raid art such as "Raid1.1" fits Underworld pages. Art is stretched to fill the page, and battle x/y are page positions, not picture pixels. An underworld page cannot also be the start page; see Underworld pages.
| Field | Default | Meaning |
|---|---|---|
before |
None | A story page (handle or ID, such as "core:zones/zone_1") that this page goes directly in front of, so it sits to that page’s left. The target must be registered already. Without before, your pages follow the campaign’s. |
secret |
false |
The page gets no dot on the strip of page dots under the map, shows no page name there, and the map never opens on it unless the player’s last fight was there. A secret page shows even when none of its battles is on the map, so it can be an empty stretch the player swipes through. Players find it only by swiping to it. |
beforeandsecretare for story pages only: not withunderworldorstart.- To place several pages, chain them: each one
beforethe next, as in the example. Several pagesbeforethe same page all end up in front of it, in no promised order. - Only the map’s order changes. Saved progress and the campaign’s acts are not affected.
- On a page with no battle shown, the battle panel and its Fight button are hidden.
sf2.map.get
Section titled “sf2.map.get”Get an existing page’s handle instead of creating one.
Signature: sf2.map.get(id)
Parameters
| Parameter | Type | Required |
|---|---|---|
id |
string |
Required |
Returns: A page handle. A missing ID is an error.
When: During loading.
local same_page = sf2.map.get("training")For another mod’s page, use its full owner:zones/id ID.
sf2.map.reveal
Section titled “sf2.map.reveal”Show a battle owned by this mod on the map, creating its saved entry.
Signature: sf2.map.reveal { battle, locked?, visible? }
Parameters
| Parameter | Type | Required |
|---|---|---|
definition |
MapBattleReveal |
Required |
Fields of MapBattleReveal
| Field | Type | Required | Meaning |
|---|---|---|---|
battle |
string|BattleHandle |
Required | One of this mod’s battles. |
locked |
boolean |
Optional | Whether a newly revealed entry appears locked. Default false. |
visible |
boolean |
Optional | Show (true) or hide (false) the entry. Omit to leave it as it is. |
Returns: true when the entry exists or was created; false if the map or battle is unavailable or input is blocked.
When: On an initialized map, or in any quest event handler such as session. Not from UI on_close.
sf2.story.on("session", function() sf2.map.reveal { battle = "training" }end)
sf2.map.reveal { battle = battle, visible = false } -- hide; lock and history stay savedRepeating a reveal keeps an existing entry’s lock, replay count and history (change the lock with sf2.map.lock). It never starts a fight or bypasses its conditions. Several reveals may be followed by one sf2.map.focus in the same callback.
sf2.map.lock
Section titled “sf2.map.lock”Lock or unlock a revealed battle owned by this mod.
Signature: sf2.map.lock { battle, locked }
Parameters
| Parameter | Type | Required |
|---|---|---|
definition |
MapBattleLock |
Required |
Fields of MapBattleLock
| Field | Type | Required | Meaning |
|---|---|---|---|
battle |
string|BattleHandle |
Required | One of this mod’s battles. |
locked |
boolean |
Required | — |
Returns: true when applied or already in that state; false if the map is unavailable, input is blocked, or the battle has no revealed entry.
When: On an initialized map, not from UI on_close.
if sf2.map.lock { battle = battle, locked = false } then sf2.ui.close(view)endOnly the lock flag changes; it does not reveal a missing entry, and unlocking does not override a fight’s other conditions. Set your own notification flags in mod state only after it returns true.
sf2.map.focus
Section titled “sf2.map.focus”Select a battle already on the current map.
Signature: sf2.map.focus(battle)
Parameters
| Parameter | Type | Required |
|---|---|---|
battle |
string|BattleHandle |
Required |
Returns: true when focused; false if the entry is missing, hidden, on the other map mode, or input is blocked.
When: On an initialized map, not from UI on_close.
if sf2.map.lock { battle = battle, locked = false } then sf2.map.focus(battle)endLocked visible entries can be focused. It does not reveal, unlock or start anything.
sf2.map.show_button
Section titled “sf2.map.show_button”Add a button to the map; clicks arrive as a map_button story event.
Signature: sf2.map.show_button { id, image, x, y, anchor_min_x?, anchor_max_x?, show_type? }
Parameters
| Parameter | Type | Required |
|---|---|---|
definition |
MapButtonDefinition |
Required |
Fields of MapButtonDefinition
| Field | Type | Required | Meaning |
|---|---|---|---|
id |
string |
Required | 1-64 lowercase letters, digits, _ or -. The game names the button <mod-id>.<id>. |
image |
SpriteHandle|string |
Required | A sprite handle or ID, or an installed Textures/ path. |
x |
number |
Required | Map X coordinate. |
y |
number |
Required | Map Y coordinate. |
anchor_min_x |
number |
Optional | 0..1, default 0.5. |
anchor_max_x |
number |
Optional | anchor_min_x..1, default 0.5. |
show_type |
"both"|"story"|"raid" |
Optional | Default “both”. |
Returns: true when added or updated; false if no profile is loaded or a change is in progress.
When: After the profile has loaded, e.g. a session handler.
sf2.story.on("session", function() sf2.map.show_button { id = "arena", image = sf2.assets.sprite("sprites/arena_button"), x = -400, y = -200 }end)sf2.story.on("map_button", function(event) if event.button == sf2.mod.id .. ".arena" then -- open an owned UI view here endend)The button is named <mod-id>.<id>, as in the event’s button field. Buttons are saved in the profile and persist until removed with sf2.map.hide_button. Showing an existing name updates it. See story events.
sf2.map.hide_button
Section titled “sf2.map.hide_button”Remove one of this mod’s map buttons.
Signature: sf2.map.hide_button(id)
Parameters
| Parameter | Type | Required |
|---|---|---|
id |
string,The id given to sf2.map.show_button. |
Required |
Returns: true when it ran (even if the button was absent); false if no profile is loaded or a change is in progress.
When: After the profile has loaded, e.g. a session handler.
sf2.story.on("session", function() sf2.map.hide_button("arena") end)sf2.map.show_underworld
Section titled “sf2.map.show_underworld”Show or hide the Underworld toggle button on the story map.
Signature: sf2.map.show_underworld(visible) -> boolean
Parameters
| Parameter | Type | Required |
|---|---|---|
visible |
boolean |
Required |
Returns: true when applied; false if the map is not ready.
When: While the map is open, e.g. scene_enter. Not from UI on_close.
sf2.story.on("scene_enter", function(event) if event.scene == "map" and not sf2.state.get("depths_found") then sf2.map.show_underworld(false) endend)The change lasts only until the map is rebuilt, so repeat it on every scene_enter and keep your own flag in mod state. It locks no battles, and it also hides the way to the game’s own raid pages. To take the player to the Underworld yourself, use sf2.map.open_underworld.
sf2.map.open_underworld
Section titled “sf2.map.open_underworld”Switch the campaign map to the Underworld, as the game’s own story does when it introduces it.
Signature: sf2.map.open_underworld() -> boolean
Returns: true when the Underworld is showing (including when it already was); false if the map is not ready.
When: While the map is open, e.g. a sequence’s on_step or on_complete. Not from UI on_close.
sf2.story.play_sequence { steps = { { act_screen = { lines = { { text = sf2.text.get("depths_title"), frames = 240 } } } }, { dialog = { lines = { { text = sf2.text.get("depths_intro") } }, button = sf2.text.get("ok") } }, }, on_step = function(index) if index == 2 then sf2.map.show_underworld(true) sf2.map.focus("fire_boss") -- one of your Underworld battles: the boss it opens on sf2.map.open_underworld() end end,}The switch is instant, like the game’s own story switch; the player’s toggle button slides instead. The Underworld opens on the boss chosen with sf2.map.focus, or on the boss the player last fought there. It does not show the toggle button, so call sf2.map.show_underworld(true) too if you hid it.
sf2.map.reveal and sf2.map.lock rebuild the map on the story side, so call this after them in the same callback. The next time the player enters the map it opens on the story map again, except when they come back from an Underworld fight.
sf2.map.underworld_colors
Section titled “sf2.map.underworld_colors”Set the Underworld map tint for normal and Power Mode.
Signature: sf2.map.underworld_colors { normal, power, duration? } -> boolean
Parameters
| Parameter | Type | Required |
|---|---|---|
definition |
UnderworldMapColors |
Required |
Fields of UnderworldMapColors
| Field | Type | Required | Meaning |
|---|---|---|---|
normal |
string |
Required | #RRGGBB or #RRGGBBAA; white preserves the map art. |
power |
string |
Required | — |
duration |
number |
Optional | 0..5 seconds, default 0.8. |
Returns: true when stored; false if the map is not ready.
When: On the map, usually scene_enter.
sf2.story.on("scene_enter", function(event) if event.scene == "map" then sf2.map.underworld_colors { normal = "#FFFFFF", power = "#BA8A82", duration = 0.8 } endend)Colors multiply the artwork, so #FFFFFF keeps the original. They last only until the map is rebuilt, so set them on every scene_enter. Purely visual: not saved, and it does not switch Power Mode.