-def quotewrap(string):
- """Wrap a string in double quotes."""
- return '"' + string + '"'
-
-def write_regular_messages(name, h, c):
-
- h += "enum {}_refs {{\n".format(name)
- for key, text in dungeon[name]:
- h += " {},\n".format(key)
- h += "};\n\n"
-
- c += "char* {}[] = {{\n".format(name)
- index = 0
- for key, text in dungeon[name]:
- if text == None:
- c += " NULL,\n"
+def get_refs(l):
+ reflist = [x[0] for x in l]
+ ref_str = ""
+ for ref in reflist:
+ ref_str += " {},\n".format(ref)
+ ref_str = ref_str[:-1] # trim trailing newline
+ return ref_str
+
+def get_arbitrary_messages(arb):
+ template = """ {},
+"""
+ arb_str = ""
+ for item in arb:
+ arb_str += template.format(make_c_string(item[1]))
+ arb_str = arb_str[:-1] # trim trailing newline
+ return arb_str
+
+def get_class_messages(cls):
+ template = """ {{
+ .threshold = {},
+ .message = {},
+ }},
+"""
+ cls_str = ""
+ for item in cls:
+ threshold = item["threshold"]
+ message = make_c_string(item["message"])
+ cls_str += template.format(threshold, message)
+ cls_str = cls_str[:-1] # trim trailing newline
+ return cls_str
+
+def get_turn_thresholds(trn):
+ template = """ {{
+ .threshold = {},
+ .point_loss = {},
+ .message = {},
+ }},
+"""
+ trn_str = ""
+ for item in trn:
+ threshold = item["threshold"]
+ point_loss = item["point_loss"]
+ message = make_c_string(item["message"])
+ trn_str += template.format(threshold, point_loss, message)
+ trn_str = trn_str[:-1] # trim trailing newline
+ return trn_str
+
+def get_locations(loc):
+ template = """ {{ // {}
+ .description = {{
+ .small = {},
+ .big = {},
+ }},
+ .sound = {},
+ .loud = {},
+ }},
+"""
+ loc_str = ""
+ for (i, item) in enumerate(loc):
+ short_d = make_c_string(item[1]["description"]["short"])
+ long_d = make_c_string(item[1]["description"]["long"])
+ sound = item[1].get("sound", "SILENT")
+ loud = "true" if item[1].get("loud") else "false"
+ loc_str += template.format(i, short_d, long_d, sound, loud)
+ loc_str = loc_str[:-1] # trim trailing newline
+ return loc_str
+
+def get_objects(obj):
+ template = """ {{ // {}
+ .inventory = {},
+ .plac = {},
+ .fixd = {},
+ .is_treasure = {},
+ .longs = (const char* []) {{
+{}
+ }},
+ .sounds = (const char* []) {{
+{}
+ }},
+ .texts = (const char* []) {{
+{}
+ }},
+ }},
+"""
+ obj_str = ""
+ for (i, item) in enumerate(obj):
+ attr = item[1]
+ i_msg = make_c_string(attr["inventory"])
+ longs_str = ""
+ if attr["longs"] == None:
+ longs_str = " " * 12 + "NULL,"
+ else:
+ labels = []
+ for l_msg in attr["longs"]:
+ if not isinstance(l_msg, str):
+ labels.append(l_msg)
+ l_msg = l_msg[1]
+ longs_str += " " * 12 + make_c_string(l_msg) + ",\n"
+ longs_str = longs_str[:-1] # trim trailing newline
+ if labels:
+ global statedefines
+ statedefines += "/* States for %s */\n" % item[0]
+ for (i, (label, message)) in enumerate(labels):
+ if len(message) >= 45:
+ message = message[:45] + "..."
+ statedefines += "#define %s\t%d /* %s */\n" % (label, i, message)
+ statedefines += "\n"
+ sounds_str = ""
+ if attr.get("sounds") == None:
+ sounds_str = " " * 12 + "NULL,"
+ else:
+ for l_msg in attr["sounds"]:
+ sounds_str += " " * 12 + make_c_string(l_msg) + ",\n"
+ sounds_str = sounds_str[:-1] # trim trailing newline
+ texts_str = ""
+ if attr.get("texts") == None:
+ texts_str = " " * 12 + "NULL,"