-
-
Notifications
You must be signed in to change notification settings - Fork 438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add getResourceFiles
#3603
base: master
Are you sure you want to change the base?
Add getResourceFiles
#3603
Changes from all commits
4f3acf9
da7617f
adde333
8289dcb
59052f4
17e0c76
452dde7
5e3d05a
6f6a8b3
6127d68
7b78449
eb831e0
543e6cd
df5275e
0d5e2e9
859f7f4
e794557
979d2ae
04a49af
a9c3768
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,8 @@ void CLuaResourceDefs::LoadFunctions() | |
{"getResourceACLRequests", getResourceACLRequests}, | ||
{"loadstring", LoadString}, | ||
{"load", Load}, | ||
|
||
{"getResourceFiles", ArgumentParser<GetResourceFiles>}, | ||
}; | ||
|
||
// Add functions | ||
|
@@ -129,6 +131,7 @@ void CLuaResourceDefs::AddClass(lua_State* luaVM) | |
lua_classfunction(luaVM, "getACLRequests", "getResourceACLRequests"); | ||
lua_classfunction(luaVM, "isArchived", "isResourceArchived"); | ||
lua_classfunction(luaVM, "isProtected", "isResourceProtected"); | ||
lua_classfunction(luaVM, "getFiles", "getResourceFiles"); | ||
|
||
lua_classvariable(luaVM, "dynamicElementRoot", NULL, "getResourceDynamicElementRoot"); | ||
lua_classvariable(luaVM, "exportedFunctions", NULL, "getResourceExportedFunctions"); | ||
|
@@ -142,6 +145,7 @@ void CLuaResourceDefs::AddClass(lua_State* luaVM) | |
lua_classvariable(luaVM, "archived", NULL, "isResourceArchived"); | ||
lua_classvariable(luaVM, "protected", nullptr, "isResourceProtected"); | ||
lua_classvariable(luaVM, "loadFailureReason", NULL, "getResourceLoadFailureReason"); | ||
lua_classvariable(luaVM, "files", nullptr, "getResourceFiles"); | ||
|
||
lua_registerclass(luaVM, "Resource"); | ||
} | ||
|
@@ -804,7 +808,7 @@ int CLuaResourceDefs::getResourceConfig(lua_State* luaVM) | |
CheckCanModifyOtherResource(argStream, pThisResource, pResource); | ||
if (!argStream.HasErrors()) | ||
{ | ||
for (CResourceFile* pResourceFile : pResource->GetFiles()) | ||
for (CResourceFile* pResourceFile : pResource->GetResourceFiles()) | ||
{ | ||
if (pResourceFile->GetType() != CResourceFile::RESOURCE_FILE_TYPE_CONFIG) | ||
continue; | ||
|
@@ -1468,3 +1472,32 @@ bool CLuaResourceDefs::isResourceProtected(CResource* const resource) | |
{ | ||
return resource->IsProtected(); | ||
} | ||
|
||
std::vector<std::string> CLuaResourceDefs::GetResourceFiles(lua_State* luaVM, std::optional<CResourceFile::eResourceCategory> type, | ||
std::optional<CResource*> resource) noexcept | ||
{ | ||
using eResourceCategory = CResourceFile::eResourceCategory; | ||
|
||
if (!type) | ||
type = eResourceCategory::ALL; | ||
|
||
if (!resource) | ||
resource = &lua_getownerresource(luaVM); | ||
|
||
const auto resourceFiles = (*resource)->GetResourceFiles(); | ||
|
||
std::unordered_set<std::string> files; | ||
for (const auto& file : resourceFiles) | ||
{ | ||
if (file->GetResourceCategoryType() != type.value() && type.value() != eResourceCategory::ALL) | ||
continue; | ||
files.insert(file->GetName()); | ||
Comment on lines
+1492
to
+1494
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previous varian was more readable. Why did you change it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. previous variant was basically the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. if (file->GetResourceCategoryType() == type.value() || type.value() == eResourceCategory::ALL)
files.insert(file->GetName()); Is fine condition, that describes the function logic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is early-return which is basically the same but whatever. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your
Not really. Multiple 'continue' conditions can make a loop harder for reading. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No one was interested in this convo for 2 weeks, give it a break. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also see the early return overuse here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
And nobody confirm your position. Don't hide requested changes. Stale conversations should be dismissed by another members. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Im following the guidelines is'all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you interpreter these guidelines very differently |
||
} | ||
|
||
// TODO: Upgrade ArgumentParser so it would accept | ||
// std::set and std::unordered_set as return values | ||
return std::vector<std::string>( | ||
std::make_move_iterator(files.begin()), | ||
std::make_move_iterator(files.end()) | ||
); | ||
} |
There was a problem hiding this comment.
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 needGetResourceCategoryType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its better this way
There was a problem hiding this comment.
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
andserver-scripts
have some sense for developers. So you shouldn't mapeResourceType
into custom enum for one Lua functionThere was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean?
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too much noise
There was a problem hiding this comment.
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.What do you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
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.