PathOfBuilding-Python icon indicating copy to clipboard operation
PathOfBuilding-Python copied to clipboard

Feat: Base Class Implemenations

Open Nostrademous opened this issue 4 years ago • 4 comments

base implemenation of some classes following code_structures.md

Nostrademous avatar Jan 27 '22 16:01 Nostrademous

Why are you using enumerations and not dictionaries

class PlayerClasses(Enum):
    SCION = 0
    MARAUDER = 1
    RANGER = 2
    WITCH = 3
    DUELIST = 4
    TEMPLAR = 5
    SHADOW = 6

I setup the colorCodes as a dictionary

colorCodes = {
    "NORMAL": "#000000",
    "MAGIC": "#8888FF",
    "RARE": "#FFFF77",

I'm not sure of the advantages of either.

X

pHiney avatar Jun 25 '22 12:06 pHiney

PEP 345 lists some reasons for using enums. Further advantages:

  • Enums have a distinct type
  • Dicts are stringly typed, so enums avoid typos
  • Enum variants are discoverable and you can auto-complete them
  • Nicer syntax: dot access vs key access; allows for automatic enumeration.
  • Stronger type guarantees for subtypes like enum.IntEnum (comparable to typing.TypedDict, but without the need for annotations)

ppoelzl avatar Jun 26 '22 13:06 ppoelzl

PEP 345 lists some reasons for using enums. Further advantages:

Currently I'm filling a combobox with

        self.colour_combo_box.addItems(color_codes.keys())

Which is super convenient. image

Whilst the color_codes naturally would be good as enums, what hoops to to go through to fill the combobox ? Or is there a different way to choose colours ?

x

pHiney avatar Jun 27 '22 12:06 pHiney

You can iterate over an enum's variants and get their names:

​self​.​colour_combo_box​.​addItems​(​[colour.name for colour in ColourCodes])

ppoelzl avatar Jun 27 '22 15:06 ppoelzl