--This is called by the engine when the game is loaded.
function p.__load_game()
    local cmd_name = "debug1"
    game_command_system.add_command(cmd_name, p.handler)
    game_command_system.add_help(cmd_name, p.get_help_str())
end

function p.handler(str)
    local pink_chunk_id = ga_get_pink_tele_dest()
    ga_console_print("pink_chunk_id = " .. tostring(pink_chunk_id))

    -- local var = "debug1.str"
    -- ga_init_package_s(var, "foo")
    -- local value1 = ga_get_package_s(var)
    -- ga_console_print("value1 = " .. value1)
    -- ga_set_package_s(var, "bar")
    -- local value2 = ga_get_package_s(var)
    -- ga_console_print("value2 = " .. value2)

    -- ga_console_print("game_cmd_debug1.handler")
    -- local func, err = load("return function(a,b) return a+b end")
    -- if func then
    --     local ok, add = pcall(func)
    --     if ok then
    --         ga_console_print(add(2,3))
    --     else
    --         ga_console_print("Execution error:", add)
    --     end
    -- else
    --     ga_console_print("Compilation error:", err)
    -- end

    -- ga_print("Printing windows:")
    -- local array = ga_win_get_windows_on_hud()
    -- for i = 1,#array do
    --     ga_console_print(array[i].name)
    -- end

    -- local chunk_id = ga_get_viewer_chunk_id()
    -- local data = ga_search_for_bt_in_chunk(chunk_id, "XAR_SMALL_YELLOW_FLOWER")
    -- if( data.is_valid ) then
    --     local pos = data.value
    --     ga_console_print("found pos = " .. std.vec_to_str(pos))
    -- end


    --The developer can add code here for debugging.
    -- ga_console_print("Here in game_cmd_debug1.handler")
    -- --
    -- ga_dyn_init_s("dyn.a.b.c",      "apple")
    -- ga_dyn_init_s("dyn.a.b.c.d",    "orange")
    -- ga_dyn_init_s("dyn.a.b.c.e",    "peach")
    -- ga_dyn_init_s("dyn.a.b.f",      "pear")
    -- ga_dyn_init_s("dyn.a.b.g.h",    "lemon")
    -- --
    -- ga_console_print("Internal nodes of dyn.a.b:")
    -- ga_dyn_node_itr_start("dyn.a.b")
    -- while(true) do
    --     local name = ga_dyn_node_itr_next()
    --     if name == "" then break end
    --     ga_console_print(name)
    -- end
    -- --
    -- ga_console_print("Leaf nodes of dyn.a.b:")
    -- ga_dyn_leaf_itr_start("dyn.a.b")
    -- while(true) do
    --     local name = ga_dyn_leaf_itr_next()
    --     if name == "" then break end
    --     ga_console_print(name)
    -- end
end

function p.get_help_str()
    return
           "Usage: debug1\n\n"
        .. "This is used internally by the developer. "
end
