93 lines
2.2 KiB
Python
93 lines
2.2 KiB
Python
import fxconv
|
|
import yaml
|
|
|
|
def convert(input, output, params, target):
|
|
recognized = True
|
|
if params["custom-type"] == "blockinfo":
|
|
o = convert_blockinfo(input, params)
|
|
else:
|
|
recognized = False
|
|
|
|
if recognized:
|
|
fxconv.elf(o, output, "_" + params["name"], **target)
|
|
return 0
|
|
|
|
return 1
|
|
|
|
def mkBreakability(br):
|
|
return fxconv.u8({
|
|
None: 0,
|
|
"Fluid": 0,
|
|
"ByAnything": 1,
|
|
"ByTool": 2,
|
|
"Unbreakable": 3,
|
|
}[br])
|
|
|
|
def mkToolKind(tk):
|
|
return fxconv.u8({
|
|
None: 0,
|
|
"Pickaxe": 0,
|
|
"Axe": 1,
|
|
"Shovel": 2,
|
|
"Hoe": 3,
|
|
}[tk])
|
|
|
|
def mkBool(b):
|
|
if isinstance(b, str):
|
|
b = b.lower()
|
|
return fxconv.u8(b in [True, "yes", "true"])
|
|
|
|
def mkGlyph(s):
|
|
assert len(s) == 1
|
|
special = {
|
|
0x2058: 1,
|
|
0x00B7: 2,
|
|
0x2225: 3,
|
|
0x00A4: 4,
|
|
0x2197: 5,
|
|
0x00BB: 6,
|
|
0x2193: 7,
|
|
0x00EE: 8,
|
|
0x222B: 9,
|
|
0x25AA: 10,
|
|
0x2605: 11,
|
|
0x25A1: 0x7f,
|
|
}
|
|
if ord(s) >= 0x20 and ord(s) <= 0x7f:
|
|
return fxconv.u8(ord(s))
|
|
elif ord(s) in special:
|
|
return fxconv.u8(special[ord(s)])
|
|
else:
|
|
raise ValueError(f"unknown glyph {s}")
|
|
|
|
def mkGlyphCluster(str):
|
|
assert len(str) == 4
|
|
return b"".join(mkGlyph(s) for s in str)
|
|
|
|
def convert_blockinfo(input, params):
|
|
with open(input, "r") as fp:
|
|
data = yaml.safe_load(fp.read())
|
|
|
|
o = fxconv.ObjectData()
|
|
|
|
for b in data:
|
|
# Make sure there are no typos in the fields
|
|
assert (f in ["name", "breakability", "toolKind",
|
|
"baseBreakDurationTicks", "walkable"] for f in b)
|
|
|
|
# If a tool is specified, default to Breakability::ByTool
|
|
tk = b.get("toolKind", None)
|
|
br = b.get("breakability", "ByTool" if tk is not None else "Fluid")
|
|
|
|
o += fxconv.string(b["name"])
|
|
o += mkGlyphCluster(b["cluster"])
|
|
o += mkBreakability(br)
|
|
o += mkToolKind(tk)
|
|
o += fxconv.u16(int(b.get("baseBreakDurationTicks", "20")))
|
|
o += mkBool(b.get("walkable", False))
|
|
o += bytes(3)
|
|
|
|
o += fxconv.sym("Nooncraft_blockInfoCount")
|
|
o += fxconv.u32(len(data))
|
|
return o
|