graph TB
%% -- Common Template --
%% nodes
start(("Start"))
next_scene_from_common(("Next scene"))
scene_start_common["goto: scene_start_common()"]
%% styles
classDef class_script_call fill:#CAF
classDef class_routine_call fill:#EE9
%% apply styles
class scene_start_common class_routine_call
%% flow
start --> scene_start_common
scene_start_common --> |next scene| next_scene_from_common
%% -- scene specific --
%% nodes
next_scene(("Next scene"))
trainend_scene(("TrainEnd scene"))
next_scene_exist{"next scene?"}
train_user_show_status("script: train_user_show_status()")
train_replace_cmd_able("script: able = train_replace_cmd_able(cmd_no)")
train_replace_cmd_able_exist{"train_replace_cmd_able()?"}
builtin_cmd_able["all train are available"]
builtin_print_train_commands["print train commands"]
train_replace_show_other_cmd("script: train_replace_show_other_cmd()")
train_replace_show_other_cmd_exist{"train_replace_show_other_cmd()?"}
builtin_print_other_cmd["print [-1] Back"]
user_input_number["wait: user input number"]
command_handler{"command condition?"}
train_user_cmd("script: handled = train_user_cmd(cmd_no)")
train_user_other_cmd("script: handled = train_user_other_cmd(cmd_no)")
train_user_check_source("script: train_user_check_source(cmd_no)")
train_event_cmdend("script: train_event_cmd_end(cmd_no)")
train_cmd_handled{"return value?"}
%% apply styles
class train_user_show_status,train_replace_show_other_cmd class_script_call
class train_replace_cmd_able class_script_call
class train_user_cmd,train_user_other_cmd class_script_call
class train_user_check_source,train_event_cmdend class_script_call
%% flows
scene_start_common --> |continue current scene| next_scene_exist
next_scene_exist --> |exist| next_scene
next_scene_exist --> |NOT exist| train_user_show_status
train_user_show_status --> train_replace_cmd_able_exist
train_replace_cmd_able_exist --> |exist| train_replace_cmd_able
train_replace_cmd_able_exist --> |NOT exist| builtin_cmd_able
train_replace_cmd_able --> builtin_print_train_commands
builtin_cmd_able --> builtin_print_train_commands
builtin_print_train_commands --> train_replace_show_other_cmd_exist
train_replace_show_other_cmd_exist --> |exist| train_replace_show_other_cmd
train_replace_show_other_cmd_exist --> |NOT exist| builtin_print_other_cmd
train_replace_show_other_cmd --> user_input_number
builtin_print_other_cmd --> user_input_number
user_input_number --> command_handler
command_handler --> |available command| train_user_cmd
command_handler --> |NOT available AND user shown other commands| train_user_other_cmd
command_handler --> |"user NOT shown other commands AND select [-1] Back"| trainend_scene
train_user_cmd --> train_cmd_handled
train_user_other_cmd --> train_cmd_handled
train_cmd_handled --> |true| train_user_check_source
train_cmd_handled --> |false| next_scene_exist
train_user_check_source --> train_event_cmdend
train_event_cmdend --> next_scene_exist