Skip to content

Commit

Permalink
Make title/texture fields fill automatically if not set
Browse files Browse the repository at this point in the history
  • Loading branch information
beckadamtheinventor committed Feb 24, 2024
1 parent d5569b4 commit e50acd8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
14 changes: 11 additions & 3 deletions _m3ec/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ def joinDicts(a, b):
c[k] = b[k]
return c

def getDictKeyLen(d, key):
if key.lower() in d.keys():
if type(d[key.lower()]) is str:
return len(d[key.lower()])
return 0

def checkDictKeyTrue(d, key):
if key.lower() in d.keys():
if type(d[key.lower()]) is str:
Expand Down Expand Up @@ -521,7 +527,7 @@ def add_content(cid, content_type, d, manifest_dict, fname=None):
if "_" in cidlow:
manifest_dict[f"mod.{content_type}.{cidlow}.class"] = "".join([word.capitalize() for word in cidlow.split("_")])
else:
manifest_dict[f"mod.{content_type}.{cidlow}.class"] = cid
manifest_dict[f"mod.{content_type}.{cidlow}.class"] = cid.capitalize()

# if f"mod.{content_type}.{cidlow}.class" in manifest_dict.keys():
# print(manifest_dict[f"mod.{content_type}.{cidlow}.class"])
Expand All @@ -532,7 +538,9 @@ def add_content(cid, content_type, d, manifest_dict, fname=None):
if content_type == "recipe":
manifest_dict[f"mod.{content_type}.{cidlow}.texture"] = d["result"]
else:
if f"mod.{content_type}.{cidlow}.texture" not in manifest_dict.keys():
if "title" not in d.keys() or getDictKeyLen(d, "title") < 1:
manifest_dict["title"] = " ".join([word.capitalize() for word in cidlow.split("_")])
if "texture" not in d.keys() or getDictKeyLen(d, "texture") < 1:
if f"mod.{content_type}.{cidlow}.texture_top" in manifest_dict.keys():
manifest_dict[f"mod.{content_type}.{cidlow}.texture"] = manifest_dict[f"mod.{content_type}.{cidlow}.texture_top"]
elif f"mod.{content_type}.{cidlow}.texture_side" in manifest_dict.keys():
Expand All @@ -542,7 +550,7 @@ def add_content(cid, content_type, d, manifest_dict, fname=None):
elif f"mod.{content_type}.{cidlow}.texture_front" in manifest_dict.keys():
manifest_dict[f"mod.{content_type}.{cidlow}.texture"] = manifest_dict[f"mod.{content_type}.{cidlow}.texture_front"]
else:
manifest_dict[f"mod.{content_type}.{cidlow}.texture"] = None
manifest_dict[f"mod.{content_type}.{cidlow}.texture"] = cidlow

return True

Expand Down
5 changes: 5 additions & 0 deletions data/default_content_files/food.m3ec
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ contentid:
title:
texture:

# Hunger restore. Player has 20 hunger points.
hunger:
# Saturation modifier. Multiplied by hunger to get actual value
saturation:
# true, false
alwaysEdible: true
# true, false
snack: false

# Haste 2 effect for 15 seconds with a 50% chance of triggering
# +statusEffects: HASTE 2 300 0.5

# customclass:
# +langs: fr_ca
# fr_ca:
7 changes: 5 additions & 2 deletions m3ec.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,11 @@ def build_mod(modloader, version, modenv, manifest_dict):
add_content(cid, "item", dictinst, manifest_dict, fname)
continue
if "contentid" not in d.keys():
print(f"Warning: Skipping file \"{fname}\" due to missing contentid.")
continue
if "cid" in d.keys():
d["contentid"] = d["cid"]
else:
print(f"Warning: Skipping file \"{fname}\" due to missing contentid.")
continue
if content_type == "recipe":
if "contentid" in d.keys():
cid = d["contentid"]
Expand Down

0 comments on commit e50acd8

Please sign in to comment.