-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph_object.py
62 lines (44 loc) · 1.26 KB
/
graph_object.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import pygame
from abc import ABCMeta
class GraphObject(metaclass=ABCMeta):
def __init__(self):
pass
def draw(self, surface):
pass
def update(self):
pass
def get_event(self, ev):
pass
class Selectable (metaclass=ABCMeta):
selections = []
def __new__(cls, *args, **kwargs):
if not hasattr(cls, "selections"):
setattr(cls, "selections", [])
return super().__new__(cls)
def __init__(self):
self.__selected = False
@property
def selected(self):
return self.__selected
@property
def selection_exists(self):
return len(self.__class__.selections) > 0
def select(self):
if self in self.__class__.selections:
return
self.__class__.selections.append(self)
self.__selected = True
def deselect(self):
if self not in self.__class__.selections:
return
self.__class__.selections.remove(self)
self.__selected = False
def get_event(self, ev):
if ev.type == pygame.KMOD_CTRL & pygame.K_d:
self.__class__.selections.clear()
class Storage:
def __init__(self, obj, fields):
self.obj = obj
self.fields = fields
def fetch(self):
pass