godot-psd-training/SceneLoader.gd

22 lines
618 B
GDScript

extends Node
func _ready():
# 监听JavaScript发送的场景名称
var training_name = JavaScriptBridge.eval("""
var urlParams = new URLSearchParams(window.location.search);
urlParams.get('training');
""")
print(training_name)
if not training_name:
$ErrMsg.text = "未指定实训"
else:
_on_scene_name_received(training_name)
func _on_scene_name_received(training_name):
print("load training: ", training_name)
var scene = load("res://trainings/" + training_name + ".tscn")
if not scene:
$ErrMsg.text = "未找到实训: %s" % training_name
if scene:
get_tree().change_scene_to_packed(scene)