Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 40 additions & 25 deletions Assets/Arcweave/Plugin/Editor/ArcweaveProjectAssetInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using UnityEngine;
using UnityEditor;
using System.Collections.Generic;

namespace Arcweave
{
Expand Down Expand Up @@ -72,16 +71,13 @@ public override void OnInspectorGUI() {
GUILayout.Label("Global Variables:", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
bool hasGlobalVariables = false;
foreach ( var variable in aw.Project.Variables)
{
if(variable.Parent == null)
{
foreach ( var variable in aw.Project.Variables ) {
if ( variable.Parent == null ) {
hasGlobalVariables = true;
EditorGUILayout.LabelField(variable.Name, variable.Value?.ToString());
}
}
if (!hasGlobalVariables)
{
if ( !hasGlobalVariables ) {
EditorGUILayout.LabelField("(None)");
}
EditorGUI.indentLevel--;
Expand All @@ -91,25 +87,44 @@ public override void OnInspectorGUI() {
// Board Variables Section - Grouped by Board
GUILayout.Label("Board Variables:", EditorStyles.boldLabel);
bool hasBoardVariables = false;
foreach (var board in aw.Project.Boards)
{
if (board.Variables != null && board.Variables.Count > 0)
{
hasBoardVariables = true;
EditorGUI.indentLevel++;
GUILayout.Label(string.IsNullOrEmpty(board.Name) ? $"Board: {board.Id}" : board.Name, EditorStyles.miniLabel);
EditorGUI.indentLevel++;
foreach (var variable in board.Variables)
{
string variableName = variable.Name;
EditorGUILayout.LabelField(variableName, variable.Value?.ToString());
}
EditorGUI.indentLevel -= 2;
GUILayout.Space(5);
foreach ( var board in aw.Project.Boards ) {
if ( board.Variables == null || board.Variables.Count == 0 ) { continue; }

hasBoardVariables = true;
EditorGUI.indentLevel++;
GUILayout.Label(string.IsNullOrEmpty(board.Name) ? $"Board: {board.Id}" : board.Name, EditorStyles.miniLabel);
EditorGUI.indentLevel++;
foreach ( var variable in board.Variables ) {
EditorGUILayout.LabelField(variable.Name, variable.Value?.ToString());
}
EditorGUI.indentLevel -= 2;
GUILayout.Space(5);
}
if (!hasBoardVariables)
{
if ( !hasBoardVariables ) {
EditorGUI.indentLevel++;
EditorGUILayout.LabelField("(None)");
EditorGUI.indentLevel--;
}

GUILayout.Space(10);

// Component Variables Section - Grouped by Component
GUILayout.Label("Component Variables:", EditorStyles.boldLabel);
bool hasComponentVariables = false;
foreach ( var component in aw.Project.Components ) {
if ( component.Variables == null || component.Variables.Count == 0 ) { continue; }

hasComponentVariables = true;
EditorGUI.indentLevel++;
GUILayout.Label(string.IsNullOrEmpty(component.Name) ? $"Component: {component.Id}" : component.Name, EditorStyles.miniLabel);
EditorGUI.indentLevel++;
foreach ( var variable in component.Variables ) {
EditorGUILayout.LabelField(variable.Name, variable.Value?.ToString());
}
EditorGUI.indentLevel -= 2;
GUILayout.Space(5);
}
if ( !hasComponentVariables ) {
EditorGUI.indentLevel++;
EditorGUILayout.LabelField("(None)");
EditorGUI.indentLevel--;
Expand All @@ -128,4 +143,4 @@ public override void OnInspectorGUI() {
}
}

#endif
#endif
18 changes: 17 additions & 1 deletion Assets/Arcweave/Plugin/Editor/ProjectViewerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ public class ProjectViewerWindow : EditorWindow
private readonly Color NODE_DEFAULT_COLOR = COLOR_THEMES["default"];

private ArcweaveProjectAsset _asset;
#if UNITY_6000_5_OR_NEWER
private EntityId _assetID;
#else
private int _assetID;
#endif
private Rect _canvasRect;
private Vector2 _translation;
private float _zoomFactor = 1f;
Expand All @@ -55,14 +59,22 @@ private ArcweaveProjectAsset asset {
get
{
if ( _asset == null ) {
#if UNITY_6000_5_OR_NEWER
_asset = EditorUtility.EntityIdToObject(_assetID) as ArcweaveProjectAsset;
#else
_asset = EditorUtility.InstanceIDToObject(_assetID) as ArcweaveProjectAsset;
#endif
}
return _asset;
}
set
{
_asset = value;
#if UNITY_6000_5_OR_NEWER
_assetID = value != null ? value.GetEntityId() : default;
#else
_assetID = value != null ? value.GetInstanceID() : 0;
#endif
}
}

Expand All @@ -88,7 +100,11 @@ private float zoomFactor {
public static void Open(ArcweaveProjectAsset asset) {
var window = GetWindow<ProjectViewerWindow>();
window._asset = asset;
#if UNITY_6000_5_OR_NEWER
window._assetID = asset.GetEntityId();
#else
window._assetID = asset.GetInstanceID();
#endif
window._currentBoardIndex = 0;
window.PanTo(asset.Project.Boards[0].Nodes[0].Pos - new Vector2(100, 100));
}
Expand Down Expand Up @@ -551,4 +567,4 @@ Vector2 GetPosAlongCurve(Vector2 from, Vector2 to, Vector2 fromTangent, Vector2
}
}

#endif
#endif
10 changes: 5 additions & 5 deletions Assets/Arcweave/Plugin/Runtime/Interpreter/ArcscriptFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ public object Reset(IList<object> args) {
}

public object ResetAll(IList<object> args) {
List<string> variableNames = new List<string>();
HashSet<string> variableIds = new HashSet<string>();
foreach ( IVariable argument in args ) {
variableNames.Add(argument.Name);
variableIds.Add(argument.Id);
}
foreach ( IVariable variable in this._project.Variables ) {
if ( !variableNames.Contains(variable.Name) ) {
foreach ( IVariable variable in this._project.GetAllVariables() ) {
if ( !variableIds.Contains(variable.Id) ) {
state.SetVarValue(variable, variable.DefaultValue);
}
}
Expand Down Expand Up @@ -212,4 +212,4 @@ public object ResetVisits(IList<object> args) {
return null;
}
}
}
}
16 changes: 5 additions & 11 deletions Assets/Arcweave/Plugin/Runtime/Interpreter/ArcscriptParserBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,11 @@ public ArcscriptParserBase(ITokenStream input, TextWriter output, TextWriter err

public void SetProject(IProject project) {
this.Project = project;
foreach (var projectVariable in project.Variables)
foreach (var projectVariable in project.GetAllVariables())
{
VariableNames.Add(projectVariable.Name);
}
foreach (var projectBoard in project.Boards)
{
if (projectBoard.Variables == null) continue;
foreach (var projectBoardVariable in projectBoard.Variables)
{
VariableNames.Add(projectBoard.CustomId + "." + projectBoardVariable.Name);
}
VariableNames.Add(projectVariable.Parent == null
? projectVariable.Name
: projectVariable.Parent.CustomId + "." + projectVariable.Name);
}
}

Expand Down Expand Up @@ -126,4 +120,4 @@ internal void setLineStart(IToken token)
}
}

}
}
15 changes: 6 additions & 9 deletions Assets/Arcweave/Plugin/Runtime/Interpreter/ArcscriptState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,9 @@ public ArcscriptState(string elementId, IProject project, System.Action<string>?
this.currentElement = elementId;
this.project = project;

this.Variables = project.Variables.ToDictionary(variable => variable.Id, variable => variable);
foreach (var projectBoard in project.Boards)
foreach (var variable in project.GetAllVariables())
{
if (projectBoard.Variables == null) continue;
foreach (var projectBoardVariable in projectBoard.Variables)
{
Variables.TryAdd(projectBoardVariable.Id, projectBoardVariable);
}
Variables.TryAdd(variable.Id, variable);
}

if (emit != null)
Expand All @@ -50,7 +45,9 @@ public ArcscriptState(string elementId, IProject project, System.Action<string>?
{
if (scope != null)
{
return variable.Name == name && scope == variable.Parent.CustomId;
return variable.Name == name &&
variable.Parent != null &&
scope == variable.Parent.CustomId;
}

return variable.Name == name && variable.Parent == null;
Expand Down Expand Up @@ -109,4 +106,4 @@ public void ResetVisits()
_emit("resetVisits");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public TranspilerOutput RunScript(string code)
// List<string> outputs = visitor.state.outputs;
var outputResult = visitor.state.Outputs.GetText();

var isCondition = tree.script() != null;
var isCondition = tree.condition() != null;

return new TranspilerOutput(outputResult, visitor.state.VariableChanges, result, isCondition);
}
Expand Down Expand Up @@ -112,4 +112,4 @@ public TranspilerOutput(string output, Dictionary<string, object> changes, objec
}
}
}
}
}
20 changes: 12 additions & 8 deletions Assets/Arcweave/Plugin/Runtime/Interpreter/INodes/IAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ public interface IAttribute
{
public enum DataType
{
Undefined,
StringPlainText,
StringRichText,
ComponentList,
AssetList,
Undefined = 0,
StringPlainText = 1,
StringRichText = 2,
ComponentList = 3,
AssetList = 4,
Boolean = 5,
Integer = 6,
Float = 7,
}

public enum ContainerType
{
Undefined,
Component,
Element,
Undefined = 0,
Component = 1,
Element = 2,
Board = 3,
}

public string Name { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Arcweave.Interpreter.INodes
{
public interface IBoard : IHasVariables
public interface IBoard : IHasVariables, IHasAttributes
{
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Arcweave.Interpreter.INodes
{
public interface IComponent : IHasAttributes
public interface IComponent : IHasAttributes, IHasVariables
{
}
}
3 changes: 3 additions & 0 deletions Assets/Arcweave/Plugin/Runtime/Interpreter/INodes/IProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ public interface IProject
#if GODOT
public Array<Arcweave.Project.Variable> Variables { get; }
public Dictionary<string, Arcweave.Project.Board> Boards { get; }
public Dictionary<string, Arcweave.Project.Component> Components { get; }
#else
public List<Arcweave.Project.Variable> Variables { get; }
public List<Arcweave.Project.Board> Boards { get; }
public List<Arcweave.Project.Component> Components { get; }
#endif
public System.Collections.Generic.IEnumerable<Arcweave.Project.Variable> GetAllVariables();
public Arcweave.Project.Element ElementWithId(string id);

public Arcweave.Project.Variable GetVariable(string name, string scope = null);
Expand Down
25 changes: 23 additions & 2 deletions Assets/Arcweave/Plugin/Runtime/Project/Attribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ namespace Arcweave.Project
public partial class Attribute
{

[field: SerializeField]
public string Id { get; private set; }
[field: SerializeField]
public string CustomId { get; private set; }
[field: SerializeField]
public string Name { get; private set; }
[field: SerializeField]
Expand All @@ -31,6 +35,15 @@ public partial class Attribute
[SerializeReference]
private List<Component> data_componentList;

[SerializeField]
private bool data_boolean;

[SerializeField]
private int data_integer;

[SerializeField]
private double data_float;

public object data {
get
{
Expand All @@ -48,13 +61,18 @@ public object data {
return data_stringRichText;
}
if ( Type == IAttribute.DataType.ComponentList ) { return data_componentList; }
if ( Type == IAttribute.DataType.Boolean ) { return data_boolean; }
if ( Type == IAttribute.DataType.Integer ) { return data_integer; }
if ( Type == IAttribute.DataType.Float ) { return data_float; }
return null;
}
}

public void InitializeInProject(Project project) { this.project = project; }

internal void Set(string name, IAttribute.DataType type, object _data, IAttribute.ContainerType containerType, string containerId) {
internal void Set(string id, string customId, string name, IAttribute.DataType type, object _data, IAttribute.ContainerType containerType, string containerId) {
this.Id = id;
this.CustomId = customId;
this.Name = name;
this.Type = type;
if ( type == IAttribute.DataType.StringPlainText ) { data_string = (string)_data; }
Expand All @@ -65,8 +83,11 @@ internal void Set(string name, IAttribute.DataType type, object _data, IAttribut
data_stringRichText = null;
}
if ( type == IAttribute.DataType.ComponentList ) { data_componentList = (List<Component>)_data; }
if ( type == IAttribute.DataType.Boolean ) { data_boolean = (bool)_data; }
if ( type == IAttribute.DataType.Integer ) { data_integer = (int)_data; }
if ( type == IAttribute.DataType.Float ) { data_float = (double)_data; }
this.containerType = containerType;
this.containerId = containerId;
}
}
}
}
Loading