Automagical resources.lua

Automagical resources.lua

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Automagical resources.lua

Post by FLOZi »

Adds all files in bitmaps/projectiletextures to resources["graphics"]["projectiletextures"] and all files in bitmaps/groundfx to resources["graphics"]["groundfx"]

use link in other post
(Many thanks to lurker for the RegExs)

Basically the point is that you no longer have to add each and every bitmap you use in CEGs into your resources.lua, just stick them in the corresponding subdirs.

Also it cleans up the adding of caustics/smoke/scars, (compare to the base file), speaking of which I'm sure a more competent lua coder could clean this up and add it to base file, so most mods would not even need to override it :regret:
Last edited by FLOZi on 25 Jan 2010, 04:46, edited 1 time in total.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: Automagical resources.lua

Post by FLOZi »

Improvements, and many more thanks to lurker. :mrgreen:

Will now add all files recursively under the projectiletextures and groundfx folders, so you can organise them more. e.g. bitmaps/projectiletextures/ARM/peewee_muzzleflash_front.tga, whilst being SVN safe (ignores .svn subdirectories and their contents) 8)

edit: @ 03.15gmt fixed a bug with adding the default caustics/smoke/scars - but it turns out the engine adds them anyway, so you could just do away with that crap :| Which is awfully strange, as spring was crashing on me earlier today complaining about missing smoke textures. *aneurysm*

And again at 03.39gmt. Must not code when sleep deprived.

http://pastebin.com/f4e3c65cb
Last edited by FLOZi on 25 Jan 2010, 04:43, edited 3 times in total.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Automagical resources.lua

Post by Argh »

That is really excellent work, thanks for making that available- I'll test it out when I get the chance.
User avatar
Masse
Damned Developer
Posts: 979
Joined: 15 Sep 2004, 18:56

Re: Automagical resources.lua

Post by Masse »

Very cool indeed 8)
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Re: Automagical resources.lua

Post by trepan »

One more reason that: Lua kicks the TDF's ass!
(think -- WinAMP voice)
SeanHeron
Engines Of War Developer
Posts: 614
Joined: 09 Jun 2005, 23:39

Re: Automagical resources.lua

Post by SeanHeron »

Like I've said elsewhere: huzzah, and include this in springs base lua files!
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Automagical resources.lua

Post by Forboding Angel »

can I use this in addition to my resources.tdf?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: Automagical resources.lua

Post by FLOZi »

Forboding Angel wrote:can I use this in addition to my resources.tdf?
No. Engine reads resources.lua only - Your resources.tdf is read by the resources.lua in base content. Obviously this one will override that one. I guess you could hack this one to parse the tdf too if you really wanted to.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: Automagical resources.lua

Post by FLOZi »

Something worth considering, as next engine will break many mods, now may be a good time to introduce this and also sort existing base files into the folders so they don't have to have manually inserted. May as well cause all the breakage in one go.

Of course, it isn't really necessary for this. Just an idea.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Automagical resources.lua

Post by Forboding Angel »

Flozi, does this support subdirectories?

That is to say, does it read all the files from the directories below the one you are looking?
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Automagical resources.lua

Post by zwzsg »

FLOZi wrote:Will now add all files recursively under the projectiletextures and groundfx folders, so you can organise them more. e.g. bitmaps/projectiletextures/ARM/peewee_muzzleflash_front.tga
That means yes.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Automagical resources.lua

Post by Argh »

Works like a charm.

So... if every game used this, there would not be resources conflicts, correct?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: Automagical resources.lua

Post by FLOZi »

Argh wrote:Works like a charm.

So... if every game used this, there would not be resources conflicts, correct?
Resources conflicts?? How can one mod's resources.lua conflict with another?
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Automagical resources.lua

Post by lurker »

I think he's referring to having hardcoded resources when using dependencies, because only the topmost version of a file is read.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Automagical resources.lua

Post by Argh »

Yes, that's exactly what I'm driving at. I want to make World Builder deployable as a map dependency, and I don't want it to conflict with games / mods that either have an existing resources tdf or which use their own resources.lua.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Automagical resources.lua

Post by Argh »

OK, I'm going to write a variant that will handle a RESOURCES.TDF. I can't eliminate conflicts with projects that use resources.lua, though.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Automagical resources.lua

Post by Argh »

Nevermind, I think that instead I'll do something else... meh, there's only so far I can push backwards compatibility.
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: Automagical resources.lua

Post by Pxtl »

Argh, I think this is a problem endemic to the engine (the fact that so many of these files are mutually exclusive) and not one I think you're going to solve today.

Fundamentally, all the mod files should be, by default, looking for addenda coming from maps and mutators, and overriding behavior instead of extending behaviour should be the exception, not the rule.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Automagical resources.lua

Post by Argh »

Yeah, I know- it's a fundamental design issue with this engine. I have been pecking at it for awhile, but this code was a real eye-opener for me- perhaps it can be dealt with by most games with a 5-minute alteration of their file structure (move stuff to folders) and even old games could be fixed very rapidly and re-released.

So I've written a rather lengthy post to FLOZi, begging for some additional help. What I think that we need to do (collectively, for once) is to get everybody on this standard for resources.lua, build a similar piece of code for sounds.lua, and that would eliminate 90% of the problems right there.

Then project content could be merged pretty easily, and World Builder could be a purely map-side level design tool, completely divorced from all dependency on other things. We could then fix all the jobjol projects, which would take somebody less time than it would take to download them.
LordMuffe
Posts: 286
Joined: 13 Mar 2005, 15:39

Re: Automagical resources.lua

Post by LordMuffe »

Could somebody explain me how to get this thing to work?

Preferably in a way that someone without any knowledge of LUA (me) can understand?

I added the linked file into my /gamedata folder, but it seems I miss something, because spring just acts like it would not have a resource file.
Post Reply

Return to “Lua Scripts”