Skip to content

Add getResourceFiles#3603

Closed
TracerDS wants to merge 20 commits into
multitheftauto:masterfrom
TracerDS:230724_Add_getLoadedFiles
Closed

Add getResourceFiles#3603
TracerDS wants to merge 20 commits into
multitheftauto:masterfrom
TracerDS:230724_Add_getLoadedFiles

Conversation

@TracerDS

@TracerDS TracerDS commented Jul 23, 2024

Copy link
Copy Markdown
Contributor

getResourceFiles will return names of all files loaded by a resource

@Fernando-A-Rocha

Copy link
Copy Markdown
Contributor

Very nice. Can you add an argument "resource element" so you can get file list of another resource, which would work if it is running?

@TracerDS

Copy link
Copy Markdown
Contributor Author

Very nice. Can you add an argument "resource element" so you can get file list of another resource, which would work if it is running?

Already did ;)

@tederis tederis added the enhancement New feature or request label Jul 24, 2024
Comment thread Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp Outdated

@Fernando-A-Rocha Fernando-A-Rocha left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp
@TheNormalnij TheNormalnij changed the title Add getLoadedFiles Add getResourceFiles Jul 28, 2024
Comment thread Server/mods/deathmatch/logic/CResourceFile.h
Comment on lines +17 to +31
switch (resourceType)
{
case eResourceType::RESOURCE_FILE_TYPE_SCRIPT:
case eResourceType::RESOURCE_FILE_TYPE_CLIENT_SCRIPT:
m_resourceCategoryType = eResourceCategory::SCRIPTS;
case eResourceType::RESOURCE_FILE_TYPE_MAP:
m_resourceCategoryType = eResourceCategory::MAPS;
case eResourceType::RESOURCE_FILE_TYPE_CONFIG:
case eResourceType::RESOURCE_FILE_TYPE_CLIENT_CONFIG:
m_resourceCategoryType = eResourceCategory::CONFIGS;
case eResourceType::RESOURCE_FILE_TYPE_CLIENT_FILE:
case eResourceType::RESOURCE_FILE_TYPE_HTML:
m_resourceCategoryType = eResourceCategory::FILES;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can filter it in CLuaResourceDefs::GetResourceFiles. You don't need GetResourceCategoryType

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its better this way

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. You can use original types. I think client-scripts and server-scripts have some sense for developers. So you shouldn't map eResourceType into custom enum for one Lua function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have to do string manipulation in both functions just to get values.
Its better that way

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is wrong with eResourceType ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too much noise

@TheNormalnij TheNormalnij Aug 3, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like using existing enum is much better than creating a new one with mapping from eResourceType and adding boilerplate code in client and server.

too much noise

What do you mean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

Exactly what I said. Its easier to have 3 categories: scripts, maps, files instead of: client/server scripts, client/server files, (client/server?) maps, etc.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no problem here. It's much useful.

@TheNormalnij

TheNormalnij commented Aug 3, 2024

Copy link
Copy Markdown
Member

Does it return shared scripts twice here? Is it expected behavior?

local list = getResourceFiles("all")

@Fernando-A-Rocha

Copy link
Copy Markdown
Contributor

File paths returned shouldn't be repeated imo

@Fernando-A-Rocha

Copy link
Copy Markdown
Contributor

To make this more advanced, the list returned could be a table of {filePath, fileType} where fileType is like "client-script" or "shared-script" or "map-file" idk

@TracerDS

TracerDS commented Aug 4, 2024

Copy link
Copy Markdown
Contributor Author

Does it return shared scripts twice here? Is it expected behavior?

local list = getResourceFiles("all")

Yeah, it returns twice. Its not expected behaviour. Will fix that
image

Comment on lines +1492 to +1494
if (file->GetResourceCategoryType() != type.value() && type.value() != eResourceCategory::ALL)
continue;
files.insert(file->GetName());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous varian was more readable. Why did you change it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previous variant was basically the same.
This leaves room for more conditions to come.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no 'early continue' rule. You obfuscate the code with overusing 'continue' in loops. And you don't really need to use early return for small code blocks.
You did the code less readable and maintainable.

if (file->GetResourceCategoryType() == type.value() || type.value() == eResourceCategory::ALL)
    files.insert(file->GetName());

Is fine condition, that describes the function logic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is early-return which is basically the same but whatever.
I'd rather go with continue rather than indentation

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your continue creates indentation too. Please, keep it simple

There is early-return which is basically the same but whatever.

Not really. Multiple 'continue' conditions can make a loop harder for reading.
There is no goal to use minimal indentation. The code should primarily describe the logic.
You're overusing 'early return'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again?

No one was interested in this convo for 2 weeks, give it a break.
No contributors were opposed against this so Im leaving it as it is.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also see the early return overuse here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No contributors were opposed against this so Im leaving it as it is.

And nobody confirm your position. Don't hide requested changes. Stale conversations should be dismissed by another members.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And nobody confirm your position

Im following the guidelines is'all.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you interpreter these guidelines very differently

@Fernando-A-Rocha Fernando-A-Rocha left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready to merge imo

Comment thread Server/mods/deathmatch/logic/CResource.h
@Fernando-A-Rocha

Copy link
Copy Markdown
Contributor

@TracerDS it would be nice to have a way to know if a file has download="false" attribute, so it can be downloaded using downloadFile later
Currently the only way to achieve this is by parsing the meta.xml file, which seems a bit too much

@Fernando-A-Rocha

Copy link
Copy Markdown
Contributor

@TracerDS it would be nice to have a way to know if a file has download="false" attribute, so it can be downloaded using downloadFile later Currently the only way to achieve this is by parsing the meta.xml file, which seems a bit too much

Any ideas?

@TracerDS

TracerDS commented Nov 6, 2024

Copy link
Copy Markdown
Contributor Author

@TracerDS it would be nice to have a way to know if a file has download="false" attribute, so it can be downloaded using downloadFile later Currently the only way to achieve this is by parsing the meta.xml file, which seems a bit too much

Any ideas?

maybe a parameter that checks download="false"?

@Fernando-A-Rocha

Fernando-A-Rocha commented Nov 6, 2024

Copy link
Copy Markdown
Contributor

@TracerDS it would be nice to have a way to know if a file has download="false" attribute, so it can be downloaded using downloadFile later Currently the only way to achieve this is by parsing the meta.xml file, which seems a bit too much

Any ideas?

maybe a parameter that checks download="false"?

Resource files, when they are parsed in the meta.xml, are already identified if they need to be downloaded later by the client.

@Fernando-A-Rocha

Copy link
Copy Markdown
Contributor

It's a matter of returning that download attribute value for each file. The array of file names returned by this new function should contain arrays where you have like
{fileName="myFoder/myFile.dff", download=false}

@TracerDS

TracerDS commented Nov 7, 2024

Copy link
Copy Markdown
Contributor Author

It's a matter of returning that download attribute value for each file. The array of file names returned by this new function should contain arrays where you have like
{fileName="myFoder/myFile.dff", download=false}

I think it would be better to return just an array of files and handle the download attribute via a parameter. It would be better for the end user

@Fernando-A-Rocha

Copy link
Copy Markdown
Contributor

It's a matter of returning that download attribute value for each file. The array of file names returned by this new function should contain arrays where you have like
{fileName="myFoder/myFile.dff", download=false}

I think it would be better to return just an array of files and handle the download attribute via a parameter. It would be better for the end user

True, but what parameter exactly?

@TracerDS

TracerDS commented Nov 7, 2024

Copy link
Copy Markdown
Contributor Author

True, but what parameter exactly?

Something like isDownloaded or something like that. Or maybe it will receive a table of flags if more param were to come

@TracerDS

Copy link
Copy Markdown
Contributor Author

Im not interested in advancing this PR further anymore.
If someone wants to refresh it, feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants