Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add export variables for default build XML #18

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ extends Resource
## Skip texture path that gets applied to caulk and nodrawnonsolid shaders.
@export var skip_texture: String = "textures/special/skip"

## Variables to include in the exported gamepack's [code]default_build_menu.xml[/code].[br][br]
## Each [String] key defines a variable name, and its corresponding [String] value as the literal command-line string to execute in place of this variable identifier[br][br]
## Entries may be referred to by key in [member default_build_commands] values.
@export var default_build_variables: Dictionary
sinewavey marked this conversation as resolved.
Show resolved Hide resolved

## Commands to include in the exported gamepack's [code]default_build_menu.xml[/code].[br][br]
## Keys, specified as a [String], define the command name as you want it to appear in Radiant.[br][br]
## Values represent steps taken within the build command.[br][br]They may be either a [String] or an
sinewavey marked this conversation as resolved.
Show resolved Hide resolved
## [Array][[String]] and will be used as the full command-line text issued by each step [i]within[/i]
sinewavey marked this conversation as resolved.
Show resolved Hide resolved
## its associated build command key. [br][br]They may reference entries in [member default_build_variables]
## by using brackets: [code][variable key name][/code]
@export var default_build_commands: Dictionary
sinewavey marked this conversation as resolved.
Show resolved Hide resolved

## Generates completed text for a .shader file.
func build_shader_text() -> String:
var shader_text: String = ""
Expand Down Expand Up @@ -207,11 +220,50 @@ func do_export_file() -> void:
target_file_path = gamepacks_folder + "/" + gamepack_name + ".game/default_build_menu.xml"
print("Exporting NetRadiant Custom Default Buld Menu to ", target_file_path)
file = FileAccess.open(target_file_path, FileAccess.WRITE)

if file != null:
file.store_string("<?xml version=\"1.0\"?><project version=\"2.0\"></project>")
file.close()
else:
printerr("Error: Could not modify " + target_file_path)
file.store_string("<?xml version=\"1.0\"?>\n<project version=\"2.0\">\n")

for key in default_build_variables.keys():
if key is String:
sinewavey marked this conversation as resolved.
Show resolved Hide resolved
if default_build_variables[key] is String:
file.store_string('\t<var name="%s">%s</var>\n' % [key, default_build_variables[key]])

else:
push_error("Variable key '%s' value '%s' is invalid type: %s; should be: String" % [
key, default_build_variables[key],
type_string(typeof(default_build_variables[key]))
])
else:
push_error("Variable '%s' is an invalid key type: %s; should be: String" % [
key, type_string(typeof(key))
])


for key in default_build_commands.keys():
if key is String:
file.store_string('\t<build name="%s">\n' % key)

if default_build_commands[key] is String:
file.store_string('\t\t<command>%s</command>\n\t</build>\n' % default_build_commands[key])

elif default_build_commands[key] is Array:
for step in default_build_commands[key]:
sinewavey marked this conversation as resolved.
Show resolved Hide resolved
if step is String:
file.store_string('\t\t<command>%s</command>\n' % step)
else:
push_error("Command '%s' has invalid step: %s with type: %s; should be: String" % [
sinewavey marked this conversation as resolved.
Show resolved Hide resolved
key, step, type_string(typeof(step))
])

file.store_string('\t</build>\n')

else:
push_error("Command '%s' is an invalid type: %s; should be: String" % [
sinewavey marked this conversation as resolved.
Show resolved Hide resolved
key, type_string(typeof(key))
])

file.store_string("</project>")

# FGD
var export_fgd : FuncGodotFGDFile = fgd_file.duplicate()
Expand Down