Discord
Login
Community
DARK THEME

How do I read sprite files of the user, with a plugin?

Following Problem: In order to add sprites into my easyDraw Plugin, I need to have access to the sprite folder of the user. Anyone knows how to accomplish that?

edit: pure system.project.listFiles("sprites",...) does not work for me

The plugin saves everything on the branch with the name it is named in the adding plugins section.

By default, this is the name of the project/plugin given in the project/plugin settings section when it was created.

When you add a plugin to your project, you can see the name in the plugin section (plus on the left, at the very bottom of the list),

and you can also change it .

By changing the name, you change the branch on which files will be added.

The plugin only has access to this branch. Only there he can add and delete files - this is probably for security reasons. Imagine that you install a plugin, run it and your entire project is deleted.


Edit

You can read files from the host project. You cannot save and delete from branches other than the plugin name.

  system.project.listFiles(  "sprites", 
    function( list, error) 
      list.forEach( function( name, index )
        print(name)
      end)    
    end)

Edit 2

It says in the documentation:

Note: when used as a plug-in, your app file access will be restricted by default to a subfolder of the host project.

init = function()
  files =  system.project.listFiles(  "sprites", 
    function( list, error) 
      list.forEach( function( name, index )
        print(name)
      end)    
    end)
end

update = function()
end

draw = function()
  screen.clear()
  if files.ready then 
    local index = screen.height / 2 - 20
    for file in files.list 
      screen.drawText( "file: " + file.name, 0, index, 20, "red")
      index -= 20
    end
    if files.list.length == 0 then 
      screen.drawText("Zero files.", 0, 0, 20, "red")
    end
  else 
    screen.drawText(" No file", 0, 0, 20, "red")
  end
end

I thought right the first time.

I changed my mind because I accidentally ran the plugin like a normal application and not in the host project.

There is no access to host files from the plugin.

Hm Okay. Would it be nice to change that? I don't how difficult this change would Be. And most important: The Plugin would only read files, no deletion needed.

Tell the user that in the directory with the name of the plugin there will be two directories: input and output. Let it drag the files into the source directory to input, after working with the plugin it will have the work result in output .

What do you mean with input/output dir? Can you make an example. I would be very thankful. I do know find the "icon" sprite of my plugin, but not the real application icon / other sprites of the plugin. strange...

Ahhh i get it. It gets the names from the sprites of the application (using the plugin) and than displaying the sprites with the names from the plugin. So I can read them, but not draw them right?

You add a plugin to the project, let's say the name of this plugin is "xyz".

  • the user runs the plugin, the plugin checks whether there is any file on the path "system.project.listFiles("sprites/xyz/input"). If there is none, it creates one empty file to create the "sprites/xyz/input" directory.

  • you display a message that the files to be processed must be in the "sprites/xyz/input" directory

  • user moves entire "abc" directory to "sprites/xyz/input"

  • run the plugin again, now the plugin has access to the files

  • the plugin's output will be in "sprites/xyz/output" e.g. "sprites/xyz/output/abc"

  • user drags directory from "sprites/xyz/output/abc" to "main/abc"

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community