refactor: Some functions now returns tuple for better unpacking

This commit is contained in:
AURUMVORXX
2025-05-26 20:50:45 +03:00
parent ef61bd6b78
commit f3eeb1e2b9
4 changed files with 46 additions and 44 deletions

View File

@@ -5,7 +5,6 @@ def get_call_repr():
func_name = frame.f_code.co_name
args_info = inspect.getargvalues(frame)
# Формируем аргументы в виде строки
args_str = []
for arg in args_info.args:
val = args_info.locals[arg]

View File

@@ -1,5 +1,6 @@
from ..server import PythonWebsocketServer
from ..call_repr import get_call_repr
from typing import Optional
async def getHostname() -> str:
"""
@@ -157,23 +158,23 @@ async def getServerWorld() -> str:
result = await server.make_request(data)
return result
async def getTime() -> dict:
async def getTime() -> tuple:
"""
The function is used to get the path of the default world on the server.
Original: [getTime](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/server-functions/game/getTime/)
## Declaration
```python
async def getTime() -> dict
async def getTime() -> tuple
```
## Returns
`dict {day, hour, min}`: The current time in the game.
`tuple (day, hour, min)`: The current time in the game.
"""
data = f'return {get_call_repr()}'
server = await PythonWebsocketServer.get_server()
result = await server.make_request(data)
return result
return (result['day'], result['hour'], result['min'])
async def serverLog(text : str):
"""

View File

@@ -1,5 +1,6 @@
from ..server import PythonWebsocketServer
from ..call_repr import get_call_repr
from typing import Optional
async def addBan(info : dict) -> bool:
"""
@@ -192,25 +193,25 @@ async def getPlayerArmor(id : int) -> str:
result = await server.make_request(data)
return result
async def getPlayerAtVector(id : int) -> dict:
async def getPlayerAtVector(id : int) -> Optional[tuple]:
"""
This function will get player at vector.
Original: [getPlayerAtVector](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/server-functions/player/getPlayerAtVector/)
## Declaration
```python
getPlayerAtVector(id : int) -> dict
getPlayerAtVector(id : int) -> Optional[tuple]
```
## Parameters
`int` **id**: the player id.
## Returns
`dict {x, y, z}`: the player at vector.
`tuple (x, y, z)`: the player at vector.
"""
data = f'return {get_call_repr()}'
server = await PythonWebsocketServer.get_server()
result = await server.make_request(data)
return result
return (result['x'], result['y'], result['z']) if result is not None else None
async def getPlayerBelt(id : int) -> str:
"""
@@ -232,25 +233,25 @@ async def getPlayerBelt(id : int) -> str:
result = await server.make_request(data)
return result
async def getPlayerCameraPosition(id : int) -> dict:
async def getPlayerCameraPosition(id : int) -> Optional[tuple]:
"""
This function will get the player camera position in world.
Original: [getPlayerCameraPosition](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/server-functions/player/getPlayerCameraPosition/)
## Declaration
```python
getPlayerCameraPosition(id : int) -> dict
getPlayerCameraPosition(id : int) -> Optional[tuple]
```
## Parameters
`int` **id**: the player id.
## Returns
`dict {x, y, z}`: the dictionary that represents camera position.
`tuple (x, y, z)`: the dictionary that represents camera position.
"""
data = f'return {get_call_repr()}'
server = await PythonWebsocketServer.get_server()
result = await server.make_request(data)
return result
return (result['x'], result['y'], result['z']) if result is not None else None
async def getPlayerCollision(id : int) -> bool:
"""
@@ -272,25 +273,25 @@ async def getPlayerCollision(id : int) -> bool:
result = await server.make_request(data)
return result
async def getPlayerColor(id : int) -> dict:
async def getPlayerColor(id : int) -> Optional[tuple]:
"""
This function will get the player nickname color.
Original: [getPlayerColor](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/server-functions/player/getPlayerColor/)
## Declaration
```python
async def getPlayerColor(id : int) -> dict
async def getPlayerColor(id : int) -> Optional[tuple]
```
## Parameters
`int` **id**: the player id.
## Returns
`dict {r, g, b}`: the player nickname color.
`tuple (r, g, b)`: the player nickname color.
"""
data = f'return {get_call_repr()}'
server = await PythonWebsocketServer.get_server()
result = await server.make_request(data)
return result
return (result['r'], result['g'], result['b']) if result is not None else None
async def getPlayerContext(id : int, type : int) -> int:
"""
@@ -638,25 +639,25 @@ async def getPlayerPing(id : int) -> int:
result = await server.make_request(data)
return result
async def getPlayerPosition(id : int) -> dict:
async def getPlayerPosition(id : int) -> Optional[tuple]:
"""
This function will get the player world position.
Original: [getPlayerPosition](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/server-functions/player/getPlayerPosition/)
## Declaration
```python
async def getPlayerPosition(id : int) -> dict
async def getPlayerPosition(id : int) -> Optional[tuple]
```
## Parameters
`int` **id**: the player id.
## Returns
`dict {x, y, z}`: the player world position.
`tuple (x, y, z)`: the player world position.
"""
data = f'return {get_call_repr()}'
server = await PythonWebsocketServer.get_server()
result = await server.make_request(data)
return result
return (result['x'], result['y'], result['z']) if result is not None else None
async def getPlayerRangedWeapon(id : int) -> str:
"""
@@ -719,25 +720,25 @@ async def getPlayerRing(id : int, handId : int) -> str:
result = await server.make_request(data)
return result
async def getPlayerScale(id : int) -> dict:
async def getPlayerScale(id : int) -> Optional[tuple]:
"""
This function will get the player scale.
Original: [getPlayerScale](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/server-functions/player/getPlayerScale/)
## Declaration
```python
async def getPlayerScale(id : int) -> dict
async def getPlayerScale(id : int) -> Optional[tuple]
```
## Parameters
`int` **id**: the player id.
## Returns
`dict {x, y, z}`: the player scale.
`tuple (x, y, z)`: the player scale.
"""
data = f'return {get_call_repr()}'
server = await PythonWebsocketServer.get_server()
result = await server.make_request(data)
return result
return (result['x'], result['y'], result['z']) if result is not None else None
async def getPlayerSerial(id : int) -> str:
"""
@@ -907,25 +908,25 @@ async def getPlayerVirtualWorld(id : int) -> int:
result = await server.make_request(data)
return result
async def getPlayerVisual(id : int) -> dict:
async def getPlayerVisual(id : int) -> Optional[tuple]:
"""
This function will get the player visual.
Original: [getPlayerVisual](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/server-functions/player/getPlayerVisual/)
## Declaration
```python
async def getPlayerVisual(id : int) -> dict
async def getPlayerVisual(id : int) -> Optional[tuple]
```
## Parameters
`int` **id**: the player id.
## Returns
`dict {bodyModel, bodyTxt, headModel, headTxt}`: player visual.
`tuple (bodyModel, bodyTxt, headModel, headTxt)`: player visual.
"""
data = f'return {get_call_repr()}'
server = await PythonWebsocketServer.get_server()
result = await server.make_request(data)
return result
return (result['bodyModel'], result['bodyTxt'], result['headModel'], result['headTxt']) if result is not None else None
async def getPlayerWeaponMode(id : int) -> int:
"""
@@ -1481,7 +1482,7 @@ async def setPlayerName(id : int, name : str) -> bool:
result = await server.make_request(data)
return result
async def setPlayerPosition(id : int, x : float, y : float, z : float):
async def setPlayerPosition(id : int, x : float, y : float, z : float) -> Optional[tuple]:
"""
!!! note
This functions supports ``pass_exception: bool`` optional argument for manual handling exceptions.
@@ -1490,7 +1491,7 @@ async def setPlayerPosition(id : int, x : float, y : float, z : float):
## Declaration
```python
async def setPlayerPosition(id : int, x : float, y : float, z : float)
async def setPlayerPosition(id : int, x : float, y : float, z : float) -> Optional[tuple]
```
## Parameters
`int` **id**: the player id.
@@ -1498,13 +1499,13 @@ async def setPlayerPosition(id : int, x : float, y : float, z : float):
`float` **y**: the position in the world on the y axis.
`float` **z**: the position in the world on the z axis.
OR
`dict[str, float]` **pos**: the position in the world on the XYZ axis.
`tuple(x, y, z)` **pos**: the position in the world on the XYZ axis.
"""
data = f'return {get_call_repr()}'
server = await PythonWebsocketServer.get_server()
result = await server.make_request(data)
return result
return (result['x'], result['y'], result['z']) if result is not None else None
async def setPlayerRespawnTime(id : int, respawnTime : int):
"""
@@ -1527,7 +1528,7 @@ async def setPlayerRespawnTime(id : int, respawnTime : int):
result = await server.make_request(data)
return result
async def setPlayerScale(id : int, x : float, y : float, z : float):
async def setPlayerScale(id : int, x : float, y : float, z : float) -> Optional[tuple]:
"""
!!! note
This functions supports ``pass_exception: bool`` optional argument for manual handling exceptions.
@@ -1536,7 +1537,7 @@ async def setPlayerScale(id : int, x : float, y : float, z : float):
## Declaration
```python
async def setPlayerScale(id : int, x : float, y : float, z : float)
async def setPlayerScale(id : int, x : float, y : float, z : float) -> Optional[tuple]
```
## Parameters
`int` **id**: the player id.
@@ -1544,13 +1545,13 @@ async def setPlayerScale(id : int, x : float, y : float, z : float):
`float` **y**: the scale factor on y axis.
`float` **z**: the scale factor on z axis.
OR
`dict[str, float]` **pos**: the scale factor on the XYZ axis.
`tuple(x, y, z)` **pos**: the scale factor on the XYZ axis.
"""
data = f'return {get_call_repr()}'
server = await PythonWebsocketServer.get_server()
result = await server.make_request(data)
return result
return (result['x'], result['y'], result['z']) if result is not None else None
async def setPlayerSkillWeapon(id : int, skillId : int, percentage : int):
"""

View File

@@ -1,14 +1,15 @@
from ..server import PythonWebsocketServer
from ..call_repr import get_call_repr
from typing import Optional
async def getNearestWaypoint(world : str, x : int, y : int, z : int) -> dict:
async def getNearestWaypoint(world : str, x : int, y : int, z : int) -> Optional[tuple]:
"""
This function is used to retrieve the information about nearest waypoint from the specified position.
Original: [getNearestWaypoint](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/server-functions/waypoint/getNearestWaypoint/)
## Declaration
```python
async def getNearestWaypoint(world : str, x : int, y : int, z : int) -> dict
async def getNearestWaypoint(world : str, x : int, y : int, z : int) -> Optional[tuple]
```
## Parameters
`str` **world**: the world name in which the waypoint exists.
@@ -16,22 +17,22 @@ async def getNearestWaypoint(world : str, x : int, y : int, z : int) -> dict:
`int` **y**: the position in the world on the y axis.
`int` **z**: the position in the world on the z axis.
## Returns
`dict {name, x, y, z}`: Waypoint information.
`tuple (name, x, y, z)`: Waypoint information.
"""
data = f'return {get_call_repr()}'
server = await PythonWebsocketServer.get_server()
result = await server.make_request(data)
return result
return (result['name'], result['x'], result['y'], result['z']) if result is not None else None
async def getWaypoint(world : str, name : str) -> dict:
async def getWaypoint(world : str, name : str) -> Optional[tuple]:
"""
This function is used to retrieve the position of specified waypoint.
Original: [getWaypoint](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/server-functions/waypoint/getWaypoint/)
## Declaration
```python
async def getWaypoint(world : str, name : str) -> dict
async def getWaypoint(world : str, name : str) -> Optional[tuple]
```
## Parameters
`str` **world**: the world name in which the waypoint exists.
@@ -43,4 +44,4 @@ async def getWaypoint(world : str, name : str) -> dict:
server = await PythonWebsocketServer.get_server()
result = await server.make_request(data)
return result
return (result['x'], result['y'], result['z']) if result is not None else None