drakosfire commited on
Commit
1830328
1 Parent(s): 3ee2b47

Added owner loop to add owner/s title, and loop through building owner blocks

Browse files
Files changed (1) hide show
  1. block_builder.py +86 -486
block_builder.py CHANGED
@@ -3,8 +3,10 @@ import utilities as u
3
  import os
4
  import ast
5
 
 
6
  block_id = 0
7
 
 
8
  def build_blocks(user_input, block_id):
9
  list_of_blocks = []
10
  title_block = build_title_block(user_input['store_name'], user_input['store_description'], user_input['store_backstory'], user_input['store_reputation'])
@@ -26,16 +28,34 @@ def build_blocks(user_input, block_id):
26
  block_id= block_id)
27
  block_id = block_id + 1
28
  list_of_blocks.append(store_properties_block)
 
29
  # Iterate over owners and generate owner image and details block
 
 
 
 
 
30
  for owner in user_input['store_owners']:
31
- owner_block = build_owner_block(owner, block_id)
 
 
 
 
32
  block_id = block_id + 1
33
  list_of_blocks.append(owner_block)
34
-
35
-
36
-
37
-
38
  return list_of_blocks
 
 
 
 
 
 
 
 
 
 
 
39
  def process_iterable_into_html(iterable_type, iterable, block_id):
40
  iterable_html = f""""""
41
  for item in iterable:
@@ -43,13 +63,39 @@ def process_iterable_into_html(iterable_type, iterable, block_id):
43
  <td align="left"><strong>{iterable_type}</strong></td>
44
  <td align="right"><textarea class="string-action-description-textarea" id="user-store-owners-{block_id}"
45
  hx-post="/update-stats" hx-trigger="change" hx-target="#user-store-owners-{block_id}t" hx-swap="outerHTML"
46
- title="Store Size">{item['name']}</textarea></td>
47
  </tr>"""
48
  iterable_html += item_html
49
  return iterable_html
50
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  def build_title_block(title,description,backstory,reputation):
52
- title_block_html = f"""<div class="block-item" data-block-id = {block_id}><h1><textarea class="title-textarea" id="user-store-title" hx-post="/update-stats" hx-trigger="change" hx-target="#user-store-name" hx-swap="outerHTML" title="Name of store">{title}</textarea></h1><div contenteditable="true" class="description-textarea" id="user-store-description"
 
 
53
  hx-post="/update-stats" hx-trigger="change"
54
  hx-target="#user-monster-description" hx-swap="outerHTML"
55
  title="Any amount or style of description">
@@ -57,7 +103,7 @@ def build_title_block(title,description,backstory,reputation):
57
  </div> """
58
 
59
  return title_block_html
60
-
61
  def build_image_block(sd_prompt, block_id):
62
  image_block_html = f"""
63
  <div class="block-item" data-block-id="{block_id}">
@@ -70,7 +116,8 @@ def build_image_block(sd_prompt, block_id):
70
  """
71
 
72
  return image_block_html
73
- # Break each part of properties into segments, add to list, loop over possible multiple owners, servies, specialties, employees, and rumors
 
74
  def build_store_properties_block(store_type,
75
  store_size,
76
  store_hours,
@@ -82,7 +129,7 @@ def build_store_properties_block(store_type,
82
  store_reputation,
83
  store_rumors,
84
  block_id):
85
-
86
  store_properties_base_html = f"""
87
  <div class="block-item" data-block-id="{block_id}">
88
  <div class="block classTable frame decoration">
@@ -134,36 +181,11 @@ def build_store_properties_block(store_type,
134
  </tr> """
135
  store_owners = []
136
  store_employees = []
137
-
138
-
139
- def process_rumors_into_html(rumors, block_id):
140
- rumors_html = f""""""
141
- for rumor in rumors:
142
- rumor_html = f"""<tr>
143
- <td align="left"><strong>Store Rumors</strong></td>
144
- <td align="right"><textarea class="string-action-description-textarea" id="user-store-rumors-{block_id}"
145
- hx-post="/update-stats" hx-trigger="change" hx-target="#user-store-rumors-{block_id}t" hx-swap="outerHTML"
146
- title="Store Size">{rumor}</textarea></td>
147
- </tr>"""
148
- rumors_html += rumor_html
149
- return rumors_html
150
-
151
  owners_html = process_iterable_into_html('Store Owners', store_owners, block_id)
152
  employees_html = process_iterable_into_html('Store Employees', store_employees, block_id)
153
  store_specialties_html = process_iterable_into_html('Store Specialties', store_specialties, block_id)
154
  store_services_html = process_iterable_into_html('Store Services', store_services, block_id)
155
- def process_secrets_into_html(secrets, block_id):
156
- secrets_html = f""""""
157
- for secret in secrets:
158
- secret_html = f"""<tr>
159
- <td align="left"><strong>Secrets</strong></td>
160
- <td align="right"><textarea class="string-action-description-textarea" id="user-store-rumors-{block_id}"
161
- hx-post="/update-stats" hx-trigger="change" hx-target="#user-store-rumors-{block_id}t" hx-swap="outerHTML"
162
- title="Store Size">{secret}</textarea></td>
163
- </tr>"""
164
- secrets_html += secret_html
165
- return secrets_html
166
-
167
  store_iterables_html = f"""
168
  {owners_html}
169
  {employees_html}
@@ -187,19 +209,26 @@ def build_store_properties_block(store_type,
187
  {store_iterables_html}
188
  {store_end_html}"""
189
  return store_properties_block_html
190
-
191
- def build_owner_block(owner, owner_id,block_id):
192
- # Owner block with values : Name, Race, Class, Description, Personality, Secrets, sd-prompt
193
- owner_name_html = process_iterable_into_html('Owner', [owner['name']], block_id)
194
- owner_race_html = process_iterable_into_html('Race', [owner['race']], block_id)
195
- owner_class_html = process_iterable_into_html('Class', [owner['class']], block_id)
196
- owner_description_html = process_iterable_into_html('Description', [owner['description']], block_id)
197
- owner_personality_html = process_iterable_into_html('Personality', [owner['personality']], block_id)
198
- owner_secrets_html = process_iterable_into_html('Secrets', [owner['secrets']], block_id)
199
- owner_block_html = f"""
200
- <div class="block-item" data-block-id="{block_id}">
201
- <h3 id="owner_{owner_id}">F{owner['name']}</h3>
202
- <table>
 
 
 
 
 
 
 
203
  <thead>
204
  <tr>
205
  <th align="center"></th>
@@ -207,447 +236,18 @@ def build_owner_block(owner, owner_id,block_id):
207
  </tr>
208
  </thead>
209
  <tbody>
210
- <tr>
211
- <td align="center"><strong>Species</strong></td>
212
- <td align="right">{owner['species']}</td>
213
- </tr>
214
- <tr>
215
- <td align="center"><strong>Class</strong></td>
216
- <td align="right">{owner['class']}</td>
217
- </tr>
218
- <tr>
219
- <td align="center"><strong>Description</strong></td>
220
- <td align="left">{}</td>
221
- </tr>
222
- <tr>
223
- <td align="center"><strong>Personality</strong></td>
224
- <td align="left">Joyful, playful, and a tad mischievous.</td>
225
- </tr>
226
- <tr>
227
- <td align="center"><strong>Secrets</strong></td>
228
- <td align="left">Fizzwidget once performed a jester act for the Queen of Faerun.<br> He has a hidden collection of practical jokes for special customers.</td>
229
- </tr>
230
  </tbody>
231
  </table>
232
  </div>
233
  """
234
- def list_names_to_str(data):
235
- list_of_names = []
236
- for i in data:
237
- list_of_names.append(i['name'])
238
- str_of_names = ', '.join(list_of_names)
239
- return str_of_names
240
 
241
- def list_to_str(list):
242
- str_of_list = ', '.join(list)
243
- return str_of_list
244
- def build_owners_section(owners_list):
245
- owner_s = 'Owner'
246
- if len(owners_list) > 1 :
247
- owner_s = 'Owners'
248
- owner_section_html = f"""<h2 id="owner">{owner_s}</h2> """
249
- # iterating through list of owners, each is a dictionary with descriptive qualities
250
- for owner in range(len(owners_list)) :
251
- secrets = '<br> '.join(owners_list[owner - 1]['secrets'])
252
- owner_section_html += f"""
253
- <h3 id="owner_{owner}">{owners_list[owner - 1]['name']}</h3>
254
- <table>
255
- <thead>
256
- <tr>
257
- <th align="center"></th>
258
- <th align="center"></th>
259
- </tr>
260
- </thead>
261
- <tbody>
262
- <tr>
263
- <td align="center"><strong>Species</strong></td>
264
- <td align="right">{owners_list[owner - 1]['species']}</td>
265
- </tr>
266
- <tr>
267
- <td align="center"><strong>Class</strong></td>
268
- <td align="right">{owners_list[owner - 1]['class']}</td>
269
- </tr>
270
- <tr>
271
- <td align="center"><strong>Description</strong></td>
272
- <td align="left">{owners_list[owner - 1]['description']}.</td>
273
- </tr>
274
- <tr>
275
- <td align="center"><strong>Personality</strong></td>
276
- <td align="left">{owners_list[owner - 1]['personality']}</td>
277
- </tr>
278
- <tr>
279
- <td align="center"><strong>Secrets</strong></td>
280
- <td align="left">{secrets}</td>
281
- </tr>
282
- </tbody>
283
- </table>
284
- """
285
- return owner_section_html
286
-
287
-
288
-
289
- store_image_url = ""
290
-
291
-
292
- # Assigning strings to variables for replacing location of dependencies for the webpage to local static folders
293
- # Path is ../../ for the html files location in output/dated_folder/
294
-
295
- def build_html_base(store_dict) :
296
 
297
- base_dir = os.path.dirname(os.path.abspath(__file__))
298
- dependencies_path = os.path.relpath(os.path.join(base_dir, "dependencies"), os.path.join(base_dir, "output", "test"))
299
-
300
-
301
- # Template for the page
302
- html_file_as_text = f"""<!DOCTYPE html>
303
- <html>
304
- <head>
305
- <link href="{dependencies_path}/all.css" rel="stylesheet" />
306
- <link href="{dependencies_path}/css.css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css" />
307
- <link href="{dependencies_path}/bundle.css" rel="stylesheet" />
308
- <link rel="icon" href="{dependencies_path}/favicon.ico" type="image/x-icon" />
309
- <link href="{dependencies_path}/style.css" rel="stylesheet" />
310
- <link href="{dependencies_path}/5ePHBstyle.css" rel="stylesheet" />
311
- <title>{store_dict['store_name']}</title>
312
- </head>
313
- <body>
314
- <div>
315
- <div class="brewRenderer" style="height: 692px;">
316
- <div class="pages" lang="en">
317
- <div class="page" id="p1">
318
- <div class="columnWrapper">
319
- <h1 id="store_name">{store_dict['store_name']}</h1>
320
- <p>{store_dict['store_description']}</p>
321
- <p>{store_dict['store_backstory']}</p>
322
- <p>{store_dict['store_reputation']}</p>
323
- <!-- Generated Image of Shop -->
324
- <p><img class="" style="width:300px; mix-blend-mode:multiply;" src="{store_image_url}" alt="{store_dict['store_name']}"></p>
325
- <div class="block classTable frame decoration">
326
- <table>
327
- <thead>
328
- <tr>
329
- <th align="left"></th>
330
- <th align="center"></th>
331
- <th align="center"></th>
332
- </tr>
333
- </thead>
334
- <tbody>
335
- <tr>
336
- <td align="left"><strong>Size</strong></td>
337
- <td align="right">{store_dict['store_size']}</td>
338
- </tr>
339
- <tr>
340
- <td align="left"><strong>Town</strong></td>
341
- <td align="right">{store_dict['store_location']['town']}</td>
342
- </tr>
343
- <tr>
344
- <td align="left"><strong>District</strong></td>
345
- <td align="right">{store_dict['store_location']['district']}</td>
346
- </tr>
347
- <tr>
348
- <td align="left"><strong>Street</strong></td>
349
- <td align="right">{store_dict['store_location']['street']}</td>
350
- </tr>
351
- <tr>
352
- <td align="left"><strong>Type</strong></td>
353
- <td align="right">{store_dict['store_type']}</td>
354
- </tr>
355
- <tr>
356
- <td align="left"><strong>Owners</strong></td>
357
- <td align="right">{list_names_to_str(store_dict['store_owners'])}</td>
358
- </tr>
359
- <tr>
360
- <td align="left"><strong>Employees</strong></td>
361
- <td align="right">{list_names_to_str(store_dict['store_employees'])}</td>
362
- </tr>
363
- <tr>
364
- <td align="left"><strong>Store Hours</strong></td>
365
- <td align="right">{store_dict['store_hours']}</td>
366
- </tr>
367
- <tr>
368
- <td align="left"><strong>Services</strong></td>
369
- <td align="right">{list_names_to_str(store_dict['store_services'])}</td>
370
- </tr>
371
- <tr>
372
- <td align="left"><strong>Specialties</strong></td>
373
- <td align="right">{list_names_to_str(store_dict['store_specialties'])}</td>
374
- </tr>
375
- <tr>
376
- <td align="left"><strong>Reputation</strong></td>
377
- <td align="right">{store_dict['store_reputation']}</td>
378
- </tr>
379
- <tr>
380
- <td align="left"><strong>Rumors</strong></td>
381
- <td align="right">{list_to_str(store_dict['store_rumors'])}</td>
382
- </tr>
383
- </tbody>
384
- </table>
385
- </div>
386
- <p><img class="" style="width:300px; mix-blend-mode:multiply;" src="https://media.githubusercontent.com/media/Drakosfire/StoreGenerator/master/galleries/test_images/Morgor_bloodclaw.png" alt="{store_dict['store_owners'][0]['name']}"></p>
387
- {build_owners_section(store_dict['store_owners'])}
388
-
389
-
390
- <p>&nbsp;</p>
391
- <div class="columnSplit"></div>
392
- <p>&nbsp;</p>
393
- </div>
394
- </div>
395
- <div class="page" id="p2">
396
- <div class="columnWrapper">
397
- <div class="blank"></div>
398
- <h2 id="employees">Employees</h2>
399
-
400
- <h3 id="brega">Brega</h3>
401
- <p><img class="" style="width:150px; mix-blend-mode:multiply;" src="https://media.githubusercontent.com/media/Drakosfire/StoreGenerator/master/galleries/test_images/Brega.png" alt="Brega"></p>
402
 
403
- <table>
404
- <thead>
405
- <tr>
406
- <th align="center"></th>
407
- <th align="center"></th>
408
- </tr>
409
- </thead>
410
- <tbody>
411
- <tr>
412
- <td align="center"><strong>Species</strong></td>
413
- <td align="center">Half-Orc</td>
414
- </tr>
415
- <tr>
416
- <td align="center"><strong>Class</strong></td>
417
- <td align="center">Assistant Butcher</td>
418
- </tr>
419
- <tr>
420
- <td align="center"><strong>Description</strong></td>
421
- <td align="center">A burly half-orc with a kind face and a perpetual smudge of blood on his cheek. Brega handles the heavy lifting and cutting of larger beasts.</td>
422
- </tr>
423
- <tr>
424
- <td align="center"><strong>Personality</strong></td>
425
- <td align="center">Soft-spoken and gentle despite his imposing appearance, Brega is loyal to Morgor and respects his cunning. He has a soft spot for stray animals.</td>
426
- </tr>
427
- </tbody>
428
- </table>
429
-
430
- <div class="block">
431
- <h1 id="notable-customers">Notable Customers</h1>
432
- <div class="block note">
433
- <h3 id="lord-vittorio-blackthorn">Lord Vittorio Blackthorn</h3>
434
- <p>An eccentric noble known for his extravagant feasts featuring rare and exotic meats.</p>
435
- <p>Lord Blackthorn’s patronage lends an air of mystery and prestige to Morgor’s shop, attracting curious gourmands and shady characters alike.</p>
436
- </div>
437
- <h1 id="related-quests">Related Quests</h1>
438
- <h3 id="the-basilisk-bounty">The Basilisk Bounty</h3>
439
- <p>Morgor needs fresh basilisk meat and offers a handsome reward for those brave enough to hunt one.</p>
440
- <p>500 gold coins and choice cuts of meat.</p>
441
- </div>
442
-
443
-
444
- <div class="columnSplit"></div>
445
- <div class="block">
446
- <h1 id="services-and-specialties">Services and Specialties</h1>
447
- <div class="blank"></div>
448
- <h2 id="services">Services</h2>
449
- <h3 id="custom-slaughtering">Custom Slaughtering</h3>
450
- <p>Bring your own beasts, and Morgor will prepare the meat to your specifications.
451
- 50 gold coins per beast.</p>
452
- <div class="blank"></div>
453
- <h2 id="specialties">Specialties</h2>
454
- <div class="blank"></div>
455
- <h3 id="basilisk-cutlets">Basilisk Cutlets</h3>
456
- <p>Tender and marbled with a unique flavor, perfect for those seeking a truly rare dining experience.</p>
457
- <h3 id="subterranean-lizard-tail">Subterranean Lizard Tail</h3>
458
- <p>A delicacy prized for its unique texture and earthy taste, enchanted to enhance its natural flavor.</p>
459
- <h1 id="security">Security</h1>
460
- <div class="blank"></div>
461
- <h3 id="bewitched-meat-hooks">Bewitched Meat Hooks</h3>
462
- <p>These enchanted meat hooks animate and attack intruders who try to take meat without paying. 200 gold coins per pound.</p>
463
- <div class="blank"></div>
464
- <p>Attack: +5 to hit, 1d8+3 piercing damage.</p>
465
- <h3 id="shadow-ward">Shadow Ward</h3>
466
- <p>A magical barrier that alerts Morgor if someone enters the shop after hours. 150 gold coins per pound.</p>
467
- <div class="blank"></div>
468
- <p>Detection radius of 60 feet, triggers an audible alarm.</p>
469
- </div> <!-- Close Block -->
470
- </div> <!-- close columnWrapper-->
471
- </div> <!-- close page 2 -->
472
-
473
- <div class="page" id="p3">
474
- <div class="columnWrapper">
475
-
476
- <div class="block classTable frame decoration">
477
- <h5 id="inventory">Inventory</h5>
478
- <table>
479
- <thead>
480
- <tr>
481
- <th align="center">Name</th>
482
- <th align="center">Type</th>
483
- <th align="left">Cost</th>
484
- <th align="center">Properties</th>
485
- </tr>
486
- </thead>
487
- <tbody>
488
- <tr>
489
- <td align="center">Poultry Drumsticks</td>
490
- <td align="center">Meat</td>
491
- <td align="left">1 gp per lbs</td>
492
- <td align="center"></td>
493
- </tr>
494
- <tr>
495
- <td align="center">Ground Beef</td>
496
- <td align="center">Meat</td>
497
- <td align="left">1 gp per lbs</td>
498
- <td align="center"></td>
499
- </tr>
500
- <tr>
501
- <td align="center">Pork Chops</td>
502
- <td align="center">Meat</td>
503
- <td align="left">1 gp per lbs</td>
504
- <td align="center"></td>
505
- </tr>
506
- <tr>
507
- <td align="center">Bacon Strips</td>
508
- <td align="center">Meat</td>
509
- <td align="left">1 gp per lbs</td>
510
- <td align="center"></td>
511
- </tr>
512
- <tr>
513
- <td align="center">Sausage Links</td>
514
- <td align="center">Meat</td>
515
- <td align="left">1 gp per lbs</td>
516
- <td align="center"></td>
517
- </tr>
518
- <tr>
519
- <td align="center">Mystic Minotaur Steak</td>
520
- <td align="center">Exotic Meat</td>
521
- <td align="left">25 gold per pound</td>
522
- <td align="center">Grants temporary strength boost when consumed, Requires fine culinary skills to cook properly</td>
523
- </tr>
524
- <tr>
525
- <td align="center">Quantum Quail</td>
526
- <td align="center">Exotic Poultry</td>
527
- <td align="left">15 gold each</td>
528
- <td align="center">“Phases in and out of existence”, “Can enhance one’s agility”</td>
529
- </tr>
530
- <tr>
531
- <td align="center">Invisible Bacon</td>
532
- <td align="center">Mystical Meat</td>
533
- <td align="left">10 gold per slice</td>
534
- <td align="center">“Invisible to the naked eye”, “Tastes incredibly savory”, “Can only be seen with a special spell”</td>
535
- </tr>
536
- <tr>
537
- <td align="center">Hydra Sausage</td>
538
- <td align="center">Mythical Meat</td>
539
- <td align="left">50 gold per link</td>
540
- <td align="center">“Each bite regenerates after a while”, “Consuming too much may cause mild hallucinations”</td>
541
- </tr>
542
- <tr>
543
- <td align="center">Cursed Cleaver</td>
544
- <td align="center">Kitchen Equipment</td>
545
- <td align="left">100 gold</td>
546
- <td align="center">“Cuts through any meat effortlessly”, “Occasionally whispers in a long-forgotten language”, “Rumored to be haunted”</td>
547
- </tr>
548
- <tr>
549
- <td align="center">Vampire Spice Mix</td>
550
- <td align="center">Cooking Ingredient</td>
551
- <td align="left">20 gold per pouch</td>
552
- <td align="center">“Adds a distinct flavor”, “Enhances blood flow in the consumer”, “Leaves a lingering aftertaste of garlic”</td>
553
- </tr>
554
- <tr>
555
- <td align="center">Phoenix Feather Skewers</td>
556
- <td align="center">Cooking Utensil</td>
557
- <td align="left">75 gold per set</td>
558
- <td align="center">“Prevents meat from overcooking”, “Gives a slight warmth to cooked items”, “Reusable endlessly”</td>
559
- </tr>
560
- </tbody>
561
- </table>
562
- </div>
563
- <p>&nbsp;</p>
564
- </div><!-- Close Column Wrapper-->
565
- </div> <!-- Close Page 3-->
566
- </div> <!-- Close pages-->
567
- </div> <!--Close brew renderer-->
568
- </div><!-- Close Div housing body-->
569
- </body>
570
- </html>"""
571
- # Open a file path that will receive the processed text
572
- store_file_path = f"output/test/{store_dict['store_name'].replace(' ', '_')}.html"
573
- with open(store_file_path, 'w') as clean_html:
574
- clean_html.write(html_file_as_text)
575
- clean_html.close()
576
-
577
- return store_file_path
578
 
579
- dict_template = {
580
- "store_name": "The Mirage Emporium",
581
- "store_description": "A peculiar shop filled with the odd and the useless, where each corner hides a laugh and a mystery.",
582
- "store_reputation": "Locally famous for its bizarre and delightful inventory, though not particularly useful.",
583
- "store_backstory": "The Mirage Emporium was founded by a retired jester known for his love of the whimsical and the curious. He traveled the world collecting oddball items that struck his fancy, and upon amassing a considerable collection, opened a shop to share his treasures with the world.",
584
- "store_sd_prompt": "A highly detailed fantasy illustration of a middle-aged full body male gnome in an eclectic shop. The gnome is wearing a colorful patchwork vest and a jaunty hat. The shop is filled with quirky items like broken clocks, mismatched shoes, and joke books. The gnome has distinct fantasy features, such as pointed ears and a small, sturdy build. The background is a vibrant mix of colors and textures, giving the impression of organized chaos.",
585
- "store_type": "Curiosity Shop",
586
- "store_size": "Small",
587
- "store_hours": "From dawn until the moonlight dances.",
588
- "store_location": {
589
- "town": "Bramblebrook",
590
- "district": "Harlequin Quarter",
591
- "street": "Twilight Alley"
592
- },
593
- "store_owners": [
594
- {
595
- "name": "Fizzwidget Funsquirrel",
596
- "species": "Gnome",
597
- "class": "Bard",
598
- "description": "A lively gnome with a perpetual twinkle in his eye and a knack for making people smile.",
599
- "personality": "Joyful, playful, and a tad mischievous.",
600
- "secrets": ["Fizzwidget once performed a jester act for the Queen of Faerun.", "He has a hidden collection of practical jokes for special customers."],
601
- "sd_prompt": "A highly detailed fantasy illustration of a cheerful full body male gnome in an eclectic shop. The gnome is wearing a colorful patchwork vest and a jaunty hat, with a playful expression and sparkling eyes. The shop is filled with quirky items and the background is a chaotic mix of vibrant colors and textures."
602
- }
603
- ],
604
- "store_employees": [
605
- {
606
- "name": "Marigold Merryleaf",
607
- "role": "Shop Assistant",
608
- "species": "Halfling",
609
- "description": "A spry halfling with a knack for finding peculiar trinkets buried under heaps of clutter.",
610
- "personality": "Curious, quirky, and always up for a laugh.",
611
- "sd_prompt": "A highly detailed fantasy illustration of a spry full body female halfling in an eclectic shop. The halfling is wearing a colorful apron and has a curious expression. The shop is filled with quirky items, and the background is a chaotic mix of vibrant colors and textures."
612
- }
613
- ],
614
- "store_quests": [
615
- {
616
- "name": "The Great Sock Hunt",
617
- "description": "Help Fizzwidget locate a rare pair of mismatched socks rumored to bring joy and luck, hidden somewhere in the town of Bramblebrook.",
618
- "reward": "A pair of enchanted socks that make the wearer extraordinarily lucky in games of chance."
619
- }
620
- ],
621
- "store_customers": [
622
- {
623
- "name": "Lord Twiddleton",
624
- "description": "An eccentric noble who collects oddities and revels in the unusual.",
625
- "influence": "High, due to his noble status and wealth."
626
- }
627
- ],
628
- "store_rumors": [
629
- "It's said that Fizzwidget once outwitted a dragon using only a rubber chicken and a whoopee cushion.",
630
- "Marigold can find lost items using her 'half-sense' for where things hide."
631
- ],
632
- "store_security": [
633
- {
634
- "name": "Gizmo Gearshaft",
635
- "description": "An ingenious contraption that includes clockwork gears, springs, and enchanted runes.",
636
- "mechanics": "Gizmo Gearshaft patrols the shop, alert for intruders and mischief-makers, and can deploy harmless yet startling pranks to deter trouble."
637
- }
638
- ],
639
- "store_services": [
640
- {
641
- "name": "Laughter Therapy",
642
- "description": "A session with Fizzwidget who tells jokes and performs tricks to brighten your day.",
643
- "price": "1 gold coin per session"
644
- }
645
- ],
646
- "store_specialties": [
647
- {
648
- "name": "Mystery Mounds",
649
- "description": "A pile of assorted oddities bundled together; you never know what you'll get, but it'll always be a conversation starter!",
650
- "price": "5 silver per bundle"
651
- }
652
- ]
653
- }
 
3
  import os
4
  import ast
5
 
6
+ # block_id is a global variable that is used to keep track of the current block id
7
  block_id = 0
8
 
9
+ # This function takes in the user input and block_id and returns a list of blocks built with textareas
10
  def build_blocks(user_input, block_id):
11
  list_of_blocks = []
12
  title_block = build_title_block(user_input['store_name'], user_input['store_description'], user_input['store_backstory'], user_input['store_reputation'])
 
28
  block_id= block_id)
29
  block_id = block_id + 1
30
  list_of_blocks.append(store_properties_block)
31
+ owner_id = 1
32
  # Iterate over owners and generate owner image and details block
33
+ owner_title = "Owner"
34
+ if len(user_input['store_owners']) > 1:
35
+ owner_title = "Owners"
36
+ owner_title_block = f"""<h2 id="owner">{owner_title}</h2>"""
37
+
38
  for owner in user_input['store_owners']:
39
+
40
+ owner_image_block = build_image_block(owner['sd_prompt'], block_id)
41
+ block_id = block_id + 1
42
+ list_of_blocks.append(owner_image_block)
43
+ owner_block = build_owner_block(owner,owner_id, owner_title_block, block_id)
44
  block_id = block_id + 1
45
  list_of_blocks.append(owner_block)
46
+ owner_id += 1
 
 
 
47
  return list_of_blocks
48
+
49
+ # Take in a specific item type and item, and return the html for that item
50
+ def process_into_html(item_type,item, block_id):
51
+ item_html = f"""<tr>
52
+ <td align="left"><strong>{item_type}</strong></td>
53
+ <td align="right"><textarea class="string-action-description-textarea" id="user-store-owners-{block_id}"
54
+ hx-post="/update-stats" hx-trigger="change" hx-target="#user-store-owners-{block_id}t" hx-swap="outerHTML"
55
+ title="">{item}</textarea></td>
56
+ </tr>"""
57
+ return item_html
58
+ # Take in a specific iterable type and iterable, and return the html for that iterable
59
  def process_iterable_into_html(iterable_type, iterable, block_id):
60
  iterable_html = f""""""
61
  for item in iterable:
 
63
  <td align="left"><strong>{iterable_type}</strong></td>
64
  <td align="right"><textarea class="string-action-description-textarea" id="user-store-owners-{block_id}"
65
  hx-post="/update-stats" hx-trigger="change" hx-target="#user-store-owners-{block_id}t" hx-swap="outerHTML"
66
+ title="">{item['name']}</textarea></td>
67
  </tr>"""
68
  iterable_html += item_html
69
  return iterable_html
70
+ # Take in a list of rumors and return the html for that list of rumors
71
+ def process_rumors_into_html(rumors, block_id):
72
+ rumors_html = f""""""
73
+ for rumor in rumors:
74
+ rumor_html = f"""<tr>
75
+ <td align="left"><strong>Store Rumors</strong></td>
76
+ <td align="right"><textarea class="string-action-description-textarea" id="user-store-rumors-{block_id}"
77
+ hx-post="/update-stats" hx-trigger="change" hx-target="#user-store-rumors-{block_id}t" hx-swap="outerHTML"
78
+ title="Rumors">{rumor}</textarea></td>
79
+ </tr>"""
80
+ rumors_html += rumor_html
81
+ return rumors_html
82
+ # Take in a list of secrets and return the html for that list of secrets
83
+ def process_secrets_into_html(secrets, block_id):
84
+ secrets_html = f""""""
85
+ for secret in secrets:
86
+ secret_html = f"""<tr>
87
+ <td align="left"><strong>Secrets</strong></td>
88
+ <td align="right"><textarea class="string-action-description-textarea" id="user-store-rumors-{block_id}"
89
+ hx-post="/update-stats" hx-trigger="change" hx-target="#user-store-rumors-{block_id}t" hx-swap="outerHTML"
90
+ title="Store Size">{secret}</textarea></td>
91
+ </tr>"""
92
+ secrets_html += secret_html
93
+ return secrets_html
94
+ # Block for title, description, backstory, and reputation
95
  def build_title_block(title,description,backstory,reputation):
96
+ title_block_html = f"""<div class="block-item" data-block-id = {block_id}><h1>
97
+ <textarea class="title-textarea" id="user-store-title" hx-post="/update-stats" hx-trigger="change" hx-target="#user-store-name" hx-swap="outerHTML" title="Name of store">{title}</textarea></h1>
98
+ <div contenteditable="true" class="description-textarea" id="user-store-description"
99
  hx-post="/update-stats" hx-trigger="change"
100
  hx-target="#user-monster-description" hx-swap="outerHTML"
101
  title="Any amount or style of description">
 
103
  </div> """
104
 
105
  return title_block_html
106
+ # Block for image generation
107
  def build_image_block(sd_prompt, block_id):
108
  image_block_html = f"""
109
  <div class="block-item" data-block-id="{block_id}">
 
116
  """
117
 
118
  return image_block_html
119
+
120
+ # Block for store properties
121
  def build_store_properties_block(store_type,
122
  store_size,
123
  store_hours,
 
129
  store_reputation,
130
  store_rumors,
131
  block_id):
132
+ # This could be a function since each block is identical.
133
  store_properties_base_html = f"""
134
  <div class="block-item" data-block-id="{block_id}">
135
  <div class="block classTable frame decoration">
 
181
  </tr> """
182
  store_owners = []
183
  store_employees = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  owners_html = process_iterable_into_html('Store Owners', store_owners, block_id)
185
  employees_html = process_iterable_into_html('Store Employees', store_employees, block_id)
186
  store_specialties_html = process_iterable_into_html('Store Specialties', store_specialties, block_id)
187
  store_services_html = process_iterable_into_html('Store Services', store_services, block_id)
188
+ store_rumors_html = process_rumors_into_html(store_rumors, block_id)
 
 
 
 
 
 
 
 
 
 
 
189
  store_iterables_html = f"""
190
  {owners_html}
191
  {employees_html}
 
209
  {store_iterables_html}
210
  {store_end_html}"""
211
  return store_properties_block_html
212
+ # Block that build owner table
213
+ def build_owner_block(owner, owner_id, owner_title_block, block_id):
214
+ # Owner block with values : Name, Race, Class, Description, Personality, Secrets, sd-prompt
215
+
216
+ # Process owner values into html
217
+ owner_name_html = process_into_html('Owner', owner['name'], block_id)
218
+ owner_race_html = process_into_html('Species', owner['species'], block_id)
219
+ owner_class_html = process_into_html('Class', owner['class'], block_id)
220
+ owner_description_html = process_into_html('Description', owner['description'], block_id)
221
+ owner_personality_html = process_into_html('Personality', owner['personality'], block_id)
222
+ owner_secrets_html = process_secrets_into_html(owner['secrets'], block_id)
223
+ # Build owner block html
224
+ # If owner_id is 1, add owner_title_block to owner_block_html
225
+
226
+ owner_block_html = f""""""
227
+ owner_block_html += f"""<div class="block-item" data-block-id="{block_id}">"""
228
+ if owner_id == 1:
229
+ owner_block_html+= owner_title_block
230
+ owner_block_html += f"""<h3 id="owner_{owner_id}">{owner['name']}</h3>"""
231
+ owner_block_html += f"""<table>
232
  <thead>
233
  <tr>
234
  <th align="center"></th>
 
236
  </tr>
237
  </thead>
238
  <tbody>
239
+ {owner_name_html}
240
+ {owner_race_html}
241
+ {owner_class_html}
242
+ {owner_description_html}
243
+ {owner_personality_html}
244
+ {owner_secrets_html}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  </tbody>
246
  </table>
247
  </div>
248
  """
249
+ return owner_block_html
 
 
 
 
 
250
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253