2019-08-02 08:17:32 +02:00
|
|
|
tool
|
2019-07-31 20:53:00 +02:00
|
|
|
extends Object
|
|
|
|
class_name MMGenLoader
|
|
|
|
|
|
|
|
func load_gen(filename: String) -> MMGenBase:
|
|
|
|
var file = File.new()
|
|
|
|
if file.open(filename, File.READ) == OK:
|
|
|
|
var data = parse_json(file.get_as_text())
|
|
|
|
return create_gen(data)
|
|
|
|
return null
|
|
|
|
|
|
|
|
func create_gen(data) -> MMGenBase:
|
|
|
|
var generator = null
|
|
|
|
if data.has("connections") and data.has("nodes"):
|
|
|
|
generator = MMGenGraph.new()
|
|
|
|
for n in data.nodes:
|
|
|
|
var g = create_gen(n)
|
|
|
|
if g != null:
|
|
|
|
generator.add_child(g)
|
2019-08-02 08:17:32 +02:00
|
|
|
generator.connections = data.connections
|
2019-08-12 15:58:42 +02:00
|
|
|
elif data.has("model_data"):
|
|
|
|
generator = MMGenShader.new()
|
|
|
|
generator.set_model_data(data.model_data)
|
2019-07-31 20:53:00 +02:00
|
|
|
elif data.has("type"):
|
|
|
|
if data.type == "material":
|
|
|
|
generator = MMGenMaterial.new()
|
|
|
|
else:
|
2019-08-12 15:58:42 +02:00
|
|
|
var file = File.new()
|
|
|
|
if file.open("res://addons/material_maker/library/"+data.type+".mml", File.READ) == OK:
|
|
|
|
var model_data = parse_json(file.get_as_text())
|
|
|
|
print("loaded description "+data.type+".mml")
|
|
|
|
generator = create_gen(model_data)
|
|
|
|
file.close()
|
|
|
|
elif file.open("res://addons/material_maker/nodes/"+data.type+".mmn", File.READ) == OK:
|
|
|
|
generator = MMGenShader.new()
|
|
|
|
var model_data = parse_json(file.get_as_text())
|
|
|
|
print("loaded description "+data.type+".mmn")
|
|
|
|
generator.set_model_data(model_data)
|
|
|
|
file.close()
|
2019-07-31 20:53:00 +02:00
|
|
|
else:
|
2019-08-12 15:58:42 +02:00
|
|
|
print("Cannot find description for "+data.type)
|
2019-08-09 08:16:24 +02:00
|
|
|
else:
|
|
|
|
print(data)
|
2019-08-12 15:58:42 +02:00
|
|
|
if generator != null:
|
|
|
|
if data.has("node_position"):
|
|
|
|
generator.position.x = data.node_position.x
|
|
|
|
generator.position.y = data.node_position.y
|
|
|
|
if data.has("parameters"):
|
|
|
|
generator.initialize(data)
|
2019-07-31 20:53:00 +02:00
|
|
|
return generator
|