-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from Nytra/main
Add IsValidGenericTypeDriver, StringToTypeDriver, TypeFeedItem and TypeItemInterface, rework ComponentsDataFeed to use those for the component library
- Loading branch information
Showing
6 changed files
with
164 additions
and
7 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
ProjectObsidian/Components/Radiant UI/Data Feeds/Feeds/ComponentDataFeedItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using Elements.Core; | ||
using FrooxEngine; | ||
using System; | ||
|
||
namespace Obsidian; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
ProjectObsidian/Components/Radiant UI/Data Feeds/Interfaces/TypeFeedItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Elements.Core; | ||
using FrooxEngine; | ||
using System; | ||
|
||
namespace Obsidian; | ||
|
||
public class TypeFeedItem : DataFeedItem | ||
{ | ||
public Type Type; | ||
|
||
public bool IsGenericType; | ||
|
||
public Type GenericTypeDefinition; | ||
|
||
public SlimList<TypeFeedItem> GenericTypes; | ||
|
||
public int GenericTypesCount; | ||
|
||
public TypeFeedItem(Type type) | ||
{ | ||
InitBase(type.GetHashCode().ToString(), null, null, type.GetNiceName()); | ||
Type = type; | ||
IsGenericType = type.IsGenericType; | ||
GenericTypeDefinition = IsGenericType ? type.GetGenericTypeDefinition() : null; | ||
int count = 0; | ||
if (type.IsGenericTypeDefinition) | ||
{ | ||
foreach (Type genericType in WorkerInitializer.GetCommonGenericTypes(type)) | ||
{ | ||
TypeFeedItem typeFeedItem = new TypeFeedItem(genericType); | ||
typeFeedItem.InitBase(genericType.GetHashCode().ToString(), null, null, genericType.GetNiceName()); | ||
GenericTypes.Add(typeFeedItem); | ||
count++; | ||
} | ||
} | ||
GenericTypesCount = count; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
ProjectObsidian/Components/Radiant UI/Data Feeds/Interfaces/TypeItemInterface.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using FrooxEngine; | ||
|
||
namespace Obsidian; | ||
|
||
[Category(new string[] { "Obsidian/Radiant UI/Data Feeds/Interfaces" })] | ||
public class TypeItemInterface : FeedItemInterface | ||
{ | ||
public readonly SyncRef<IField<System.Type>> Type; | ||
|
||
public readonly SyncRef<IField<bool>> IsGenericType; | ||
|
||
public readonly SyncRef<IField<System.Type>> GenericTypeDefinition; | ||
|
||
public readonly SyncRef<IField<int>> GenericTypesCount; | ||
|
||
public readonly FeedSubTemplate<TypeFeedItem, TypeItemInterface> GenericTypes; | ||
|
||
public override void Set(IDataFeedView view, DataFeedItem item) | ||
{ | ||
base.Set(view, item); | ||
if (item is TypeFeedItem typeFeedItem) | ||
{ | ||
Type.TrySetTarget(typeFeedItem.Type); | ||
IsGenericType.TrySetTarget(typeFeedItem.IsGenericType); | ||
GenericTypeDefinition.TrySetTarget(typeFeedItem.GenericTypeDefinition); | ||
GenericTypesCount.TrySetTarget(typeFeedItem.GenericTypesCount); | ||
GenericTypes.Set(typeFeedItem.GenericTypes, view); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
ProjectObsidian/Components/Utility/IsValidGenericTypeDriver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Elements.Core; | ||
using FrooxEngine; | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Obsidian; | ||
|
||
[Category(new string[] { "Obsidian/Utility" })] | ||
public class IsValidGenericTypeDriver : Component | ||
{ | ||
public readonly SyncType Type; | ||
|
||
public readonly FieldDrive<bool> Target; | ||
|
||
protected override void OnChanges() | ||
{ | ||
base.OnChanges(); | ||
if (!Target.IsLinkValid) return; | ||
if (Type.Value == null || !Type.Value.IsGenericType) | ||
{ | ||
Target.Target.Value = false; | ||
} | ||
else | ||
{ | ||
Target.Target.Value = Type.Value.IsValidGenericType(validForInstantiation: true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Elements.Core; | ||
using FrooxEngine; | ||
using System; | ||
|
||
namespace Obsidian; | ||
|
||
[Category(new string[] { "Obsidian/Utility" })] | ||
public class StringToTypeDriver : Component | ||
{ | ||
public readonly Sync<string> Text; | ||
|
||
public readonly FieldDrive<Type> Target; | ||
|
||
protected override void OnChanges() | ||
{ | ||
base.OnChanges(); | ||
if (!Target.IsLinkValid) return; | ||
if (string.IsNullOrWhiteSpace(Text.Value)) | ||
{ | ||
Target.Target.Value = null; | ||
} | ||
else | ||
{ | ||
try | ||
{ | ||
var parsedType = WorkerManager.ParseNiceType(Text.Value); | ||
Target.Target.Value = parsedType; | ||
} | ||
catch (Exception ex) | ||
{ | ||
UniLog.Warning("Exception when parsing type from string:\n" + ex.ToString()); | ||
Target.Target.Value = null; | ||
} | ||
} | ||
} | ||
} |