Skip to content

Commit

Permalink
492 support for typed attributes (#493)
Browse files Browse the repository at this point in the history
* attributes as a Dictionary<string, dynamic> + untested changes to make Unity run again..
Create si/bd/ro/rk OK

* Correct VectorX & float casting from attributes

*  Fix templated object creation

* Fix slot slot positioning

* Fix temperature parsing in Item

* Remove unused code/LocalizedText

* Remove attributes lists from OgreeObject: Unity Editor cannot display dynamic variables

* Support for new displayContent interaction for Group

* Positionner.ComputePosition use the good type for posXYZ & rotation

* Better format for JArrays in GUIObjectInfos

* Doc & cleanup

* Better switches for changing height or size

* Even better switches

* Avoid double casting

* Typo
  • Loading branch information
Cedrok authored Apr 26, 2024
1 parent 4c775d1 commit 66f9c77
Show file tree
Hide file tree
Showing 38 changed files with 241 additions and 292 deletions.
8 changes: 0 additions & 8 deletions Assets/Localization/Logs Shared Data.asset
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,6 @@ MonoBehaviour:
m_Key: Tcp server will listen
m_Metadata:
m_Items: []
- m_Id: 371025540157440
m_Key: Temperature must be a numerical value
m_Metadata:
m_Items: []
- m_Id: 404037640261632
m_Key: There is no template for
m_Metadata:
Expand Down Expand Up @@ -335,10 +331,6 @@ MonoBehaviour:
m_Key: Unknown ui command
m_Metadata:
m_Items: []
- m_Id: 444654990790656
m_Key: Unknown unit at creation
m_Metadata:
m_Items: []
- m_Id: 53240142368768
m_Key: Unrecognised temperature unit
m_Metadata:
Expand Down
12 changes: 1 addition & 11 deletions Assets/Localization/Logs_en.asset
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,6 @@ MonoBehaviour:
m_Metadata:
m_Items:
- rid: 5456596318824431623
- m_Id: 371025540157440
m_Localized: '{str}: Temperature must be a numerical value'
m_Metadata:
m_Items:
- rid: 5456596318824431623
- m_Id: 399082057502720
m_Localized: Set {str0} details level to {str1}
m_Metadata:
Expand Down Expand Up @@ -345,11 +340,6 @@ MonoBehaviour:
m_Metadata:
m_Items:
- rid: 5456596318824431623
- m_Id: 444654990790656
m_Localized: '{str0}: Unknown "{str1}" unit at creation'
m_Metadata:
m_Items:
- rid: 5456596318824431623
- m_Id: 451722313338880
m_Localized: '{str}: Parent not found, this object can''t be drawn as a standalone'
m_Metadata:
Expand Down Expand Up @@ -466,4 +456,4 @@ MonoBehaviour:
- rid: 5456596318824431623
type: {class: SmartFormatTag, ns: UnityEngine.Localization.Metadata, asm: Unity.Localization}
data:
m_Entries: 0010c6d51e0100000010866cfb25000000108603032600000010c65d73260000001046fde12600000010c68694270000001006dd862a0000001086ed902a00000010c650c12b0000001086f0b22c00000010863e762d00000010c6ef6b3000000010c6e30d3100000010060a4832000000104631d13300000010866e76480000001086bd134a0000001086606d4b000000108693104c0000001046b2424c00000010062c1c4e00000010c6d558500000001006e083550000001046c1903d010000100694944001000010c640b24101000010c6cad64e01000010068efe4e0100001086075750010000100675825001000010861d7251010000104688f66a0100001006600e6b010000104687116c0100001046dc206d010000108633876d0100001046371b6e010000100642296e010000108639e06e010000100658786f01000010466a3b70010000100663777701000010c635658901000010c64e69940100001006ccd69a01000010c666e5a00100001086aba0150500001086be8e1d0500001086cc66210500001046582f2205000010c6594d5905000010868d695b05000010c64dd15c050000100634886005000010461781650500001086daa1670500001086182c680500001006284a680500001006cf876a0500001006e5547005000010862ebc2f00000010462b282d000000b08f996c64180000b04fcf63641800
m_Entries: 0010c6d51e0100000010866cfb25000000108603032600000010c65d73260000001046fde12600000010c68694270000001006dd862a0000001086ed902a00000010c650c12b0000001086f0b22c00000010863e762d00000010c6ef6b3000000010c6e30d3100000010060a4832000000104631d13300000010866e76480000001086bd134a0000001086606d4b000000108693104c0000001046b2424c00000010062c1c4e00000010c6d558500000001006e083550000001046c1903d010000100694944001000010c640b24101000010c6cad64e01000010068efe4e01000010860757500100001006758250010000104688f66a0100001006600e6b010000104687116c0100001046dc206d010000108633876d0100001046371b6e010000100642296e010000108639e06e010000100658786f01000010466a3b70010000100663777701000010c63565890100001006ccd69a01000010c666e5a00100001086aba0150500001086be8e1d0500001086cc66210500001046582f2205000010c6594d5905000010868d695b05000010c64dd15c050000100634886005000010461781650500001086daa1670500001086182c680500001006284a680500001006cf876a0500001006e5547005000010862ebc2f00000010462b282d000000b08f996c64180000b04fcf63641800
12 changes: 1 addition & 11 deletions Assets/Localization/Logs_es.asset
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,6 @@ MonoBehaviour:
m_Metadata:
m_Items:
- rid: 3691382812341436417
- m_Id: 371025540157440
m_Localized: "{str}: La temperatura debe ser un valor num\xE9rico"
m_Metadata:
m_Items:
- rid: 3691382812341436417
- m_Id: 404037640261632
m_Localized: No hay un template para {str}
m_Metadata:
Expand Down Expand Up @@ -397,11 +392,6 @@ MonoBehaviour:
m_Localized: Comando de UI desconocido
m_Metadata:
m_Items: []
- m_Id: 444654990790656
m_Localized: "{str0}: Unidad \"{str1}\" desconocida durante la creaci\xF3n"
m_Metadata:
m_Items:
- rid: 3691382812341436417
- m_Id: 53240142368768
m_Localized: 'Unidad de temperatura desconocida: {str}'
m_Metadata:
Expand Down Expand Up @@ -451,4 +441,4 @@ MonoBehaviour:
- rid: 3691382812341436417
type: {class: SmartFormatTag, ns: UnityEngine.Localization.Metadata, asm: Unity.Localization}
data:
m_Entries: 0010860303260000001086daa16705000010462b282d0000001006cf876a05000010c6cad64e010000108639e06e0100001006284a680500001006dd862a0000001006600e6b010000100642296e0100001046371b6e0100001086606d4b00000010866e76480000001086bd134a00000010c640b241010000100634886005000010461781650500001086182c6805000010062c1c4e0000001046b2424c00000010c68694270000001046fde12600000010c65d732600000010c6d558500000001086f0b22c0000001086ed902a000000104687116c010000108633876d0100001046dc206d0100001046c1903d0100001086cc662105000010863e762d00000010c650c12b00000010862ebc2f000000108693104c000000104631d133000000100663777701000010c666e5a00100001006e554700500001006ccd69a01000010866cfb2500000010868d695b05000010c6d51e010000001006758250010000104688f66a010000100694944001000010861d7251010000100658786f01000010c64dd15c0500001086aba01505000010466a3b700100001046582f2205000010860757500100001086be8e1d05000010c635658901000010c64e699401000010c6ef6b3000000010c6e30d3100000010c6594d5905000010068efe4e0100001006e08355000000b08f996c641800
m_Entries: 0010860303260000001086daa16705000010462b282d0000001006cf876a05000010c6cad64e010000108639e06e0100001006284a680500001006dd862a0000001006600e6b010000100642296e0100001046371b6e0100001086606d4b00000010866e76480000001086bd134a00000010c640b241010000100634886005000010461781650500001086182c6805000010062c1c4e0000001046b2424c00000010c68694270000001046fde12600000010c65d732600000010c6d558500000001086f0b22c0000001086ed902a000000104687116c010000108633876d0100001046dc206d0100001046c1903d0100001086cc662105000010863e762d00000010c650c12b00000010862ebc2f000000108693104c000000104631d133000000100663777701000010c666e5a00100001006e554700500001006ccd69a01000010866cfb2500000010868d695b05000010c6d51e010000001006758250010000104688f66a0100001006949440010000100658786f01000010c64dd15c0500001086aba01505000010466a3b700100001046582f2205000010860757500100001086be8e1d05000010c635658901000010c6ef6b3000000010c6e30d3100000010c6594d5905000010068efe4e0100001006e08355000000b08f996c641800
12 changes: 1 addition & 11 deletions Assets/Localization/Logs_fr.asset
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,6 @@ MonoBehaviour:
m_Metadata:
m_Items:
- rid: 5456596318824431624
- m_Id: 371025540157440
m_Localized: "{str} : La temp\xE9rature doit \xEAtre une valeur num\xE9rique"
m_Metadata:
m_Items:
- rid: 5456596318824431624
- m_Id: 399184461434880
m_Localized: "Origine de {str} affich\xE9e"
m_Metadata:
Expand Down Expand Up @@ -332,11 +327,6 @@ MonoBehaviour:
m_Metadata:
m_Items:
- rid: 5456596318824431624
- m_Id: 444654990790656
m_Localized: "{str0}: Unit\xE9 \"{str1}\" inconnue lors de la cr\xE9ation"
m_Metadata:
m_Items:
- rid: 5456596318824431624
- m_Id: 451722313338880
m_Localized: "{str}\_: Parent introuvable, cet objet ne peut pas \xEAtre dessin\xE9
de mani\xE8re autonome"
Expand Down Expand Up @@ -455,4 +445,4 @@ MonoBehaviour:
- rid: 5456596318824431624
type: {class: SmartFormatTag, ns: UnityEngine.Localization.Metadata, asm: Unity.Localization}
data:
m_Entries: 0010c6d51e0100000010866cfb25000000108603032600000010c65d73260000001046fde12600000010c68694270000001006dd862a0000001086ed902a00000010c650c12b0000001086f0b22c00000010863e762d00000010c6ef6b3000000010c6e30d31000000104631d13300000010866e76480000001086bd134a0000001086606d4b000000108693104c0000001046b2424c00000010062c1c4e00000010c6d558500000001006e083550000001046c1903d010000100694944001000010c640b24101000010c6cad64e01000010068efe4e0100001086075750010000100675825001000010861d72510100001006600e6b010000104687116c010000104688f66a0100001046dc206d010000108633876d0100001046371b6e010000100642296e010000108639e06e010000100658786f01000010466a3b70010000100663777701000010c635658901000010c64e69940100001006ccd69a01000010c666e5a00100001086aba0150500001086be8e1d0500001086cc66210500001046582f2205000010c6594d5905000010868d695b05000010c64dd15c050000100634886005000010461781650500001086daa1670500001086182c680500001006284a680500001006cf876a0500001006e5547005000010862ebc2f00000010462b282d000000b04fcf6364180000b08f996c641800
m_Entries: 0010c6d51e0100000010866cfb25000000108603032600000010c65d73260000001046fde12600000010c68694270000001006dd862a0000001086ed902a00000010c650c12b0000001086f0b22c00000010863e762d00000010c6ef6b3000000010c6e30d31000000104631d13300000010866e76480000001086bd134a0000001086606d4b000000108693104c0000001046b2424c00000010062c1c4e00000010c6d558500000001006e083550000001046c1903d010000100694944001000010c640b24101000010c6cad64e01000010068efe4e010000108607575001000010067582500100001006600e6b010000104687116c010000104688f66a0100001046dc206d010000108633876d0100001046371b6e010000100642296e010000108639e06e010000100658786f01000010466a3b70010000100663777701000010c63565890100001006ccd69a01000010c666e5a00100001086aba0150500001086be8e1d0500001086cc66210500001046582f2205000010c6594d5905000010868d695b05000010c64dd15c050000100634886005000010461781650500001086daa1670500001086182c680500001006284a680500001006cf876a0500001006e5547005000010862ebc2f00000010462b282d000000b04fcf6364180000b08f996c641800
12 changes: 1 addition & 11 deletions Assets/Localization/Logs_pt.asset
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,6 @@ MonoBehaviour:
m_Metadata:
m_Items:
- rid: 3691382812341436416
- m_Id: 371025540157440
m_Localized: "{str}: a temperatura deve ser um valor num\xE9rico"
m_Metadata:
m_Items:
- rid: 3691382812341436416
- m_Id: 404037640261632
m_Localized: "N\xE3o h\xE1 template para {str}"
m_Metadata:
Expand Down Expand Up @@ -396,11 +391,6 @@ MonoBehaviour:
m_Localized: Comando UI desconhecido
m_Metadata:
m_Items: []
- m_Id: 444654990790656
m_Localized: "{str0}: Unidade \"{str1}\" desconhecida na cria\xE7\xE3o"
m_Metadata:
m_Items:
- rid: 3691382812341436416
- m_Id: 53240142368768
m_Localized: 'Unidade de temperatura desconhecida: {str}'
m_Metadata:
Expand Down Expand Up @@ -451,4 +441,4 @@ MonoBehaviour:
- rid: 3691382812341436416
type: {class: SmartFormatTag, ns: UnityEngine.Localization.Metadata, asm: Unity.Localization}
data:
m_Entries: 0010860303260000001086daa16705000010462b282d0000001006cf876a05000010c6cad64e010000108639e06e0100001006284a680500001006dd862a0000001006600e6b010000100642296e0100001046371b6e0100001086606d4b00000010866e76480000001086bd134a00000010c640b241010000100634886005000010461781650500001086182c6805000010062c1c4e0000001046b2424c00000010c68694270000001046fde12600000010c65d732600000010c6d558500000001086f0b22c0000001086ed902a000000104687116c010000108633876d0100001046dc206d0100001046c1903d0100001086cc662105000010863e762d00000010c650c12b00000010862ebc2f000000108693104c000000104631d133000000100663777701000010c666e5a00100001006e554700500001006ccd69a01000010866cfb2500000010868d695b05000010c6d51e010000001006758250010000104688f66a010000100694944001000010861d7251010000100658786f01000010c64dd15c0500001086aba01505000010466a3b700100001046582f2205000010860757500100001086be8e1d05000010c635658901000010c64e699401000010c6ef6b3000000010c6e30d3100000010c6594d5905000010068efe4e0100001006e08355000000b04fcf6364180000b08f996c641800
m_Entries: 0010860303260000001086daa16705000010462b282d0000001006cf876a05000010c6cad64e010000108639e06e0100001006284a680500001006dd862a0000001006600e6b010000100642296e0100001046371b6e0100001086606d4b00000010866e76480000001086bd134a00000010c640b241010000100634886005000010461781650500001086182c6805000010062c1c4e0000001046b2424c00000010c68694270000001046fde12600000010c65d732600000010c6d558500000001086f0b22c0000001086ed902a000000104687116c010000108633876d0100001046dc206d0100001046c1903d0100001086cc662105000010863e762d00000010c650c12b00000010862ebc2f000000108693104c000000104631d133000000100663777701000010c666e5a00100001006e554700500001006ccd69a01000010866cfb2500000010868d695b05000010c6d51e010000001006758250010000104688f66a0100001006949440010000100658786f01000010c64dd15c0500001086aba01505000010466a3b700100001046582f2205000010860757500100001086be8e1d05000010c635658901000010c6ef6b3000000010c6e30d3100000010c6594d5905000010068efe4e0100001006e08355000000b04fcf6364180000b08f996c641800
9 changes: 2 additions & 7 deletions Assets/Scenes/Main.unity
Original file line number Diff line number Diff line change
Expand Up @@ -9949,9 +9949,9 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: 'Build date: 2024-04-22
m_text: 'Build date: 2024-04-25

Commit #d85083f1'
Commit #18c6c92d'
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2100000, guid: 79459efec17a4d00a321bdcc27bbc385, type: 2}
Expand Down Expand Up @@ -16221,8 +16221,6 @@ MonoBehaviour:
description:
domain:
tags: []
attributesKeys: []
attributesValues: []
currentLod: 0
originalLocalPosition: {x: -Infinity, y: -Infinity, z: -Infinity}
originalLocalRotation: {x: 0, y: 0, z: 0, w: 1}
Expand Down Expand Up @@ -19771,8 +19769,6 @@ MonoBehaviour:
description:
domain:
tags: []
attributesKeys: []
attributesValues: []
currentLod: 0
originalLocalPosition: {x: -Infinity, y: -Infinity, z: -Infinity}
originalLocalRotation: {x: 0, y: 0, z: 0, w: 1}
Expand Down Expand Up @@ -20153,7 +20149,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 79c1755e73e32d14ba7c2a990a4e34b8, type: 3}
m_Name:
m_EditorClassIdentifier:
camControlAllowed: 1
target: {fileID: 0}
coordModeController: {fileID: 1372162505}
lockMouseInteract: 0
Expand Down
5 changes: 3 additions & 2 deletions Assets/Scripts/CameraControl.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using TMPro;
using UnityEngine;

Expand Down Expand Up @@ -334,12 +335,12 @@ public void MoveToObject(Transform _target)
{
case Category.Rack:
transform.position = _target.GetChild(0).position;
offset = Utils.ParseVector2(obj.attributes["size"]).y / 45;
offset = ((JArray)obj.attributes["size"]).ToVector2().y / 45;
transform.eulerAngles = _target.eulerAngles + new Vector3(0, 180, 0);
break;
case Category.Device:
transform.position = _target.GetChild(0).position;
offset = Utils.ParseVector2(obj.attributes["size"]).y / 450;
offset = ((JArray)obj.attributes["size"]).ToVector2().y / 450;
transform.eulerAngles = _target.eulerAngles + new Vector3(0, 180, 0);
break;
default:
Expand Down
22 changes: 13 additions & 9 deletions Assets/Scripts/ClearanceHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using UnityEngine;

[System.Serializable]
Expand Down Expand Up @@ -111,17 +112,20 @@ public void BuildClearance()


// Apply scale and move all components to have the rack's pivot at the lower left corner
Vector2 size = Utils.ParseVector2(item.attributes["size"]);
float height = Utils.ParseDecFrac(item.attributes["height"]);
if (item.attributes["heightUnit"] == LengthUnit.U)
height *= UnitValue.U;
else if (item.attributes["heightUnit"] == LengthUnit.Centimeter)
height /= 100;
if (item.attributes["sizeUnit"] == LengthUnit.Millimeter)
Vector2 size = ((JArray)item.attributes["size"]).ToVector2();
float height = (float)item.attributes["height"];
height *= item.attributes["heightUnit"] switch
{
LengthUnit.U => UnitValue.U,
LengthUnit.OU => UnitValue.OU,
LengthUnit.Centimeter => 0.01f,
LengthUnit.Millimeter => 0.001f,
_ => 1
};
if ((string)item.attributes["sizeUnit"] == LengthUnit.Millimeter)
size /= 10;

clearanceWrapper.transform.localPosition = clearedObject.GetChild(0).localPosition;
clearanceWrapper.transform.localRotation = Quaternion.identity;
clearanceWrapper.transform.SetLocalPositionAndRotation(clearedObject.GetChild(0).localPosition, Quaternion.identity);
Transform clearanceObject = Object.Instantiate(GameManager.instance.clearanceModel, clearanceWrapper.transform).transform;
clearanceObject.transform.localScale = new Vector3(size.x / 100, height, size.y / 100);
clearanceObject.GetChild(0).GetComponent<ClearanceCollisionHandler>().ownObject = clearedObject;
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/CoordModeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private void OnEnable()
diagonalText.transform.parent.gameObject.SetActive(true);
diagonal.localPosition = bd.transform.position;
Room ro = (Room)bd;
hasNonDefaultOrientation = ro && ro.attributes["axisOrientation"] != AxisOrientation.Default;
hasNonDefaultOrientation = ro && (string)ro.attributes["axisOrientation"] != AxisOrientation.Default;
if (hasNonDefaultOrientation && ro.isSquare)
{
diagonalForNonDefaultOrientations.gameObject.SetActive(true);
Expand Down
31 changes: 18 additions & 13 deletions Assets/Scripts/DisplayObjectData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using TMPro;
using UnityEngine;

Expand Down Expand Up @@ -56,21 +57,25 @@ public void PlaceTexts(string _labelPos)
lodGroup = GetComponent<LODGroup>();
Transform shape = transform.GetChild(0);

if (item && item.attributes.ContainsKey("template") && !string.IsNullOrEmpty(item.attributes["template"]))
if (item && item.attributes.HasKeyAndValue("template"))
{
Vector2 size = Utils.ParseVector2(item.attributes["size"]);
if (item.attributes["sizeUnit"] == LengthUnit.Millimeter)
size /= 1000;
else if (item.attributes["sizeUnit"] == LengthUnit.Centimeter)
size /= 100;
Vector2 size = ((JArray)item.attributes["size"]).ToVector2();
size *= item.attributes["sizeUnit"] switch
{
LengthUnit.Centimeter => 0.01f,
LengthUnit.Millimeter => 0.001f,
_ => 1
};

float height = Utils.ParseDecFrac(item.attributes["height"]);
if (item.attributes["heightUnit"] == LengthUnit.U)
height *= UnitValue.U;
else if (item.attributes["heightUnit"] == LengthUnit.Millimeter)
height /= 1000;
else if (item.attributes["heightUnit"] == LengthUnit.Centimeter)
height /= 100;
float height = (float)item.attributes["height"];
height *= item.attributes["heightUnit"] switch
{
LengthUnit.U => UnitValue.U,
LengthUnit.OU => UnitValue.OU,
LengthUnit.Centimeter => 0.01f,
LengthUnit.Millimeter => 0.001f,
_ => 1
};
boxSize = new(size.x, height, size.y);
}
else
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Enums_Strucs/FixedValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class CommandParameter
public const string LabelBackground = "labelBackground";
public const string Alpha = "alpha";
public const string Slots = "slots";
public const string Content = "content";
public const string DisplayContent = "displayContent";
public const string U = "U";
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Enums_Strucs/SDataFromJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public struct SApiObject
public string description;
public string domain;
public List<string> tags;
public Dictionary<string, string> attributes;
public Dictionary<string, dynamic> attributes;
public SApiObject[] children;

public SApiObject(OgreeObject _src)
Expand Down
Loading

0 comments on commit 66f9c77

Please sign in to comment.