-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilterFactory.py
More file actions
175 lines (146 loc) · 5.05 KB
/
Copy pathFilterFactory.py
File metadata and controls
175 lines (146 loc) · 5.05 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/python3
from PoEInfos import FILTER as f
def buildArgumentString(argList):
argString = ""
for arg in argList:
if " " in arg:
argString += " \"" + arg + "\""
else:
argString += " " + arg
return argString
def buildConditionString(condition, argList):
return condition + " "*(len(f.ACTION.BACKGROUND_COLOR)-len(condition)+2) + buildArgumentString(argList)
def colorPartToString(part):
s = str(part)
return "0"*(3-len(s)) + s
def colorToString(color):
return map(colorPartToString, color)
class ItemFilter:
def __init__(self, name, version=None, information=[]):
self.name = name
self.indent = 0
self.header = f.COMMENT*(len(name)+6) + "\n"
self.header += f.COMMENT + " "*(len(name)+4) + f.COMMENT + "\n"
self.header += f.COMMENT + " " + name + " " + f.COMMENT
if version:
self.header += " " + version
self.header += "\n"
self.header += f.COMMENT + " "*(len(name)+4) + f.COMMENT + "\n"
self.header += f.COMMENT*(len(name)+6) + "\n\n"
if information:
for info in information:
self.header += f.COMMENT + " " + info + "\n"
self.header += "\n"
self.content = ""
self.contConditions = []
def __str__(self):
return self.header + self.content
def beginContinuousCondition(self, condition):
if condition in self.contConditions:
print("Warning: \"" + condition + "\" is already in continuous condition and will not be added (again).")
return
self.contConditions.append(condition)
def endContinuousCondition(self, condition):
if condition not in self.contConditions:
print("Warning: \"" + condition + "\" is not in continuous conditions and could not be removed.")
return
self.contConditions.remove(condition)
def beginContinuousConditions(self, conditions):
for condition in conditions:
self.beginContinuousCondition(condition)
def endContinuousConditions(self, conditions):
for condition in conditions:
self.endContinuousCondition(condition)
def addLine(self, line="", comment=False):
if not line:
self.content += "\n"
return
self.content += "\t"*self.indent
if comment:
self.content += f.COMMENT + " "
self.content += line + "\n"
def addBlock(self, name, conditions, appearance, doShow=True, doContinue=False, comments=[]):
if doShow:
blockType = f.SHOW
else:
blockType = f.HIDE
self.addLine(blockType + " " + f.COMMENT + " " + name)
self.indent += 1
for comment in comments:
self.addLine(f.COMMENT + " " + comment)
for condition in self.contConditions + conditions:
self.addLine(condition)
self.addLine(f.COMMENT)
for line in appearance.toLines():
self.addLine(line)
if doContinue:
addLine(f.CONTINUE)
self.indent -= 1
def write(self, prefix = "", suffix = ""):
f = open(self.name + ".filter", "w+")
if prefix != "":
f.write(prefix + "\n\n\n\n")
f.write(str(self) + "\n")
if suffix != "":
f.write("\n\n\n" + suffix + "\n")
f.close()
class Display:
def __init__(self, textColor, backgroundColor, borderColor, fontSize):
self.textColor = textColor
self.backgroundColor = backgroundColor
self.borderColor = borderColor
self.fontSize = fontSize
def toLines(self):
lines = []
lines.append(buildConditionString(f.ACTION.TEXT_COLOR, colorToString(self.textColor)))
lines.append(buildConditionString(f.ACTION.BACKGROUND_COLOR, colorToString(self.backgroundColor)))
lines.append(buildConditionString(f.ACTION.BORDER_COLOR, colorToString(self.borderColor)))
lines.append(buildConditionString(f.ACTION.FONT_SIZE, [str(self.fontSize)]))
return lines
class Effect:
def __init__(self, color, temp=False):
self.color = color
self.temp = temp
def toLine(self):
argList = [self.color]
if self.temp:
argList.append(f.TEMP_EFFECT)
return buildConditionString(f.ACTION.EFFECT, argList)
class Icon:
def __init__(self, size, color, shape):
self.size = str(size)
self.color = color
self.shape = shape
def toLine(self):
return buildConditionString(f.ACTION.ICON, [self.size, self.color, self.shape])
class Sound:
def __init__(self, sound=""):
self.sound = sound
def toLine(self):
if self.sound == "":
return None
if self.sound == None:
return f.ACTION.NO_SOUND
return buildConditionString(f.ACTION.CUSTOM_SOUND, [self.sound])
class Appearance:
NO_ICON = buildConditionString(f.COMMENT + " " + f.ACTION.ICON, ["None"])
NO_EFFECT = buildConditionString(f.COMMENT + " " + f.ACTION.EFFECT, ["None"])
def __init__(self, display, effect=None, icon=None, sound=Sound()):
self.display = display
self.effect = effect
self.icon = icon
self.sound = sound
def toLines(self):
lines = self.display.toLines()
if not self.effect:
lines.append(Appearance.NO_EFFECT)
else:
lines.append(self.effect.toLine())
if not self.icon:
lines.append(Appearance.NO_ICON)
else:
lines.append(self.icon.toLine())
soundLine = self.sound.toLine()
if soundLine:
lines.append(soundLine)
return lines