Skip to content

Commit

Permalink
Removed name prop from keys
Browse files Browse the repository at this point in the history
  • Loading branch information
crashkonijn committed Nov 14, 2024
1 parent 2c34c46 commit 1157e71
Show file tree
Hide file tree
Showing 23 changed files with 127 additions and 140 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using CrashKonijn.Goap.Core;
using CrashKonijn.Goap.Runtime;
using UnityEngine;
using UnityEngine.UIElements;

Expand All @@ -22,7 +23,7 @@ public ConditionElement(INodeCondition graphCondition, EditorWindowValues values

this.Circle = new Circle(this.GetCircleColor(graphCondition), 10f);
this.Add(this.Circle);

this.Label = new Label(this.GetText(graphCondition.Condition));
this.Add(this.Label);

Expand All @@ -37,47 +38,47 @@ private Color GetCircleColor(INodeCondition condition)
{
if (Application.isPlaying)
return this.GetLiveColor();

if (!condition.Connections.Any())
return Color.red;

return Color.green;
}

private Color GetLiveColor()
{
if (this.values.SelectedObject is not IMonoGoapActionProvider agent)
return Color.white;

if (agent.AgentType == null)
return Color.white;

var conditionObserver = agent.AgentType.GoapConfig.ConditionObserver;
conditionObserver.SetWorldData(agent.WorldData);

return conditionObserver.IsMet(this.GraphCondition.Condition) ? Color.green : Color.red;
}

private string GetText(ICondition condition)
{
var suffix = this.GetSuffix(condition);
return $"{condition.WorldKey.Name} {this.GetText(condition.Comparison)} {condition.Amount} {suffix}";

return $"{condition.WorldKey.GetName()} {this.GetText(condition.Comparison)} {condition.Amount} {suffix}";
}

private string GetSuffix(ICondition condition)
{
if (!Application.isPlaying)
return "";

if (this.values.SelectedObject is not IMonoGoapActionProvider agent)
return "";

var (exists, value) = agent.WorldData.GetWorldValue(condition.WorldKey);

return "(" + (exists ? value.ToString() : "-") + ")";
}

private string GetText(Comparison comparison)
{
switch (comparison)
Expand All @@ -91,8 +92,8 @@ private string GetText(Comparison comparison)
case Comparison.SmallerThanOrEqual:
return "<=";
}

return "";
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CrashKonijn.Goap.Core;
using CrashKonijn.Goap.Runtime;
using UnityEngine.UIElements;

namespace CrashKonijn.Goap.Editor
Expand All @@ -11,18 +12,18 @@ public EffectElement(INodeEffect graphEffect)
{
this.GraphEffect = graphEffect;
this.AddToClassList("effect");

this.Label = new Label(this.GetText(graphEffect.Effect));
this.Add(this.Label);
}

private string GetText(IEffect effect)
{
var suffix = effect.Increase ? "++" : "--";

return $"{effect.WorldKey.Name}{suffix}";
return $"{effect.WorldKey.GetName()}{suffix}";
}

public Label Label { get; set; }
}
}
}
4 changes: 2 additions & 2 deletions Package/Editor/CrashKonijn.Goap.Editor/Styles/GraphViewer.uss
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@
}

.node-wrapper, .child-wrapper {
flex-grow: 0; /* Don’t grow larger than content */
flex-shrink: 0; /* Don’t shrink smaller than content */
/*flex-grow: 0; !* Don’t grow larger than content *!*/
/*flex-shrink: 0; !* Don’t shrink smaller than content *!*/

margin: 10px 20px;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.Linq;
using CrashKonijn.Goap.Core;
using CrashKonijn.Goap.Runtime;
Expand All @@ -15,16 +14,16 @@ namespace CrashKonijn.Goap.Editor
public class GoapSetConfigEditor : UnityEditor.Editor
{
private GoapSetConfigScriptable config;

public override VisualElement CreateInspectorGUI()
{
this.config = (GoapSetConfigScriptable) this.target;

var root = new VisualElement();

var styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>($"{GoapEditorSettings.BasePath}/Styles/Generic.uss");
root.styleSheets.Add(styleSheet);

root.Add(this.Group("Upgrade", card =>
{
// CapabilityConfigScriptable capabilityScriptable = default;
Expand All @@ -42,15 +41,15 @@ public override VisualElement CreateInspectorGUI()
// });
//
// card.Add(input);

card.Add(new PropertyField(this.serializedObject.FindProperty("capabilityConfig")));

var button = new Button(() =>
{
this.Upgrade(this.config.capabilityConfig);
})
{
text = "Upgrade to CapabilityConfigs"
text = "Upgrade to CapabilityConfigs",
};

card.Add(button);
Expand All @@ -61,44 +60,44 @@ public override VisualElement CreateInspectorGUI()
card.Add(new PropertyField(this.serializedObject.FindProperty("actions")));
card.Add(new PropertyField(this.serializedObject.FindProperty("goals")));
}));

root.Add(this.Group("World Keys", card =>
{
card.Add(new PropertyField(this.serializedObject.FindProperty("worldSensors")));
card.Add(this.SimpleLabelView("World keys", this.config.GetWorldKeys(), (label, key) =>
{
label.text = key.Name;
label.text = key.GetName();
}));
}));

root.Add(this.Group("Targets", card =>
{
card.Add(new PropertyField(this.serializedObject.FindProperty("targetSensors")));
card.Add(this.SimpleLabelView("Target keys", this.config.GetTargetKeys(), (label, key) =>
{
label.text = key.Name;
label.text = key.GetName();
}));
}));

var validateButton = new Button(() =>
{
var validator = new AgentTypeConfigValidatorRunner();
var results = validator.Validate(this.config);

foreach (var error in results.GetErrors())
{
Debug.LogError(error);
}

foreach (var warning in results.GetWarnings())
{
Debug.LogWarning(warning);
}

if (!results.HasErrors() && !results.HasWarnings())
Debug.Log("No errors or warnings found!");
});

validateButton.Add(new Label("Validate"));

root.Add(validateButton);
Expand All @@ -115,88 +114,88 @@ private void Upgrade(CapabilityConfigScriptable capabilityScriptable)
{
goal = new ClassRef
{
Name = this.GetName(goalConfig.ClassType)
Name = this.GetName(goalConfig.ClassType),
},
baseCost = goalConfig.BaseCost,
conditions = goalConfig.Conditions.Select(x => new CapabilityCondition
{
worldKey = new ClassRef
{
Name = x.WorldKey.Name
Name = x.WorldKey.GetName(),
},
comparison = x.Comparison,
amount = x.Amount
}).ToList()
amount = x.Amount,
}).ToList(),
});
}

capabilityScriptable.actions.Clear();
foreach (var actionConfig in this.config.Actions)
{
capabilityScriptable.actions.Add(new CapabilityAction
{
action = new ClassRef
{
Name = this.GetName(actionConfig.ClassType)
Name = this.GetName(actionConfig.ClassType),
},
target = new ClassRef
{
Name = actionConfig.Target.Name
Name = actionConfig.Target.GetName(),
},
baseCost = actionConfig.BaseCost,
stoppingDistance = actionConfig.StoppingDistance,
conditions = actionConfig.Conditions.Select(x => new CapabilityCondition
{
worldKey = new ClassRef
{
Name = x.WorldKey.Name
Name = x.WorldKey.GetName(),
},
comparison = x.Comparison,
amount = x.Amount
amount = x.Amount,
}).ToList(),
effects = actionConfig.Effects.Select(x => new CapabilityEffect
{
worldKey = new ClassRef
{
Name = x.WorldKey.Name
Name = x.WorldKey.GetName(),
},
effect = x.Increase ? EffectType.Increase : EffectType.Decrease,
}).ToList()
}).ToList(),
});
}

capabilityScriptable.worldSensors.Clear();
foreach (var worldSensorConfig in this.config.WorldSensors)
{
capabilityScriptable.worldSensors.Add(new CapabilityWorldSensor
{
sensor = new ClassRef
{
Name = this.GetName(worldSensorConfig.ClassType)
Name = this.GetName(worldSensorConfig.ClassType),
},
worldKey = new ClassRef
{
Name = worldSensorConfig.Key.Name
}
Name = worldSensorConfig.Key.GetName(),
},
});
}

capabilityScriptable.targetSensors.Clear();
foreach (var targetSensorConfig in this.config.TargetSensors)
{
capabilityScriptable.targetSensors.Add(new CapabilityTargetSensor
{
sensor = new ClassRef
{
Name = this.GetName(targetSensorConfig.ClassType)
Name = this.GetName(targetSensorConfig.ClassType),
},
targetKey = new ClassRef
{
Name = targetSensorConfig.Key.Name
}
Name = targetSensorConfig.Key.GetName(),
},
});
}

EditorUtility.SetDirty(capabilityScriptable);
AssetDatabase.SaveAssetIfDirty(capabilityScriptable);
// Set selected object to the new capability scriptable
Expand All @@ -206,7 +205,7 @@ private void Upgrade(CapabilityConfigScriptable capabilityScriptable)
private string GetName(string fullName)
{
var parts = fullName.Split(',').First();

return parts.Split('.').Last();
}

Expand All @@ -230,12 +229,12 @@ private VisualElement SimpleLabelView<T>(string title, T[] list, Action<Label, T
{
bind(element as Label, list[index]);
},
selectionType = SelectionType.None
selectionType = SelectionType.None,
};
listView.AddToClassList("card");
foldout.Add(listView);

return foldout;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
namespace CrashKonijn.Goap.Core
{
public interface ITargetKey : IConfig
{
}
}
public interface ITargetKey { }
}
6 changes: 2 additions & 4 deletions Package/Runtime/CrashKonijn.Goap.Core/Interfaces/IWorldKey.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
namespace CrashKonijn.Goap.Core
{
public interface IWorldKey : IConfig
{
}
}
public interface IWorldKey { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@

namespace CrashKonijn.Goap.Runtime
{
public abstract class TargetKeyBase : ITargetKey
{
public string Name { get; set; }
}
}
public abstract class TargetKeyBase : ITargetKey { }
}
Loading

0 comments on commit 1157e71

Please sign in to comment.