Skip to content
This repository was archived by the owner on Jul 16, 2020. It is now read-only.

Commit bcbe202

Browse files
authored
Merge pull request #68 from mixer/fix-set-property-api
Fix SetProperty API
2 parents 14a32b0 + 02e1807 commit bcbe202

File tree

4 files changed

+145
-14
lines changed

4 files changed

+145
-14
lines changed

Source/InteractiveSDK/Assets/MixerInteractive/Source/Scripts/InteractiveControl.cs

+47-2
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,31 @@ public void SetDisabled(bool disabled)
8686
/// </summary>
8787
/// <param name="name">The name of the control property.</param>
8888
/// <param name="value">The value of the control property.</param>
89+
public void SetProperty(InteractiveControlProperty name, bool value)
90+
{
91+
SetPropertyImpl(
92+
InteractivityManager.SingletonInstance.InteractiveControlPropertyToString(name),
93+
value
94+
);
95+
}
96+
public void SetProperty(InteractiveControlProperty name, double value)
97+
{
98+
SetPropertyImpl(
99+
InteractivityManager.SingletonInstance.InteractiveControlPropertyToString(name),
100+
value
101+
);
102+
}
103+
public void SetProperty(InteractiveControlProperty name, string value)
104+
{
105+
SetPropertyImpl(
106+
InteractivityManager.SingletonInstance.InteractiveControlPropertyToString(name),
107+
value
108+
);
109+
}
89110
public void SetProperty(InteractiveControlProperty name, object value)
90111
{
91112
SetPropertyImpl(
92-
InteractivityManager.SingletonInstance.InteractiveControlPropertyToString(name),
113+
InteractivityManager.SingletonInstance.InteractiveControlPropertyToString(name),
93114
value
94115
);
95116
}
@@ -99,14 +120,38 @@ public void SetProperty(InteractiveControlProperty name, object value)
99120
/// </summary>
100121
/// <param name="name">The name of the control property.</param>
101122
/// <param name="value">The value of the control property.</param>
123+
public void SetProperty(string name, bool value)
124+
{
125+
SetPropertyImpl(name, value);
126+
}
127+
public void SetProperty(string name, double value)
128+
{
129+
SetPropertyImpl(name, value);
130+
}
131+
public void SetProperty(string name, string value)
132+
{
133+
SetPropertyImpl(name, value);
134+
}
102135
public void SetProperty(string name, object value)
103136
{
104137
SetPropertyImpl(name, value);
105138
}
106139

140+
private void SetPropertyImpl(string name, bool value)
141+
{
142+
InteractivityManager.SingletonInstance._QueuePropertyUpdate(SceneID, ControlID, name, value);
143+
}
144+
private void SetPropertyImpl(string name, double value)
145+
{
146+
InteractivityManager.SingletonInstance._QueuePropertyUpdate(SceneID, ControlID, name, value);
147+
}
148+
private void SetPropertyImpl(string name, string value)
149+
{
150+
InteractivityManager.SingletonInstance._QueuePropertyUpdate(SceneID, ControlID, name, value);
151+
}
107152
private void SetPropertyImpl(string name, object value)
108153
{
109-
InteractivityManager.SingletonInstance.QueuePropertyUpdate(SceneID, ControlID, name, value);
154+
InteractivityManager.SingletonInstance._QueuePropertyUpdate(SceneID, ControlID, name, value);
110155
}
111156

112157
internal InteractiveControl(string controlID, string kind, InteractiveEventType type, bool disabled, string helpText, string eTag, string sceneID)

Source/InteractiveSDK/Assets/MixerInteractive/Source/Scripts/InteractiveLabelControl.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public string Text
5252
public void SetText(string text)
5353
{
5454
InteractivityManager interactivityManager = InteractivityManager.SingletonInstance;
55-
interactivityManager.QueuePropertyUpdate(
55+
interactivityManager._QueuePropertyUpdate(
5656
SceneID,
5757
ControlID,
5858
interactivityManager.InteractiveControlPropertyToString(InteractiveControlProperty.Text),

Source/InteractiveSDK/Assets/MixerInteractive/Source/Scripts/InteractivityManager.cs

+97-11
Original file line numberDiff line numberDiff line change
@@ -1327,12 +1327,24 @@ public void SendQueuedSetControlPropertyUpdates()
13271327
jsonWriter.WriteStartObject();
13281328
jsonWriter.WritePropertyName(WS_MESSAGE_KEY_CONTROL_ID);
13291329
jsonWriter.WriteValue(controlID);
1330-
Dictionary<string, object> controlPropertyData = _queuedControlPropertyUpdates[sceneID][controlID].properties;
1330+
Dictionary<string, InternalControlPropertyMetaData> controlPropertyData = _queuedControlPropertyUpdates[sceneID][controlID].properties;
13311331
var controlPropertyDataKeys = controlPropertyData.Keys;
13321332
foreach (string controlPropertyDataKey in controlPropertyDataKeys)
13331333
{
13341334
jsonWriter.WritePropertyName(controlPropertyDataKey);
1335-
jsonWriter.WriteValue(controlPropertyData[controlPropertyDataKey].ToString());
1335+
InternalControlPropertyMetaData controlPropertyMetaData = controlPropertyData[controlPropertyDataKey];
1336+
if (controlPropertyMetaData.type == KnownControlPropertyPrimitiveTypes.Boolean)
1337+
{
1338+
jsonWriter.WriteValue(controlPropertyMetaData.boolValue);
1339+
}
1340+
else if (controlPropertyMetaData.type == KnownControlPropertyPrimitiveTypes.Number)
1341+
{
1342+
jsonWriter.WriteValue(controlPropertyMetaData.numberValue);
1343+
}
1344+
else
1345+
{
1346+
jsonWriter.WriteValue(controlPropertyMetaData.stringValue);
1347+
}
13361348
}
13371349
jsonWriter.WriteEndObject();
13381350
}
@@ -3868,12 +3880,33 @@ private void UpdateInternalTextBoxState(InteractiveTextEventArgs e)
38683880
_textboxValuesByParticipant[e.Participant.UserID][e.ControlID] = text;
38693881
}
38703882

3871-
internal void QueuePropertyUpdate(string sceneID, string controlID, string name, object value)
3883+
internal void _QueuePropertyUpdate(string sceneID, string controlID, string name, bool value)
3884+
{
3885+
KnownControlPropertyPrimitiveTypes type = KnownControlPropertyPrimitiveTypes.Boolean;
3886+
_QueuePropertyUpdateImpl(sceneID, controlID, name, type, value);
3887+
}
3888+
internal void _QueuePropertyUpdate(string sceneID, string controlID, string name, double value)
3889+
{
3890+
KnownControlPropertyPrimitiveTypes type = KnownControlPropertyPrimitiveTypes.Number;
3891+
_QueuePropertyUpdateImpl(sceneID, controlID, name, type, value);
3892+
}
3893+
internal void _QueuePropertyUpdate(string sceneID, string controlID, string name, string value)
3894+
{
3895+
KnownControlPropertyPrimitiveTypes type = KnownControlPropertyPrimitiveTypes.String;
3896+
_QueuePropertyUpdateImpl(sceneID, controlID, name, type, value);
3897+
}
3898+
internal void _QueuePropertyUpdate(string sceneID, string controlID, string name, object value)
3899+
{
3900+
KnownControlPropertyPrimitiveTypes type = KnownControlPropertyPrimitiveTypes.Unknown;
3901+
_QueuePropertyUpdateImpl(sceneID, controlID, name, type, value);
3902+
}
3903+
3904+
internal void _QueuePropertyUpdateImpl(string sceneID, string controlID, string name, KnownControlPropertyPrimitiveTypes type, object value)
38723905
{
38733906
// If a scene entry doesn't exist, add one.
38743907
if (!_queuedControlPropertyUpdates.ContainsKey(sceneID))
38753908
{
3876-
InternalControlPropertyUpdateData controlPropertyData = new InternalControlPropertyUpdateData(name, value);
3909+
InternalControlPropertyUpdateData controlPropertyData = new InternalControlPropertyUpdateData(name, type, value);
38773910
Dictionary<string, InternalControlPropertyUpdateData> controlData = new Dictionary<string, InternalControlPropertyUpdateData>();
38783911
controlData.Add(controlID, controlPropertyData);
38793912
_queuedControlPropertyUpdates.Add(sceneID, controlData);
@@ -3884,20 +3917,34 @@ internal void QueuePropertyUpdate(string sceneID, string controlID, string name,
38843917
Dictionary<string, InternalControlPropertyUpdateData> controlData = _queuedControlPropertyUpdates[sceneID];
38853918
if (!controlData.ContainsKey(controlID))
38863919
{
3887-
InternalControlPropertyUpdateData controlPropertyData = new InternalControlPropertyUpdateData(name, value);
3920+
InternalControlPropertyUpdateData controlPropertyData = new InternalControlPropertyUpdateData(name, type, value);
38883921
_queuedControlPropertyUpdates[sceneID].Add(controlID, controlPropertyData);
38893922
}
38903923
else
38913924
{
38923925
// Control entry exists, but does property entry exist?
38933926
InternalControlPropertyUpdateData controlPropertyData = controlData[controlID];
3927+
InternalControlPropertyMetaData controlPropertyMetaData = new InternalControlPropertyMetaData();
3928+
controlPropertyMetaData.type = type;
3929+
if (type == KnownControlPropertyPrimitiveTypes.Boolean)
3930+
{
3931+
controlPropertyMetaData.boolValue = (bool)value;
3932+
}
3933+
else if (type == KnownControlPropertyPrimitiveTypes.Number)
3934+
{
3935+
controlPropertyMetaData.numberValue = (double)value;
3936+
}
3937+
else
3938+
{
3939+
controlPropertyMetaData.stringValue = value.ToString();
3940+
}
38943941
if (!controlPropertyData.properties.ContainsKey(name))
38953942
{
3896-
_queuedControlPropertyUpdates[sceneID][controlID].properties.Add(name, value);
3943+
_queuedControlPropertyUpdates[sceneID][controlID].properties.Add(name, controlPropertyMetaData);
38973944
}
38983945
else
38993946
{
3900-
_queuedControlPropertyUpdates[sceneID][controlID].properties[name] = value;
3947+
_queuedControlPropertyUpdates[sceneID][controlID].properties[name] = controlPropertyMetaData;
39013948
}
39023949
}
39033950
}
@@ -3985,14 +4032,53 @@ internal struct InternalButtonState
39854032

39864033
internal struct InternalControlPropertyUpdateData
39874034
{
3988-
internal Dictionary<string, object> properties;
3989-
public InternalControlPropertyUpdateData(string name, object value)
4035+
internal Dictionary<string, InternalControlPropertyMetaData> properties;
4036+
public InternalControlPropertyUpdateData(string name, KnownControlPropertyPrimitiveTypes type, object value)
39904037
{
3991-
properties = new Dictionary<string, object>();
3992-
properties.Add(name, value);
4038+
properties = new Dictionary<string, InternalControlPropertyMetaData>();
4039+
InternalControlPropertyMetaData typeData = new InternalControlPropertyMetaData();
4040+
typeData.type = type;
4041+
// This should never fail, but just in case.
4042+
try
4043+
{
4044+
if (type == KnownControlPropertyPrimitiveTypes.Boolean)
4045+
{
4046+
typeData.boolValue = (bool)value;
4047+
}
4048+
else if (type == KnownControlPropertyPrimitiveTypes.Number)
4049+
{
4050+
typeData.numberValue = (double)value;
4051+
}
4052+
else
4053+
{
4054+
typeData.stringValue = value.ToString();
4055+
}
4056+
}
4057+
catch (Exception ex)
4058+
{
4059+
InteractivityManager.SingletonInstance.LogError("Failed to cast the value to a known type. Exception: " + ex.Message);
4060+
}
4061+
properties.Add(name, typeData);
39934062
}
39944063
}
39954064

4065+
internal struct InternalControlPropertyMetaData
4066+
{
4067+
public object objectValue;
4068+
public bool boolValue;
4069+
public double numberValue;
4070+
public string stringValue;
4071+
public KnownControlPropertyPrimitiveTypes type;
4072+
}
4073+
4074+
internal enum KnownControlPropertyPrimitiveTypes
4075+
{
4076+
Unknown,
4077+
Boolean,
4078+
Number,
4079+
String
4080+
}
4081+
39964082
internal struct InternalJoystickState
39974083
{
39984084
internal double X;
Binary file not shown.

0 commit comments

Comments
 (0)