It looks like you're new here. If you want to get involved, click one of these buttons!
Here’s something I thru together trying to get used to using the new assets format. I don’t know if this will be useful or not to anyone. I didn’t set out to write this, I just ended up with it as I was playing with the different assets formats and commands. This is best viewed when run in portrait orientation. If this is useful to anyone, I can probably make it easier to use by eliminating some of the text input fields. The instructions will explain how to use it when you run it.
I put this in the beta category for now since this will only work with the beta code.
displayMode(STANDARD)
function setup()
dy=0
xx={}
fill(255)
textMode(CORNER)
parameter.action("show builtin files",showBuiltin)
parameter.text("builtin ext")
parameter.action("list mtl",showMtl)
parameter.action("list obj",showObj)
parameter.text("folder")
parameter.text("name")
print("slide print area down if name isnt showing")
print("mtl and obj text dump will show in this print area")
end
function draw()
background(0)
inst()
cnt=0
h=""
if #xx>0 then
for a,b in pairs(xx) do
cnt=cnt+1
s=string.find(b,".....",1,true)
s1=string.sub(b,1,s-1)
if s1~=h then
cnt=cnt+2
end
text(b,10,HEIGHT-cnt*25+dy)
h=s1
end
end
end
function touched(t)
if t.state==MOVING then
dy=dy+t.deltaY
if dy<0 then
dy=0
end
end
end
function showMtl()
output.clear()
if folder=="" or name=="" then
print("folder or name error")
return
end
tab=assets.builtin[folder].all
for c,d in pairs(tab) do
if string.find(c,name) and string.find(c,"mtl") then
str=readText(d)
print(name.." ============")
print(str)
end
end
end
function showObj()
output.clear()
if folder=="" or name=="" then
print("folder or name error")
return
end
tab1=assets.builtin.all
for a,b in pairs(tab1) do
s=string.find(a,".",1,true)
n=string.sub(a,1,s-1)
n=string.gsub(n," ","_")
tab=assets.builtin[n].all
for c,d in pairs(tab) do
if string.find(c,name) and string.find(c,"obj") then
str=readText(d)
print(name.." ============")
print(str)
end
end
end
end
function showBuiltin()
shown=true
dy=0
output.clear()
print("Creating list")
xx={}
tab1=assets.builtin.all
for a,b in pairs(tab1) do
s=string.find(a,".",1,true)
n=string.sub(a,1,s-1)
n=string.gsub(n," ","_")
tab=assets.builtin[n].all
for c,d in pairs(tab) do
if builtin_ext=="" then
table.insert(xx,a.."............"..c)
elseif string.find(c,"."..builtin_ext) then
table.insert(xx,a.."............"..c)
end
end
table.sort(xx)
end
end
function inst()
if not shown then
text("Instructions",50,HEIGHT-50)
text("show builtin files: shows a list of files",100,HEIGHT-100)
text("builtin_ext: can be one of",100,HEIGHT-125)
text("mtl, obj, png, shader, plist",150,HEIGHT-150)
text("if blank, shows all extensions",150,HEIGHT-175)
text("list mtl: shows contents of a mtl file",100,HEIGHT-250)
text("list obj: shows contents of an obj file",100,HEIGHT-275)
text("folder: name of folder, can be one of",100,HEIGHT-300)
text(" Basic, Blocks, Blocky Characters, etc.. ",150,HEIGHT-325)
text(" if blank, prints folder or name error",150,HEIGHT-350)
text("name: name of file",100,HEIGHT-375)
text(" if blank, prints folder or name error",150,HEIGHT-400)
text("To start, just press show builtin files",100,HEIGHT-450)
text(" then scroll the list up/down",100,HEIGHT-475)
text("Run in portrait orientation for more room",100,HEIGHT-550)
end
end
Comments
Nice! How are you finding the new asset API compared to how we used to do things (assetList)?
@Simeon I’m finding the new assets harder to use than the older one. If I do something like sprite() or others where I can select between the (), then it’s no problem. But when I have to create my own string for things like for readText or saveText or createProject, then it take some trial and error before I get it to work. The new assets allows me to see more of the Codea files like I show in the above code, but I don’t have much use for that. I guess it’ll get easier the more I use them. I just don’t have them all in my memory yet, so I have to refer to code where I already used them to get the right syntax.
Thanks for the feedback. I can see how the old syntax was simpler for both reading and saving
I had thought about making
documents
andbuiltin
global names, along withproject
So that it would be:
But ultimately I wanted to encourage people to store assets in the project folder, so kept only the
assets
name out in the open. Not sure if I made the right choice. (Also thought about using the nameasset
instead, e.g.,asset.MyFile
)@Simeon We'll see how it goes with the new assets. It might be just getting used to using it. Sometimes you use a period between the names, other time you skip the period and use [ ]. The hard part was going thru 600+ projects and seeing if I needed to change sprites or other thing that used the assets. That was on one iPad. Now I have to do the same with my other iPad because I have different projects on it.
are we looking at an incompatible change for this new stuff? or just a useful new way?
@RonJeffries old code will still work, but it will print a warning to the output pane to bug you to change
@RonJeffries I would say incompatible on some things. That’s what I’m running into now trying to make changes to some of my projects. The sprites and things like that are easy changes, but lists of projects or files isn’t the same.
@dave1707 did you run into issues where your old projects stopped working if you didn't touch them? I was hoping the new assets API would be opt-in (e.g., just start using it for new projects, old ones continue to run as-is)
@Simeon I didn’t run into any issues other than all the warnings that popped up. I thought that you would eventually eliminate the old stuff so I converted my projects to use the new assets. That’s where I started to run into issues with things that didn’t seem compatible with what I was doing.
Question: Are you changing anything else with the assets. So if I don’t get a warning on something then it’s OK to keep using it. For instance, listProjects doesn’t give a warning but I was trying to use assets.documents.all . listProjects just returned a table of projects, whereas assets.documents.all returned a keyed table of a whole lot of things. That’s where I was running into problems and had to code around it.
I'd eventually like to deprecate those functions too (though they will stick around for a long time), so I am glad that you tried to use them and found the pain points
After reading about the issues people face I was thinking to add some extra APIs
Namely,
.type
,.ext
on asset folders as well. Because at the moment we only have these APIs for asset keysThat way getting the Codea projects would be
I think having native filtering for tables would work nicely, but I need to find a good functional API for Lua. That way you could do something like
Or we build this into the API and make
.all
a function that can accept parameters instead of a propertyAlso considering renaming
assets
toasset
before the beta is done. Having threes
s in a keyword is bothering me@Simeon I guess it’s going to take awhile to get this all straightened out. But I’m still going to try and get all the warnings eliminated.
@dave1707 that's OK, just wondering if you had a preference in the API design for more convenience methods to access different subsets of folders
@Simeon I’m still playing with the asset stuff, but maybe something like what’s below or however you want to do it.
I think that a way to create regular tables of individual names would be very helpful. The keyed tables aren’t very useful. Right now I create a second table from the first keyed table, stripping off the extension names. Maybe a way to have a table of just names or another way to have names with extensions. I’m not sure if/when extension names are needed.
Also another thing I’m running into are spaces in the names. I have to replace the spaces with _ to get them to work. Maybe I need to use [ ], but I’m not sure, still experimenting.