Files
rosetta/tools/fixtures/docs_roblox.py
T

50 lines
2.5 KiB
Python

# Docs inputs for the Roblox guide page (tools/fixtures.py, tools/docs_check.py): a small place built by rojo 7.7 as
# .rbxl (binary) and .rbxlx (XML), and a skinned version 4.00 .mesh written by tools/fixtures/robloxmesh.py's spec
# writer.
# tests/gen/docs_roblox.luau { files = { [name] = bytes }, vars = { placeBytes, placeText, meshBytes } }
import importlib.util, json, os, random, shutil, tempfile
INPUTS = ["tools/docs_check.py", "tools/fixtures/robloxmesh.py"]
PLACE = {"name": "Obby", "tree": {
"$className": "DataModel",
"Workspace": {"$className": "Workspace",
"Spawn": {"$className": "SpawnLocation", "$properties": {"Size": [6, 1, 6], "Anchored": True}},
"Course": {"$className": "Model",
"Step1": {"$className": "Part", "$properties": {"Size": [4, 1, 4], "Position": [0, 4, 10], "Anchored": True, "Color": [1, 0, 0]}},
"Step2": {"$className": "Part", "$properties": {"Size": [4, 1, 4], "Position": [0, 8, 20], "Anchored": True, "Color": [0, 1, 0]}}}},
"Lighting": {"$className": "Lighting", "$properties": {"ClockTime": 14}},
"ServerScriptService": {"$className": "ServerScriptService",
"Main": {"$className": "Script", "$properties": {"Source": "print(\"hello from the obby\")\n"}}},
}}
def load(ctx, name):
spec = importlib.util.spec_from_file_location("docs_roblox_" + name, os.path.join(ctx.root, "tools", *name.split("/")))
m = importlib.util.module_from_spec(spec)
spec.loader.exec_module(m)
return m
def generate(ctx):
dc = load(ctx, "docs_check.py")
mesh = load(ctx, "fixtures/robloxmesh.py")
tmp = tempfile.mkdtemp(prefix="formats-docs-roblox-")
try:
proj = os.path.join(tmp, "place.project.json")
with open(proj, "w") as f:
json.dump(PLACE, f)
files = {}
for out in ("obby.rbxl", "obby.rbxlx"):
ctx.nix("rojo", ["rojo", "build", proj, "-o", os.path.join(tmp, out)])
with open(os.path.join(tmp, out), "rb") as f:
files[out] = f.read()
finally:
shutil.rmtree(tmp, ignore_errors=True)
rng = random.Random(5)
sv, sf = mesh.sphere(rng, 6, 10)
bones = mesh.make_bones(rng, 4)
nv, nf, subs, env, _, _ = mesh.make_skin(rng, sv, sf, bones, segs=10)
files["blob.mesh"], _ = mesh.write_v45("4.00", nv, nf, [0, len(nf)], bones, subs, env)
dc.emit_inputs(ctx, files, {"placeBytes": "obby.rbxl", "placeText": "obby.rbxlx", "meshBytes": "blob.mesh"})