-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayout2.py
434 lines (346 loc) · 11.6 KB
/
layout2.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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
import os
import uvicorn
from fastapi import FastAPI
from fastapi.responses import HTMLResponse, FileResponse
from fastapi.staticfiles import StaticFiles
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
app.mount("/assets", StaticFiles(directory="assets"), name="assets")
def read_file(filename: str):
with open("./static/" + filename + ".html") as f:
return f.read()
def compile_component(filename: str, *args) -> str:
with open("./components/" + filename + ".html") as f:
file = f.read()
for arg in args:
file = file.replace(arg[0], arg[1])
return file
def get_asset(filename: str, group: str):
with open("./assets/" + group + "/" + filename + ".svg") as f:
return f.read()
def color_to_variable(color_name: str) -> str:
match color_name:
case "primary":
return "oklch(var(--p))"
case "primary-content":
return "oklch(var(--pc))"
case "secondary":
return "oklch(var(--s))"
case "secondary-content":
return "oklch(var(--sc))"
case "accent":
return "oklch(var(--a))"
case "accent-content":
return "oklch(var(--ac))"
case "neutral":
return "oklch(var(--n))"
case "neutral-content":
return "oklch(var(--nc))"
case "base-100":
return "oklch(var(--b1))"
case "base-200":
return "oklch(var(--b2))"
case "base-300":
return "oklch(var(--b3))"
case "base-content":
return "oklch(var(--bc))"
case "info":
return "oklch(var(--in))"
case "success":
return "oklch(var(--inc))"
case "warning":
return "oklch(var(--wa))"
case "warning-content":
return "oklch(var(--wac))"
case "error":
return "oklch(var(--er))"
case "error-content":
return "oklch(var(--erc))"
case _:
return "oklch(var(--bc))"
def get_class_color(class_name: str):
match class_name.lower():
case "artificer":
return "sky"
case "barbarian":
return "red"
case "bard":
return "amber"
case "blood hunter":
return "rose"
case "cleric":
return "yellow"
case "druid":
return "lime"
case "fighter":
return "green"
case "monk":
return "orange"
case "paladin":
return "violet"
case "ranger":
return "emerald"
case "sorcerer":
return "blue"
case "warlock":
return "purple"
case "wizard":
return "indigo"
case _:
return "primary"
def ability_score_to_modifier(value: int):
return (value - 10) // 2
@app.get("/", response_class=HTMLResponse)
async def root():
return read_file("layout2")
@app.get("/title-card", response_class=HTMLResponse)
async def title_card():
return compile_component("title-card")
# @app.get("/player")
# async def player():
# pass
# @app.get("/player/avatar", response_class=FileResponse)
# async def player_avatar():
# with open("./assets/avatar.png") as f:
# return f
@app.get("/assets/")
@app.get("/player/name", response_class=HTMLResponse)
async def player_name():
return "George"
@app.get("/player/race", response_class=HTMLResponse)
async def player_race():
return "Human"
@app.get("/player/level", response_class=HTMLResponse)
async def player_level():
return "13"
@app.get("/player/hitpoints/max", response_class=HTMLResponse)
async def player_hitpoints_max():
return "304"
@app.get("/player/hitpoints/current", response_class=HTMLResponse)
async def player_hitpoints_current():
return "250"
@app.get("/player/hitpoints/percent", response_class=HTMLResponse)
async def player_hitpoints_percent():
return str(round((250 / 304) * 100)) + "%"
@app.get("/player/hitpoints/temp", response_class=HTMLResponse)
async def player_hitpoints_temp():
return "12"
@app.get("/player/armorclass", response_class=HTMLResponse)
async def player_armorclass():
return "20"
@app.get("/player/initiative", response_class=HTMLResponse)
async def player_initiative():
return "4"
@app.get("/player/speed/walking", response_class=HTMLResponse)
async def player_speed_walking():
return "30"
@app.get("/player/classes/{class_name}/level", response_class=HTMLResponse)
async def player_class_level(class_name: str):
return "13"
@app.get("/player/classes", response_class=HTMLResponse)
async def player_classes():
classes = [
"artificer",
# "barbarian",
# "bard",
# "cleric",
# "druid",
# "fighter",
# "monk",
# "paladin",
# "ranger",
# "rogue",
# "sorcerer",
# "warlock",
# "wizard",
]
content = ""
for player_class in classes:
content += compile_component(
"class-badge",
("{color}", get_class_color(player_class)),
("{class}", player_class.capitalize()),
("{class_lower}", player_class),
)
return content
@app.get("/player/abilities/{ability}/score", response_class=HTMLResponse)
def player_attribute(ability: str):
return str(20)
@app.get("/player/abilities/{ability}/modifier", response_class=HTMLResponse)
def player_attribute(ability: str):
return str(ability_score_to_modifier(20))
@app.get("/player/skills/{skill}/status", response_class=HTMLResponse)
def player_skill_status(skill: str):
return compile_component("skill-status-proficient")
@app.get("/player/skills/{skill}/bonus", response_class=HTMLResponse)
def player_skill_bonus(skill: str):
return "5"
@app.get("/player/senses/perception", response_class=HTMLResponse)
def player_senses_perception():
return "18"
@app.get("/player/senses/investigation", response_class=HTMLResponse)
def player_senses_perception():
return "18"
@app.get("/player/senses/insight", response_class=HTMLResponse)
def player_senses_perception():
return "18"
@app.get("/player/proficiencies/armor", response_class=HTMLResponse)
def player_proficiencies_armor():
return "None"
@app.get("/player/proficiencies/weapons", response_class=HTMLResponse)
def player_proficiencies_weapons():
return "Crossbow, Light, Dagger, Dart, Quarterstaff, Sling"
@app.get("/player/proficiencies/tools", response_class=HTMLResponse)
def player_proficiencies_tools():
return "Tinkerers' Tools, Artisan Tools"
@app.get("/player/proficiencies/languages", response_class=HTMLResponse)
def player_proficiencies_languages():
return "Abyssal, Celestial, Draconic"
@app.get("/player/actions/action", response_class=HTMLResponse)
def player_actions_action():
actions = [
{
"name": "Ray of Frost",
"type": "Cantrip - Wizard",
"range": 60,
"hitdc": 11,
"damage": {"dice": "4d8", "type": "cold"},
"notes": "V/S",
},
{
"name": "Unarmed Strike",
"type": "Melee Attack",
"range": 5,
"hitdc": 5,
"damage": {"dice": "0", "type": "bludgeoning"},
"notes": "",
},
{
"name": "Melf's Minute Meteors",
"type": "3rd Level - Wizard",
"range": "Self",
"hitdc": "DEX 14",
"damage": {"dice": "2d6", "type": "fire"},
"notes": "Concentration, V/S/M",
},
]
content = ""
for action in actions:
content += compile_component(
"actions-workspace-attack",
("{name}", action["name"]),
("{type}", action["type"]),
("{range}", str(action["range"])),
("{hitdc}", str(action["hitdc"])),
("{damage}", action["damage"]["dice"]),
("{damage_type}", action["damage"]["type"]),
("{notes}", action["notes"]),
)
return content
@app.get("/player/actions/bonusaction", response_class=HTMLResponse)
def player_actions_bonusaction():
bonus_actions = [
{
"name": "Melf's Minute Meteors",
"type": "3rd Level - Wizard",
"range": "Self",
"hitdc": "DEX 14",
"damage": {"dice": "2d6", "type": "fire"},
"notes": "Concentration, V/S/M",
}
]
content = ""
for bonus_action in bonus_actions:
content += compile_component(
"actions-workspace-attack",
("{name}", bonus_action["name"]),
("{type}", bonus_action["type"]),
("{range}", str(bonus_action["range"])),
("{hitdc}", str(bonus_action["hitdc"])),
("{damage}", bonus_action["damage"]["dice"]),
("{damage_type}", bonus_action["damage"]["type"]),
("{notes}", bonus_action["notes"]),
)
return content
@app.get("/player/actions/reaction", response_class=HTMLResponse)
def player_actions_reaction():
reactions = [
{
"name": "",
"type": "",
"range": "",
"hitdc": "",
"damage": {"dice": "", "type": ""},
"notes": "",
}
]
content = ""
for reaction in reactions:
content += compile_component(
"actions-workspace-attack",
("{name}", reaction["name"]),
("{type}", reaction["type"]),
("{range}", str(reaction["range"])),
("{hitdc}", str(reaction["hitdc"])),
("{damage}", reaction["damage"]["dice"]),
("{damage_type}", reaction["damage"]["type"]),
("{notes}", reaction["notes"]),
)
return content
@app.get("/player/actions/other", response_class=HTMLResponse)
def player_actions_other():
other_actions = [
{
"name": "",
"type": "",
"range": "",
"hitdc": "",
"damage": {"dice": "", "type": ""},
"notes": "",
}
]
content = ""
for action in other_actions:
content += compile_component(
"actions-workspace-attack",
("{name}", action["name"]),
("{type}", action["type"]),
("{range}", str(action["range"])),
("{hitdc}", str(action["hitdc"])),
("{damage}", action["damage"]["dice"]),
("{damage_type}", action["damage"]["type"]),
("{notes}", action["notes"]),
)
return content
@app.get("/player/actions/limiteduse", response_class=HTMLResponse)
def player_actions_limiteduse():
limiteduse_actions = [
{
"name": "",
"type": "",
"range": "",
"hitdc": "",
"damage": {"dice": "", "type": ""},
"notes": "",
}
]
content = ""
for action in limiteduse_actions:
content += compile_component(
"actions-workspace-attack",
("{name}", action["name"]),
("{type}", action["type"]),
("{range}", str(action["range"])),
("{hitdc}", str(action["hitdc"])),
("{damage}", action["damage"]["dice"]),
("{damage_type}", action["damage"]["type"]),
("{notes}", action["notes"]),
)
return content
if __name__ == "__main__":
app.mount("/static", StaticFiles(directory="static"), name="static")
app.mount("/assets", StaticFiles(directory="assets"), name="assets")
os.system(
"uvicorn layout2:app --reload --reload-dir static --reload-include output.css"
) # dev
# uvicorn.run(app, host="127.0.0.1", port=8000) #production