feat: Added docs via MkDocs

This commit is contained in:
AURUMVORXX
2024-11-04 05:09:59 +03:00
parent 810dd00dd8
commit 6a20d96bb5
21 changed files with 299 additions and 63 deletions

21
.github/workflows/docs_pages.yml vendored Normal file
View File

@@ -0,0 +1,21 @@
name: docs
on:
push:
branches:
- main
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: |
pip install mkdocs
pip install "mkdocstrings[python]"
pip install mkdocs-material
pip install mkdocs-callouts
mkdocs gh-deploy --force

View File

@@ -1,7 +0,0 @@
include:
- project: GothicMultiplayerTeam/templates
file: [squirrel-module.yml]
variables:
PROJECT_NAME: ${CI_PROJECT_NAME}
VERSION: "0.1"

View File

@@ -66,6 +66,8 @@ file(GLOB_RECURSE SOURCE
"src/*.h" "src/*.h"
"src/*.cpp" "src/*.cpp"
"src/events/*.h"
"src/events/*.cpp"
) )
# Linking directories # Linking directories

View File

@@ -0,0 +1,27 @@
# `event` onBan
!!! note
If serial/mac/ip/name indexes doesn't exist, then the parameters has not been specified when ban was added.
If timestamp doesn't exist, then ban was permanent.
This event is triggered when new ban is being added.
## Parameters
* `dict` **kwargs**:
* `str` **mac**: MAC address of the banned player.
* `str` **ip**: IP address of the banned player.
* `str` **serial**: serial of the banned player.
* `str` **name**: nickname of the banned player.
* `int` **timestamp**: timestamp when the ban expires.
## Usage
```python
import g2o
from datetime import datetime
@g2o.event('onBan')
def onBan(**kwargs):
print(f'Player {kwargs['name']} has been banned.')
if ('timestamp' in kwargs):
banExpires = datetime.fromtimestamp(kwargs['timestamp'])
print(f'Ban expires at {banExpires}')
```

View File

@@ -0,0 +1,15 @@
# `event` onExit
This event is triggered when server is going to shut down.
You can use it, to save some data before closing up, or do something else.
## Parameters
No parameters.
## Usage
```python
import g2o
@g2o.event('onExit')
def onExitEvt(**kwargs):
print('Bye')
```

View File

@@ -0,0 +1,14 @@
# `event` onInit
This event is triggered when server successfully starts up.
## Parameters
No parameters.
## Usage
```python
import g2o
@g2o.event('onInit')
def onInitEventHandler(**kwargs):
print('Called onInit event')
```

View File

@@ -0,0 +1,14 @@
# `event` onTick
This event is triggered in every server main loop iteration.
## Parameters
No parameters.
## Usage
```python
import g2o
@g2o.event('onTick')
def onTickEvt(**kwargs):
print('Tock')
```

View File

@@ -0,0 +1,20 @@
# `event` onTime
This event is triggered each time when game time minute passes.
## Parameters
* `dict` **kwargs**:
* `int` **day**: the current ingame day.
* `int` **hour**: the current ingame hour.
* `int` **min**: the current ingame minutes.
## Usage
```python
import g2o
@g2o.event('onTick')
def onTickEvt(**kwargs):
day = kwargs['day']
hour = kwargs['hour']
mins = kwargs['min']
print(f'Current time: Day {day}, Hour {hour}, Min {mins}')
```

View File

@@ -0,0 +1,23 @@
# `event` onUnban
!!! note
If serial/mac/ip/name indexes doesn't exist, then the parameters has not been specified when ban was added.
If timestamp doesn't exist, then ban was permanent.
This event is triggered when ban with specified info is being removed.
## Parameters
* `dict` **kwargs**:
* `str` **mac**: MAC address of the banned player.
* `str` **ip**: IP address of the banned player.
* `str` **serial**: serial of the banned player.
* `str` **name**: nickname of the banned player.
* `int` **timestamp**: timestamp when the ban expires.
## Usage
```python
import g2o
@g2o.event('onUnban')
def onUnban(**kwargs):
print(f'Player {kwargs['name']} has been unbanned.')
```

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -1,3 +0,0 @@
# Home
An example README that you can replace with your own content!

View File

@@ -1,7 +0,0 @@
:root {
--md-primary-fg-color: #8191ff;
}
.md-header {
background-color: #232323;
}

2
docs/events/addEvent.md Normal file
View File

@@ -0,0 +1,2 @@
# `function` addEvent
::: g2o.events.addEvent

2
docs/events/callEvent.md Normal file
View File

@@ -0,0 +1,2 @@
# `function` callEvent
::: g2o.events.callEvent

2
docs/events/event.md Normal file
View File

@@ -0,0 +1,2 @@
# `function` event
::: g2o.events.event

View File

@@ -0,0 +1,2 @@
# `function` removeEventHandler
::: g2o.events.removeEventHandler

1
docs/index.md Normal file
View File

@@ -0,0 +1 @@
# Blank

View File

@@ -1,37 +0,0 @@
site_name: Squirrel Template Module - Docs
repo_url: https://gitlab.com/GothicMultiplayerTeam/modules/squirrel-template
repo_name: Squirrel Template Module
edit_uri: ""
site_dir: "public"
extra_css:
- stylesheets/extra.css
extra:
version:
provider: mike
markdown_extensions:
- admonition
- attr_list
- pymdownx.tabbed
- pymdownx.highlight
- pymdownx.superfences
theme:
name: material
logo: assets/logo.png
icon:
repo: fontawesome/brands/gitlab
palette:
- media: "(prefers-color-scheme: light)"
scheme: default
toggle:
icon: material/eye-outline
name: Switch to dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
toggle:
icon: material/eye
name: Switch to light mode

View File

@@ -1,3 +0,0 @@
mkdocs==1.5.3
mkdocs-material==9.5.12
mike==2.0.0

View File

@@ -1,16 +1,84 @@
eventList = {} eventList = {}
def callEvent(name : str, **args : dict): def callEvent(evtName : str, **kwargs : dict):
if name in eventList: """
for event in eventList[name]: This function will notify (call) every handler bound to specified event.
event['function'](**args) Original: [callEvent](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/shared-functions/event/callEvent/)
## Declaration
```python
def callEvent(evtName : str, **kwargs : dict)
```
## Parameters
* `str` **name**: the name of the event
* `**dict` **kwargs**: the variable number of arguments.
## Usage
```python
import g2o
g2o.addEvent('testEvt')
@g2o.event('testEvt')
def onTestEvent(**kwargs):
print(f'{kwargs['name']} called my beautiful test event')
g2o.callEvent('testEvt', name = 'Diego')
```
"""
if evtName in eventList:
for event in eventList[evtName]:
event['function'](**kwargs)
def addEvent(name): def addEvent(name):
"""
This function will register a new event with specified name.
Events can be used to notify function(s) when something will happen, like player joins the server, etc.
Original: [addEvent](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/shared-functions/event/addEvent/)
## Declaration
```python
def addEvent(name)
```
## Parameters
* `str` **name**: the name of the event
## Usage
```python
import g2o
g2o.addEvent('testEvt')
```
"""
if not name in eventList: if not name in eventList:
eventList[name] = [] eventList[name] = []
def event(name : str, priority : int = 9999): def event(name : str, priority : int = 9999):
"""
This function will bind function to specified event.
Original: [addEventHandler](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/shared-functions/event/addEventHandler/)
## Declaration
```python
def event(name : str, priority : int = 9999)
```
## Parameters
* `str` **name**: the name of the event
* `int` **priority**: the function priority. The lower the value, the sooner the function/handler will be called.
## Usage
```python
import g2o
@g2o.event('onInit')
def onInitEventHandler(**kwargs):
print('Called onInit event')
```
"""
def inlineEvt(func): def inlineEvt(func):
if not name in eventList: if not name in eventList:
pass pass
@@ -20,7 +88,30 @@ def event(name : str, priority : int = 9999):
return func return func
return inlineEvt return inlineEvt
def removeEventHandler(name : str, func : int): def removeEventHandler(name : str, func : function):
"""
This function will unbind function from specified event.
Original: [removeEventHandler](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/shared-functions/event/removeEventHandler/)
## Declaration
```python
def removeEventHandler(name : str, func : function)
```
## Parameters
* `str` **name**: the name of the event
* `function` **func**: the reference to a function which is currently bound to specified event.
## Usage
```python
import g2o
@g2o.event('onTime')
def onTimeEvt(**kwargs):
print('Calling only once')
g2o.removeEventHandler('onTime', onTimeEvt)
```
"""
if not name in eventList: if not name in eventList:
pass pass
@@ -28,7 +119,7 @@ def removeEventHandler(name : str, func : int):
if item['function'] == func: if item['function'] == func:
del eventList[name][index] del eventList[name][index]
## registering all events ## registering default events
addEvent('onInit') addEvent('onInit')
addEvent('onExit') addEvent('onExit')

57
mkdocs.yml Normal file
View File

@@ -0,0 +1,57 @@
site_name: PyG2O
markdown_extensions:
- nl2br
- admonition
- pymdownx.details
- pymdownx.superfences
- sane_lists
plugins:
- mkdocstrings
- search
- callouts
repo_url: https://github.com/AURUMVORXX/PyG2O.git
nav:
- Home: index.md
- Events:
- General:
- onInit: defaultEvents/onInit.md
- onExit: defaultEvents/onExit.md
- onTick: defaultEvents/onTick.md
- onTime: defaultEvents/onTime.md
- onBan: defaultEvents/onBan.md
- onUnban: defaultEvents/onUnban.md
- Functions:
- Events:
- event: events/event.md
- removeEventHandler: events/removeEventHandler.md
- addEvent: events/addEvent.md
- callEvent: events/callEvent.md
theme:
name: material
features:
- search.suggest
- search.highlight
- content.tabs.link
- content.code.annotation
- content.code.copy
icon:
repo: fontawesome/brands/gitlab
palette:
- media: "(prefers-color-scheme: light)"
scheme: default
toggle:
icon: material/eye-outline
name: Switch to dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
toggle:
icon: material/eye
name: Switch to light mode
primary: black