Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
getting absolute path of resource (asset) foler — Gideros Forum

getting absolute path of resource (asset) foler

salesioparksalesiopark Member
edited September 9 in Suggestions & requests
I'm developing pixel art editor that is running on Gideros player. I want the resulting pixel art data in the resource directory (i.e. in the asset folder). However, there is no function that can get absolute path of the asset folder in the Gideros API. Any help?

Comments

  • MoKaLuxMoKaLux Member
    edited September 9
    from the wiki: https://wiki.gideros.rocks/index.php/File_system

    The resource directory is the default directory. Therefore, to access the files you specify the file path as it is:

    local sprite1 = Texture.new("gfx/sprite1.png")
    local sprite2 = Texture.new("gfx/sprite2.png")

    You can also use the io library provided by Lua:
    io.read("data/list.txt")

    Note: the resource directory is read-only and you should not try to write any files there
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • salesioparksalesiopark Member
    edited September 10
    MoKaLux said:

    from the wiki: https://wiki.gideros.rocks/index.php/File_system

    The resource directory is the default directory. Therefore, to access the files you specify the file path as it is:

    local sprite1 = Texture.new("gfx/sprite1.png")
    local sprite2 = Texture.new("gfx/sprite2.png")

    You can also use the io library provided by Lua:
    io.read("data/list.txt")

    Note: the resource directory is read-only and you should not try to write any files there

    The thing I want to do is creating 'data.txt' file and storing it to the Giderois resource (assets) folder at runtime in simulator mode. I know that the resource directory is read-only and solar2d is the same. I succeeded in solar2d simulator by creating the 'data.txt' file in the temporaty folder first and then copying it to the resource directory using os.execute("copy temp/datat.txt resourceFolder") function. I want to do similar thing in Gideros Simulator.
  • MoKaLuxMoKaLux Member
    edited September 9

    I'm developing pixel art editor that is running on Gideros player. I want the resulting pixel art data in the resource directory (i.e. in the asset folder).

    Sorry I don't know why you "want the resulting pixel art data in the resource directory". Why don't you use LFS https://wiki.gideros.rocks/index.php/Lfs for example? Why don't you save it to |D| document folder?

    There is also this thread https://forum.gideros.rocks/discussion/8429/os-execute

    PS: I did this a while ago https://mokalux.itch.io/onetiletotileset :)

    Good luck with your pixel art editor, can't wait to see it <3

    Likes: E1e5en

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
  • salesioparksalesiopark Member
    edited September 9
    MoKaLux said:

    I'm developing pixel art editor that is running on Gideros player. I want the resulting pixel art data in the resource directory (i.e. in the asset folder).

    Sorry I don't know why you "want the resulting pixel art data in the resource directory". Why don't you use LFS https://wiki.gideros.rocks/index.php/Lfs for example? Why don't you save it to |D| document folder?

    There is also this thread https://forum.gideros.rocks/discussion/8429/os-execute

    PS: I did this a while ago https://mokalux.itch.io/onetiletotileset :)

    Good luck with your pixel art editor, can't wait to see it <3 </p>
    I'm making some sort of fantasy console in which user can download resource (png/wav files), can manage library and can make and save pixel arts/tiles maps. In all the tasks, I need to know the resource folder path. In Solar2d, it was easy, but Gideros not.

    I made a short youtube video.

    https://youtube.com/watch?v=7q4j1HUFEYc

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • E1e5enE1e5en Member
    edited September 9
    The resource directory is for static files that you use in your application. You can save the file "template", database, etc. there. All files that are changed are stored either in temporary folders or in the documents directory. This follows from the documentation of game engines and application development (for example, for the Android operating system).
    For accessing directories (temp and docs) the code and link to the docs was written by @MoKaLux.
    What's the difference between storing files in the resource directory or elsewhere? You define the path where the file will be stored and you can use it to load it into the application. What is the difficulty?
    io.read("|R|file.txt") -- open file.txt in the resource directory to read (same as above)
    io.write("|D|file.txt")
    io.read("|D|file.txt") -- open file.txt in the document directory to read
    io.write("|T|file.txt")
    io.read("|T|file.txt") -- open file.txt in the temporary directory to read

    Likes: MoKaLux

    Beginner game developer
    https://e1e5en.itch.io
    +1 -1 (+1 / -0 )Share on Facebook
  • salesioparksalesiopark Member
    edited September 9
    E1e5en said:

    The resource directory is for static files that you use in your application. You can save the file "template", database, etc. there. All files that are changed are stored either in temporary folders or in the documents directory. This follows from the documentation of game engines and application development (for example, for the Android operating system).
    For accessing directories (temp and docs) the code and link to the docs was written by @MoKaLux.
    What's the difference between storing files in the resource directory or elsewhere? You define the path where the file will be stored and you can use it to load it into the application. What is the difficulty?

    io.read("|R|file.txt") -- open file.txt in the resource directory to read (same as above)
    io.write("|D|file.txt")
    io.read("|D|file.txt") -- open file.txt in the document directory to read
    io.write("|T|file.txt")
    io.read("|T|file.txt") -- open file.txt in the temporary directory to read
    As seen in the above youtube video, the current key idea of my work is using Gideros Simulator as data Editing console for users (kids or students). Example workflow is as follows:

    (1) user makes pixel art on Simulator and the created data file (e.g. 'mypixelart.lua') is saved in the resource folder automatically.
    (2) user can download png/wav or 3rd-person library directly into the resource folder using command-line-interface in the console.
    (3) The users can use the data/library in their project easily (without manually moving data files) e.g., in creating class object like
     
        local pa = Pixels('mypixelart'):setxy(100,200)
     
        local Blowup = import 'blowup' -- using downloaed library
        local boom = Blowup():setxy(300,400)
    I need to know the absolute path of the resource folder to implement this. I think (as of solar2d) that there seems to be no problem with the resource path being provided in simulator mode.
  • E1e5enE1e5en Member
    edited September 9
    If I understand you correctly, the students write the code in Lua, and your program dynamically (at runtime) connects the code and, accordingly, all the resources (pictures, sounds, etc.) in it.
    Or do you have some kind of interpreter for the written code?

    Update:
    When interpreting the code, you could write and replace the paths to the files yourself, and in the case of using the code "directly", then either solve the problem of copying files to the desired directory (perhaps you may need an additional service / service), or require the student to be sure to prescribe 'D' or 'T' (if you decide to use directories of documents or temporary files).
    Beginner game developer
    https://e1e5en.itch.io
  • salesioparksalesiopark Member
    edited September 9
    E1e5en said:

    If I understand you correctly, the students write the code in Lua, and your program dynamically (at runtime) connects the code and, accordingly, all the resources (pictures, sounds, etc.) in it.
    Or do you have some kind of interpreter for the written code?

    I'm making some sort of framework that makes it easy to develop lua-based apps which works on top of Gideros and Solar2d. Not interpreter.
  • hgy29hgy29 Maintainer
    Accepted Answer
    Yes, I understand your need. That's quite unsual, and I couldn't find a way of getting this info from some lua API in current Gideros. A new API could be added easily and with minimum code.

    Likes: salesiopark

    +1 -1 (+1 / -0 )Share on Facebook
  • hgy29 said:

    Yes, I understand your need. That's quite unsual, and I couldn't find a way of getting this info from some lua API in current Gideros. A new API could be added easily and with minimum code.

    Thank you again. :)
  • E1e5enE1e5en Member
    edited September 9
    Out of curiosity, can you clarify? That is, you wrote a wrapper on top of the game engine. Example:
    -- Your framework (API)
    CONST_PATH_FILE = “C:\Users\...”
     
    function DownloadFile(url, filename)
    	local loader = UrlLoader.new(url)
    	…
    End
     
    function onCompleteDownload(event)
    	local out = io.open(CONST_PATH_FILE..filename, "wb")
    	out:write(event.data)
    	out:close()
    end
     
     
    -- API for students
    function LoadSprite(filename)
    	local b = Bitmap.new(Texture.new(CONST_PATH_FILE..filename))
    	stage:addChild(b)
    end
     
     
    -- The student writes
    DownloadFile(\"http:\\example.com\image.png", "image.png")
    local sprite1 = LoadSprite("image.png"):setxy(100, 200)
    So?
    Beginner game developer
    https://e1e5en.itch.io
  • salesioparksalesiopark Member
    edited September 9
    E1e5en said:

    Out of curiosity, can you clarify? That is, you wrote a wrapper on top of the game engine. Example:

    -- Your framework (API)
    CONST_PATH_FILE = “C:\Users\...”
     
    function DownloadFile(url, filename)
    	local loader = UrlLoader.new(url)
    	…
    End
     
    function onCompleteDownload(event)
    	local out = io.open(CONST_PATH_FILE..filename, "wb")
    	out:write(event.data)
    	out:close()
    end
     
     
    -- API for students
    function LoadSprite(filename)
    	local b = Bitmap.new(Texture.new(CONST_PATH_FILE..filename))
    	stage:addChild(b)
    end
     
     
    -- The student writes
    DownloadFile(\"http:\\example.com\image.png", "image.png")
    local sprite1 = LoadSprite("image.png"):setxy(100, 200)
    So?
    I made a very short video about creating sprite animation (flying bird) using my library. After download png file, only two lines of lua code are needed.

    https://youtu.be/80_li5RRVuo

    On the gideros, same method can be used.

    Likes: E1e5en

    +1 -1 (+1 / -0 )Share on Facebook
  • Thanks for the demo. Now it became clear why it is more convenient for you and how libraries are connected to you. I initially believed that everything can be done through the console (download the resource and create a sprite), and did not understand how you dynamically link libraries.
    Good luck with your development! :)

    Likes: salesiopark

    Beginner game developer
    https://e1e5en.itch.io
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.