Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Base Class Implemenations #17

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/code_structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
[class] Tree
[str] version
[dict] All Nodes (addressable by Node ID)
[dict] Selected Nodes (addressable by Node ID)
[dict] Allocated Nodes (addressable by Node ID)

[class] Player
[enum] Class Selection
Expand Down
33 changes: 33 additions & 0 deletions src/classes/Build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not work well for projects with external dependencies. The system Python interpreter is for system-level scripts. For your own applications, always use a virtual environment.


# Build Class
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider replacing this redundant comment with a module-level docstring that describes teh purpose of this module.

#
# Contains:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a table of contents, you could either use your IDE's conde structure view or extract the structure with an automatic documentation builder tool like Sphinx.

# [class] Build
# [ref] Tree
# [ref] Player

import Tree
import Player


class Build:
def __init__(self, name: str = "temp") -> None:
self.name = name
self.tree_ref = Tree.Tree()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Python, every variable is a reference to a value that lives somewhere else. Best to leave out the "ref" part, except when you would actually use weak references.

self.player_ref = Player.Player()

def __repr__(self) -> str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__repr__ functions are intended for debugging only, not for human readable display. That's what __str__ is for. See https://docs.python.org/3/library/functions.html#repr and https://docs.python.org/3/library/functions.html#str

ret_str = f"[BUILD]: '{self.name}'\n"
ret_str += f"{self.tree_ref}"
ret_str += f"{self.player_ref}"
return ret_str


def test() -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually, tests are contained in their own file hierarcy, starting from tests/ at the repository root.

build = Build()
print(build)


if __name__ == "__main__":
test()
57 changes: 57 additions & 0 deletions src/classes/Player.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3

# Player Class
#
# [class] Player
# [enum] Class Selection
# [enum] Ascendancy Selection
# [dict] Stats (e.g. Str/Dex/Int, Hit/Crit, Life/Mana,
# Block/Spell Block/Evade/Dodge, etc.)
# [dict] Item Slots
# [per slot ref] Item
# [optional list] Minions

from enum import Enum


class PlayerClasses(Enum):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider enum.IntEnum and enum.auto.

SCION = 0
MARAUDER = 1
RANGER = 2
WITCH = 3
DUELIST = 4
TEMPLAR = 5
SHADOW = 6


class PlayerAscendancy(Enum):
NONE = None


class Player:
def __init__(
self,
player_class: PlayerClasses = PlayerClasses.SCION,
ascendancy: PlayerAscendancy = PlayerAscendancy.NONE,
level: int = 1,
) -> None:
self.player_class = player_class
self.ascendancy = ascendancy
self.level = level
self.stats = dict()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider dict literals.

self.item_slots = dict()
self.minions = dict()

def __repr__(self) -> str:
ret_str = f"Level {self.level} {self.player_class.name}"
ret_str += f" {self.ascendancy.value}\n" if self.ascendancy.value else "\n"
return ret_str


def test() -> None:
player = Player()
print(player)


if __name__ == "__main__":
test()
30 changes: 30 additions & 0 deletions src/classes/Tree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python3

# Tree Class
#
# [class] Tree
# [str] version
# [dict] All Nodes (addressable by Node ID)
# [dict] Allocated Nodes (addressable by Node ID)

_VERSION_ = "3.17"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this should be a constant that is private to the module, remove the trailing underscore. Trailing underscores are usually uses to avoid name conflicts with built-ins and keywords.



class Tree:
def __init__(self, version: str = _VERSION_) -> None:
self.version = version
self.tree_nodes = dict()
self.allocated_nodes = dict()

def __repr__(self) -> str:
ret_str = f"[TREE]: version '{self.version}'\n"
return ret_str


def test() -> None:
tree = Tree()
print(tree)


if __name__ == "__main__":
test()
Empty file added src/classes/__init__.py
Empty file.