Guest User

Dynamic Mod Menu Code Generator

a guest
Dec 24th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.75 KB | None | 0 0
  1. import os
  2. import codecs
  3.  
  4. locales = ["l_english", "l_braz_por", "l_french", "l_german",
  5.            "l_polish", "l_russian", "l_simp_chinese", "l_spanish"]
  6.  
  7. event_template = """
  8. namespace = dmm_mod{1}
  9.  
  10. country_event = {{
  11.    id = dmm_mod{1}.{0}
  12.    title = "dmm_mod{1}.{0}.title"
  13.    desc = "dmm_mod{1}.{0}.desc"
  14.    picture = GFX_evt_psionics
  15.    is_triggered_only = yes
  16.  
  17.    trigger = {{
  18.        has_global_flag = dmm_mod{1}_{0}
  19.    }}
  20.  
  21.    after = {{
  22.        remove_global_flag = dmm_mod{1}_{0}_opened
  23.    }}
  24.  
  25.    option = {{
  26.        name = "dmm_options.close"
  27.    }}
  28. }}"""
  29.  
  30. button_template = """
  31. spriteTypes = {{
  32.     spriteType = {{
  33.         name = "GFX_dmm_mod{1}_{0}"
  34.         texturefile = "gfx/interface/buttons/button_200_34_animated.dds"
  35.         effectFile = "gfx/FX/buttonstate_onlydisable.lua"
  36.         noOfFrames = 3
  37.         animation = {{
  38.             animationmaskfile = "gfx/interface/buttons/button_200_34_mask.dds"
  39.             animationtexturefile = "gfx/interface/buttons/button_142_animated_texture.dds"
  40.             animationrotation = 180.0
  41.             animationlooping = yes
  42.             animationtime = 40.0
  43.             animationdelay = 0.0
  44.             animationblendmode = "overlay"       #add, multiply, overlay
  45.             animationtype = "scrolling"      #scrolling, rotating, pulsing
  46.             animationrotationoffset = {{ x = 0.0 y = 0.0 }}
  47.             animationtexturescale = {{ x = 1.0 y = 1.0 }}
  48.             animationframes = {{ 1 2 3 }}
  49.         }}
  50.         hitbox_margin = {{ x=11 y=11 }}
  51.     }}
  52. }}"""
  53.  
  54. localization_template = """
  55. {3}:
  56. dmm_mod{1}_{0}:0 \"Dynamic Mod Menu {2} {0}\"
  57. dmm_mod{1}.{0}.title:0 \"Dynamic Mod Menu {2} {0}\"
  58. dmm_mod{1}.{0}.desc:0 \"Dynamic Mod Menu {2} {0}\""""
  59.  
  60.  
  61. on_actions_template = """
  62. on_game_start = {{
  63.     events = {{
  64.             dmm_mod{1}_{0}_flag.1
  65.        }}
  66. }}
  67. """
  68.  
  69. global_flag_template = """
  70. namespace = dmm_mod{1}_{0}_flag
  71.  
  72. event = {{
  73.     id = dmm_mod{1}_{0}_flag.1
  74.     hide_window = yes
  75.     fire_only_once = yes
  76.     is_triggered_only = yes
  77.  
  78.     trigger = {{
  79.        NOT = {{
  80.            has_global_flag = dmm_mod{1}_{0}
  81.        }}
  82.    }}
  83.  
  84.     immediate = {{
  85.         set_global_flag = dmm_mod{1}_{0}
  86.     }}
  87. }}"""
  88.  
  89.  
  90. categories = {
  91.     "general": "",
  92.     "events": "_events",
  93.     "gfx": "_gfx",
  94.     "utilities": "_utilities",
  95.     "other": "_other"
  96. }
  97.  
  98.  
  99. def pick_id():
  100.     id = 0
  101.     while id == 0:
  102.         try:
  103.             value = input("Pick an number id from 1-250: ")
  104.             eval_exit_requested(value)
  105.             user_id = int(value)
  106.             if user_id < 251:
  107.                 id = user_id
  108.         except ValueError:
  109.             pass
  110.     return id
  111.  
  112.  
  113. def pick_category():
  114.     category = None
  115.     while category == None:
  116.         try:
  117.             value = input(
  118.                 "Type a desired category, valid categories are: \"general\", \"events\", \"gfx\", \"utilities\" and \"other\": ")
  119.             eval_exit_requested(value)
  120.             if value.lower() in categories:
  121.                 category = {'name': value.lower(), 'value': categories[value]}
  122.         except ValueError:
  123.             pass
  124.     return category
  125.  
  126.  
  127. def eval_exit_requested(command):
  128.     if command.lower() == "exit" or command.lower() == "quit":
  129.         exit()
  130.  
  131.  
  132. def save(path, template, bomEncoding=False):
  133.     if bomEncoding:
  134.         with codecs.open(path, "w+", "utf-8-sig") as file:
  135.             file.write(template)
  136.     else:
  137.         with open(path, "w+") as file:
  138.             file.write(template)
  139.  
  140.  
  141. def locale_to_path(locale):
  142.     return locale.replace("l_", "")
  143.  
  144.  
  145. if __name__ == "__main__":
  146.     print("When propmted type \"exit\" or \"quit\" to kill the script.")
  147.     category = pick_category()
  148.     cat_name = category['name']
  149.     cat_value = category['value']
  150.     id = pick_id()
  151.     if not os.path.exists("events"):
  152.         os.makedirs("events")
  153.     if not os.path.exists("interface"):
  154.         os.makedirs("interface")
  155.     if not os.path.exists("common/on_actions"):
  156.         os.makedirs("common/on_actions")
  157.     save("events/000_dmm_mod{0}_".format(cat_value) + str(id) +
  158.          ".txt", event_template.format(id, cat_value))
  159.     save("events/dmm_mod{0}_flag_".format(cat_value) + str(id) +
  160.          ".txt", global_flag_template.format(id, cat_value))
  161.     save("interface/zzz_dmm_mod{0}_".format(cat_value) + str(id) +
  162.          ".gfx", button_template.format(id, cat_value))
  163.     save("common/on_actions/dmm_mod{0}_".format(cat_value) +
  164.          str(id) + ".txt", on_actions_template.format(id, cat_value))
  165.  
  166.     for locale in locales:
  167.         if not os.path.exists("localisation/" + locale_to_path(locale) + "/replace"):
  168.             os.makedirs("localisation/" + locale_to_path(locale) + "/replace")
  169.         save("localisation/" + locale_to_path(locale) + "/replace/dmm_mod{0}_".format(cat_value) + str(
  170.             id) + "_" + locale + ".yml", localization_template.format(id, cat_value, cat_name.capitalize(), locale), 1)
Advertisement
Add Comment
Please, Sign In to add comment