0 votes

Hi,

I want to use Tiled Map Importer Plugin. It is only available for 2.x now.

How can I refactor the code to get the job done?

func _on_ImportTilemap_confirmed():
var alert = get_node("ErrorAlert")
var valid = validate_options()
if valid != "OK":
    alert.set_text(valid)
    alert.popup_centered_minsize()
    return

var imd = ResourceImportMetadata.new()
imd.add_source(get_node("MainDialog/Origin/Path").get_text())
imd.set_option("post_script", get_node("MainDialog/PostImportScript/Path").get_text().strip_edges())

for opt_code in options:
    var opt = options[opt_code]
    if opt.type == TreeItem.CELL_MODE_CHECK:
        imd.set_option(opt_code, opt.item.is_checked(1))
    elif opt.type == TreeItem.CELL_MODE_STRING:
        imd.set_option(opt_code, opt.item.get_text(1))
    elif opt.type == TreeItem.CELL_MODE_CUSTOM:
        imd.set_option(opt_code, opt.item.get_metadata(1))

var f = File.new()
imd.set_source_md5(0, f.get_md5(imd.get_source_path(0)))

var err = import_plugin.import(get_node("MainDialog/Target/Path").get_text(), imd)

if err != "OK":
    alert.set_text("Error when importing:\n%s" % [err])
    alert.popup_centered_minsize()
    return

hide()
asked Dec 27, 2017 in Engine by thinkrapido (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.