godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.71k stars 21.12k forks source link

Globals.localize_path fails to localize an absolute path #6979

Closed neikeq closed 7 years ago

neikeq commented 8 years ago

Issue description (what happened, and what was expected): Regression from #6813

Globals.localize_path(String path) is returning the same absolute path that was passed to it, instead of the localized path.

Steps to reproduce:

Example with the Platformer 2D demo:

func reproduce_the_bug_plz():
    var local_path = "res://player.gd"
    var global_path = Globals.globalize_path(local_path)
    assert(local_path == Globals.localize_path(global_path))
    #assert(global_path != Globals.localize_path(global_path))
akien-mga commented 8 years ago

CC @Faless

Faless commented 8 years ago

Yeah, I really messed up this path thing :-1: . Anyway, can someone check if the small patch referencing this issue is ok? It is in my mind, but I'm not completely sure about the behavior of localize_path. This way if the path is absolute will be localized if a subfolder of the resource folder, it will be left absolute otherwise.

neikeq commented 8 years ago

@Faless I tested your patch with "res://player.gd" and "res://folder/test.gd" globalized and both succeeded at localizing the path.

However, wouldn't the following be better?:

    if (p_path.is_abs_path() && !p_path.begins_with(resource_path)) {
        return p_path;
    }
    // Otherwise continue with the function, which localizes the path
    // It seems to do more than just calling replace