-
Notifications
You must be signed in to change notification settings - Fork 39
Various fixes #176
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
base: master
Are you sure you want to change the base?
Various fixes #176
Conversation
# Conflicts: # Scripts/Editor/CustomEditors/CollectionCustomEditor.cs # Scripts/Editor/Generators/CollectionGenerators.cs # Scripts/Runtime/Core/ScriptableObjectCollection.cs
Fixed Add returning false when collection was indeed corrected
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.
Found some stuff that is probably worth fixing. Mostly style inconsistencies, but some functional things as well. Please have a look
|
||
// Delete any existing files that have the old deprecated extension. | ||
string deprecatedFileName = finalFileName + ExtensionOld; | ||
if (File.Exists(deprecatedFileName)) |
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.
Why did you remove this exactly? It is useful when migrating from an older version of SOC that it doesn't leave the old .cs
file but automatically removes it, otherwise you get compile errors and you have to manually find where it generated the code and delete the old .cs
file
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.
Our collections are in the same folder as the generated code, so this code deletes them. Not sure how we ended up with a different structure than recommended, but we have a 100+ collections now.
This wasn't meant to be sent with the pull request, but since I start the pr with master, it got updated
|
||
internal struct LimitedComparer : IComparer<ScriptableObject> | ||
{ | ||
private readonly HashSet<ScriptableObjectCollectionItem> m_ItemsToBeSorted; |
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.
The m_ prefix is not consistent with the rest of the package. According to the style of this package this field should be called itemsToBeSorted
. That goes for m_FirstItemIndex
as well
{ | ||
ScriptableObjectCollection collection = Collections[i]; | ||
if (!collection.AutomaticallyLoaded) | ||
if (!collection) |
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's fine to omit braces for one line statements after an if condition. It's not done 100% of the time so I wouldn't say it's a rule, just know that it's okay to do so. In cases like this where it's just a continue
, I'd say it's simpler / snappier.
if (items.Contains(item)) | ||
|
||
bool contains = items.Contains(item); | ||
bool set = socItem.Collection == this; |
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 don't find set
a very clear name. How did you intend it? As "should set collection"?
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's more meant as "collectionAlreadySet" and "collectionAlreadyContains"
ObjectUtility.SetDirty(this); | ||
} | ||
|
||
private string Desc(int index) |
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.
The method name Desc
is not consistent with other method names / not that clear. Please write it out fully and with a verb, like GetDescription
, which I think is what you intended here.
|
||
private string Desc(int index) | ||
{ | ||
var item = items[index]; |
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.
Please use explicit types unless the type is very long and it's also very obvious what it is.
{ | ||
public static partial class TypeExtensions | ||
{ | ||
private static bool IsList(this Type type) |
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.
This method is either not named correctly or does not function as intended, it seems to check if something is an ICollection<>
but that just indicates that it's a collection, not that it's a list. For example, if you called IsList
or an a Dictionary
it would also return true
.
You should either rename this to IsCollection
or make it check for IList<>
instead.
{ | ||
if (baseType.IsGenericType && | ||
baseType.GetGenericTypeDefinition() == typeof(CollectionItemIndirectReference<>)) | ||
return baseType; |
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.
Multi-line conditions should have braces
public bool HasUniqueGUID(ISOCItem targetItem) | ||
{ | ||
for (int i = 0; i < collections.Count; i++) | ||
foreach (ScriptableObjectCollection collection in collections) |
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.
Is there a particular reason you've changed these for
loops to foreach
loops?
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.
They're faster and I find them more readable
if (toSortX) | ||
{ | ||
// compare y with the first item in the list to sort | ||
return x.Index - m_FirstItemIndex; | ||
} | ||
if (toSortY) | ||
{ | ||
// compare x with the first item in the list to sort | ||
return m_FirstItemIndex - y.Index; | ||
} |
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.
Are the comments in these if statements perhaps flipped?
Action onCompleteCallback = null) | ||
{ | ||
if (item is ISOCItem) | ||
if (item is ISOCItem iItem) |
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 think a better name would be socItem
instead of iItem
changed = true; | ||
ObjectUtility.SetDirty(itemsFromOtherCollection.Collection); | ||
} | ||
} |
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.
Is the indentation correct here? I'm seeing two }
in a row on the same indentation
Co-authored-by: Roy Theunissen <roy.theunissen@live.nl>
Co-authored-by: Roy Theunissen <roy.theunissen@live.nl>
To be honest, I didn't really intend for this PR to be merged. It just contains a bunch of fixes to issues that you may or may not want to include. I won't have time to fit it to the repo standard until at least next week. The most important fix by far is the ReorderableList fix |
That's totally fair and you did sorta already mention this in the description! |
Thank you, sorry for the messy code :) |
You may want to pick and chose, this is just all of the edits we made to fit our usecase, and some general fixes