Skip to content

Commit

Permalink
[GL] doc(Engine): add documentation for Engine functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Insineer committed Sep 14, 2019
1 parent 0e74e83 commit 8a78eb9
Show file tree
Hide file tree
Showing 6 changed files with 560 additions and 9 deletions.
107 changes: 106 additions & 1 deletion GameLogic/Engine/Geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,32 @@
from typing import List

class Vector2D:
"""
Vector2D Class
Attributes
----------
x, y: float
vector coordinates
Methods
-------
Magnitude() -> float
count vector's length
Normalize() -> Vector2D
get unit vector with same direction
Direction() -> Direction
get Direction where vector is directed (1 direction of 8 options)
Angle() -> float
get vector's angle from the x-axis
Rotate(angleToRotate: float) -> Vector2D
create vector rotated by given angle relatively initial
"""
def __init__(self, x, y):
self.x = x
self.y = y
Expand All @@ -28,7 +54,7 @@ def Direction(self) -> Direction:
return eVec2f(self.x, self.y).GetDirection()

def Angle(self) -> float:
"""Returns the angle of this vector from the x axis"""
"""Returns the angle of this vector from the x-axis"""
return atan2(self.y, self.x)

def Rotate(self, angleToRotate: float) -> Vector2D:
Expand Down Expand Up @@ -90,6 +116,23 @@ def _FromEngineVec(cls, engineVec):


class Vector:
"""
Vector Class
Attributes
----------
x, y, z: float
vector coordinates
Methods
-------
Magnitude() -> float
count vector's length
Normalize() -> Vector
get unit vector with same direction
"""
def __init__(self, x=0, y=0, z=0):
self.x = x
self.y = y
Expand Down Expand Up @@ -163,6 +206,10 @@ def __FromEngineVec(cls, engineVec):


class Direction(eDirection):
"""
Direction enumeration
8 existing world directions, Center and None
"""
NONE = eDirection.NONE
SOUTH = eDirection.SOUTH
WEST = eDirection.WEST
Expand All @@ -176,14 +223,72 @@ class Direction(eDirection):


def DirectionToVect(dir: Direction) -> Vector2D:
"""Cast Direction to Vector2D
Attributes
----------
dir: Direction
Direction to be casted to Vector2D
Returns
-------
Vector2D
resulted vector
all coordinates equal one of {-1, 0, 1}
Example:
-------
DirectionToVect(Direction.NORTH_EAST) -> Vector2D(1, 1)
"""
return Vector2D._FromEngineVect(eDirectionToVect(dir))


def InvertDirection(dir: Direction) -> Direction:
"""Invert Direction
Parameters
----------
dir: Direction
Direction to be inverted
Returns
-------
Direction
opposite direction (mirrored)
Example:
-------
InvertDirection(Direction.NORTH_EAST) -> Directon.SOUTH_WEST
"""
return eInvertDirection(dir)


class DirectionSet(eDirectionSet):
"""
A class used to represent a set of directions. You can add directions and check which are already added.
Any composite direction will be broken to its components.
Methods
-------
Add(List[Direction])
Add directions from list to set. With composite direction both components will be added.
Remove(List[Direction])
Remove list of directions from set. For composite direction, it's components will be removed.
DoesExistOne(List[Direction]) -> bool
Check if one of directions is exist in set.
DoExistAll(List[Direction]) -> bool
Check if all of directions are exist in set.
Reset()
Remove all directions from set.
"""

def __init__(self, impl = eDirectionSet()):
self._impl = impl

Expand Down
1 change: 1 addition & 0 deletions GameLogic/Engine/Hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
from Objects.Creatures.Ghost import Ghostize

def OnPlayerJoined(player: Player):
"""is called by Engine on player join to game"""
print(player.ckey + " has joined! Yay!")
player.AddVerb("ghost", Ghostize)
7 changes: 7 additions & 0 deletions GameLogic/Engine/Map.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
from Objects.Turfs.Airlock import Airlock

def FillMap(map):
"""
FillMap is called by Engine when map is created
You can add any map generation logic here
"""

for i in range(45, 56):
for j in range(45, 56):
CreateObject("Objects.Turfs.Floor", map.GetTile(Vector(i, j, 0)))
Expand Down
82 changes: 74 additions & 8 deletions GameLogic/Engine/Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
from typing import Callable

class Game(eGame):
"""
Game object.
Note: Use gGame global instance!
Attributes
----------
world: World
Game's world
Read-only
"""

def __init__(self, impl):
self._impl = impl

Expand All @@ -15,13 +28,54 @@ def world() -> World:
return World(eGGame.world)

class VerbsHolder(eVerbsHolder):
"""
Inheritance from this class allow to define special actions without
arguments which can be called with command from console
VerbsHolder is registrated with unique name, so player can call it's verbs.
For example, class Player registrated with name "Player".
So player's verb "Drop" can be called with next command: "Player.Drop"
Methods
-------
AddVerb(name: str, action: Callable[[], None])
add new verb
Parametres
----------
name: str
verb's key. Use name to call verb from console
"""

def __init__(self, impl):
self._impl = impl

def AddVerb(self, name: str, action: Callable[[], None]):
self._impl.AddVerb(name, action)

class Player(ePlayer, VerbsHolder):
"""
Player class is persistent until restart. When player re-logins, existed Player instance is used.
Attributes
----------
ckey: str
client key, nickname
Read-only
control: Control
control component used by player for creature controlling
Methods
-------
IsConnected() -> bool
returns True when player is online
"""

def __init__(self, impl):
VerbsHolder.__init__(self, impl)

Expand All @@ -32,7 +86,6 @@ def ckey(self) -> str:
@property
def control(self) -> Control:
return Control(self._impl.control)

@control.setter
def control(self, value):
self._impl.control.fset(value)
Expand All @@ -42,20 +95,33 @@ def IsConnected(self) -> bool:


class ResourceManager(eResourceManager):
"""
Class for resources management
Note: Use gRM global instance!
Methods
-------
GetIcon(title: str, state: ItemSpriteState) -> eIcon
returns icon object by it's string id and state
"""

def __init__(self, impl):
self._impl = impl

def GetIcon(self, title: str, state: ItemSpriteState) -> eIcon:
return self._impl.GetIcon(title, state)


class ItemSpriteState(eItemSpriteState):
""" Enumeration of icon states"""
DEFAULT = eItemSpriteState.DEFAULT """default icon"""
ON_MOB = eItemSpriteState.ON_MOB """is being weared by creature"""
IN_HAND_LEFT = eItemSpriteState.IN_HAND_LEFT """is being holded in left hand"""
IN_HAND_RIGHT = eItemSpriteState.IN_HAND_RIGHT """is being holded in right hand"""


gServer = eGServer
gGame = Game(eGGame)
gRM = ResourceManager(eGServer.RM)


class ItemSpriteState(eItemSpriteState):
DEFAULT = eItemSpriteState.DEFAULT
ON_MOB = eItemSpriteState.ON_MOB
IN_HAND_LEFT = eItemSpriteState.IN_HAND_LEFT
IN_HAND_RIGHT = eItemSpriteState.IN_HAND_RIGHT
13 changes: 13 additions & 0 deletions GameLogic/Engine/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,17 @@
from Engine_Server import eGGame

def spawn(delay: timedelta, activity: Callable[[], None]) -> None:
"""
Schedule delayed activity
Parameteres
-----------
delay: timedelta
time do activity will be called
activity: Callable[[], None]
activity which should be called
"""

eGGame.AddDelayedActivity(delay, activity)
Loading

0 comments on commit 8a78eb9

Please sign in to comment.