Skip to content

Commit

Permalink
add syntax hilighting to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dregu committed Mar 20, 2021
1 parent c96a95e commit 37ee6e1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions docs/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def print_af(lf, af):

print('## Event functions')
print("""Define these in your script to be called on an event. For example:
```
```lua
function on_level()
toast("Welcome to the level")
end
Expand Down Expand Up @@ -207,7 +207,7 @@ def print_af(lf, af):

print('## Types')
print('Using the api through these directly is kinda dangerous, but such is life. I got pretty bored writing this doc generator at this point, so you can find the variable types in the [source files](https://github.com/spelunky-fyi/overlunky/tree/main/src/game_api). They\'re mostly just ints and floats. Example:')
print("""```
print("""```lua
-- This doesn't make any sense, as you could just access the variables directly from players[]
-- It's just a weird example OK!
ids = get_entities_by_mask(1) -- I think this just covers CHARs
Expand All @@ -232,7 +232,7 @@ def print_af(lf, af):

print('## Enums')
print('Enums are like numbers but in text that\'s easier to remember. Example:')
print("""```
print("""```lua
set_callback(function()
if state.theme == THEME.COSMIC_OCEAN then
x, y, l = get_position(players[1].uid)
Expand Down
14 changes: 7 additions & 7 deletions docs/script-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Table of strings where you should set some script metadata shown in the UI.
### [`state`](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=state)
A bunch of [game state](#statememory) variables
Example:
```
```lua
if state.time_level > 300 and state.theme == THEME.DWELLING then
toast("Congratulations for lasting 5 seconds in Dwelling")
end
Expand All @@ -38,7 +38,7 @@ An array of [Player](#player) of the current players. Pro tip: You need `players
Table of options set in the UI, added with the [register_option_functions](#register_option_int).
## Event functions
Define these in your script to be called on an event. For example:
```
```lua
function on_level()
toast("Welcome to the level")
end
Expand Down Expand Up @@ -119,7 +119,7 @@ Add a combobox option that the user can change in the UI. Read the int index of
Spawn an entity in position with some velocity and return the uid of spawned entity.
Uses level coordinates with [LAYER.FRONT](#layer) and LAYER.BACK, but player-relative coordinates with LAYER.PLAYERn.
Example:
```
```lua
-- spawn megajelly using absolute coordinates
set_callback(function()
x, y, layer = get_position(players[1].uid)
Expand Down Expand Up @@ -199,7 +199,7 @@ Get uids of entities by some conditions. Set `type` or `mask` to `0` to ignore t
#### Returns: `array<int>`
Get uids of entities matching id. This function is variadic, meaning it accepts any number of id's.
You can even pass a table! Example:
```
```lua
types = {ENT_TYPE.MONS_SNAKE, ENT_TYPE.MONS_BAT}
function on_level()
uids = get_entities_by_type(ENT_TYPE.MONS_SNAKE, ENT_TYPE.MONS_BAT)
Expand Down Expand Up @@ -305,7 +305,7 @@ Calculate the tile distance of two entities by uid
#### Returns: `float`, `float`, `float`, `float`
Basically gets the absolute coordinates of the area inside the unbreakable bedrock walls, from wall to wall. Every solid entity should be
inside these boundaries. The order is: top left x, top left y, bottom right x, bottom right y Example:
```
```lua
-- Draw the level boundaries
set_callback(function()
xmin, ymin, xmax, ymax = get_bounds()
Expand Down Expand Up @@ -356,7 +356,7 @@ Draws a filled circle on screen
Draws text on screen
## Types
Using the api through these directly is kinda dangerous, but such is life. I got pretty bored writing this doc generator at this point, so you can find the variable types in the [source files](https://github.com/spelunky-fyi/overlunky/tree/main/src/game_api). They're mostly just ints and floats. Example:
```
```lua
-- This doesn't make any sense, as you could just access the variables directly from players[]
-- It's just a weird example OK!
ids = get_entities_by_mask(1) -- I think this just covers CHARs
Expand Down Expand Up @@ -497,7 +497,7 @@ Derived from [`Entity`](#entity) [`Movable`](#movable)
- [`quest_flags`](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=quest_flags) &StateMemory::quest_flags
## Enums
Enums are like numbers but in text that's easier to remember. Example:
```
```lua
set_callback(function()
if state.theme == THEME.COSMIC_OCEAN then
x, y, l = get_position(players[1].uid)
Expand Down
8 changes: 4 additions & 4 deletions src/game_api/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ SpelunkyScript::ScriptImpl::ScriptImpl(std::string script, std::string file, boo

/// A bunch of [game state](#statememory) variables
/// Example:
/// ```
/// ```lua
/// if state.time_level > 300 and state.theme == THEME.DWELLING then
/// toast("Congratulations for lasting 5 seconds in Dwelling")
/// end
Expand Down Expand Up @@ -399,7 +399,7 @@ SpelunkyScript::ScriptImpl::ScriptImpl(std::string script, std::string file, boo
/// Spawn an entity in position with some velocity and return the uid of spawned entity.
/// Uses level coordinates with [LAYER.FRONT](#layer) and LAYER.BACK, but player-relative coordinates with LAYER.PLAYERn.
/// Example:
/// ```
/// ```lua
/// -- spawn megajelly using absolute coordinates
/// set_callback(function()
/// x, y, layer = get_position(players[1].uid)
Expand Down Expand Up @@ -458,7 +458,7 @@ SpelunkyScript::ScriptImpl::ScriptImpl(std::string script, std::string file, boo
/// Returns: `array<int>`
/// Get uids of entities matching id. This function is variadic, meaning it accepts any number of id's.
/// You can even pass a table! Example:
/// ```
/// ```lua
/// types = {ENT_TYPE.MONS_SNAKE, ENT_TYPE.MONS_BAT}
/// function on_level()
/// uids = get_entities_by_type(ENT_TYPE.MONS_SNAKE, ENT_TYPE.MONS_BAT)
Expand Down Expand Up @@ -549,7 +549,7 @@ SpelunkyScript::ScriptImpl::ScriptImpl(std::string script, std::string file, boo
/// Returns: `float`, `float`, `float`, `float`
/// Basically gets the absolute coordinates of the area inside the unbreakable bedrock walls, from wall to wall. Every solid entity should be
/// inside these boundaries. The order is: top left x, top left y, bottom right x, bottom right y Example:
/// ```
/// ```lua
/// -- Draw the level boundaries
/// set_callback(function()
/// xmin, ymin, xmax, ymax = get_bounds()
Expand Down

0 comments on commit 37ee6e1

Please sign in to comment.