Skip to content

Conversation

Streus
Copy link
Contributor

@Streus Streus commented Sep 12, 2019

Starting this PR early 'cause core functionality is done, just need some last polish, so I figured I'd do that with PR comments, if there are any.

Create a FeatureLibrary via Assets/Create/Labrys/Feature Library in the menu bar, or in the project view context menu. A prompt will appear asking for a target directory. This is the directory the library will scrape feature assets from.

Auto refresh stuff might not happen. There aren't a lot of options for asset creation hooks.

@Streus Streus added enhancement New feature or request feature-editor Something related to the Feature Editor labels Sep 12, 2019
@Streus Streus requested a review from rushingseas8 September 12, 2019 22:08
@Streus Streus self-assigned this Sep 12, 2019
}
#endregion
}
} No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

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

newline at end of file

EditorGUILayout.EndFadeGroup();
}
}
} No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

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

newline at end of file

}

GUILayout.Space(25);
if (GUILayout.Button(fadeGroupVal.value ? "Hide contents" : "Show contents"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we have a rule for always using braces? /nitpick

public string TargetDirectory { get; private set; }

private Dictionary<string, ushort> nameToFAID;
private FeatureAsset[] features;
Copy link
Collaborator

Choose a reason for hiding this comment

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

(for my own understanding) In short:
Adding a FeatureAsset to the Library essentially adds it to the end of an array, with an additional search structure which indexes by name (that is specified on add). Accessing a FA by index is trivial, accessing by name has a lookup in the name->index Dictionary.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Additional note now that I'm looking at this more: nameToFAID.Values() will only contain sequential integers. I think you can just replace this with an array of strings of the same size as features, since their order will be equivalent (purely for storage). The Dictionary is necessary because of the need for a reverse lookup from names->assets.

if (name == null || feature == null)
return false;

features[nameToFAID.Count] = feature;
Copy link
Collaborator

Choose a reason for hiding this comment

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

features is an array, and it's only ever initialized to size 0. I don't see any lines where this array expands in size, so I think any time you call Add, you'll get an array index out of bounds exception.

Copy link
Collaborator

Choose a reason for hiding this comment

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

On further inspection, the only way this array gets created otherwise is by [de]serialization, so this is okay. This does limit the FeatureLibrary to being editor-only, and it can't be easily modified via code.


public bool Contains(string name) => nameToFAID.ContainsKey(name);

public bool Contains(ushort faid) => 0 <= faid && faid < features.Length;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This zero is very important
=> 0 <=

{
string str = "";

foreach(Entry e in this)
Copy link
Collaborator

Choose a reason for hiding this comment

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

i'm guessing this is implicitly calling IEnumerable.GetEnumerator()- neat syntax

[SerializeField]
private List<string> serializedNames;
[SerializeField]
private List<FeatureAsset> serializedFeatures;
Copy link
Collaborator

Choose a reason for hiding this comment

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

if i remember right, only the Dictionary has trouble serializing. the FeatureAsset[] features should be okay, so based on that, serializedFeatures might be unnecessary. If so, it can be replaced with just the list of strings in the same order as the FeatureAsset array.

Copy link
Collaborator

@rushingseas8 rushingseas8 left a comment

Choose a reason for hiding this comment

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

Generally looks good to me. Working with it in the Unity editor felt pretty okay.

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

Labels

enhancement New feature or request feature-editor Something related to the Feature Editor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants