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

View File

@@ -1,16 +1,84 @@
eventList = {}
def callEvent(name : str, **args : dict):
if name in eventList:
for event in eventList[name]:
event['function'](**args)
def callEvent(evtName : str, **kwargs : dict):
"""
This function will notify (call) every handler bound to specified event.
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):
"""
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:
eventList[name] = []
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):
if not name in eventList:
pass
@@ -20,7 +88,30 @@ def event(name : str, priority : int = 9999):
return func
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:
pass
@@ -28,7 +119,7 @@ def removeEventHandler(name : str, func : int):
if item['function'] == func:
del eventList[name][index]
## registering all events
## registering default events
addEvent('onInit')
addEvent('onExit')