Skip to content

Commit

Permalink
Use arrow syntax for properties
Browse files Browse the repository at this point in the history
  • Loading branch information
vanjac committed Nov 10, 2023
1 parent 92a5309 commit b772d52
Show file tree
Hide file tree
Showing 37 changed files with 89 additions and 192 deletions.
6 changes: 2 additions & 4 deletions Assets/Base/ActivatedSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,13 @@ public override string ToString()

public Filter filter = new EntityTypeFilter(Entity.objectType);

public override ICollection<Property> Properties()
{
return Property.JoinProperties(new Property[]
public override ICollection<Property> Properties() =>
Property.JoinProperties(new Property[]
{
new Property("fil", "Filter",
() => filter,
v => filter = (Filter)v,
PropertyGUIs.Filter,
true) // explicit type
}, base.Properties());
}
}
11 changes: 3 additions & 8 deletions Assets/Base/CustomTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ public static CustomTexture FromBaseMaterial(Material baseMat, bool overlay)
return customTex;
}

public ICollection<Property> Properties()
{
return new Property[]
public ICollection<Property> Properties() =>
new Property[]
{
new Property("bas", "Base",
() => baseMat,
Expand All @@ -146,12 +145,8 @@ public ICollection<Property> Properties()
v => filter = (CustomFilter)v,
PropertyGUIs.Enum)
};
}

public ICollection<Property> DeprecatedProperties()
{
return System.Array.Empty<Property>();
}
public ICollection<Property> DeprecatedProperties() => System.Array.Empty<Property>();

public static bool IsCustomTexture(Material material)
{
Expand Down
38 changes: 10 additions & 28 deletions Assets/Base/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,21 +242,16 @@ public override string ToString()

public virtual PropertiesObjectType ObjectType => objectType;

public virtual ICollection<Property> Properties()
{
return new Property[]
public virtual ICollection<Property> Properties() =>
new Property[]
{
new Property("tag", "Tag",
() => tag,
v => tag = (byte)v,
PropertyGUIs.Tag),
};
}

public virtual ICollection<Property> DeprecatedProperties()
{
return System.Array.Empty<Property>();
}
public virtual ICollection<Property> DeprecatedProperties() => Array.Empty<Property>();

// storeComponent: whether the "component" variable should be set
// this should usually be true, but false for clones
Expand Down Expand Up @@ -485,9 +480,8 @@ public BehaviorTargetProperty(EntityReference targetEntity, bool targetEntityIsA
public PropertiesObjectType ObjectType => BehaviorObjectType;
public virtual BehaviorType BehaviorObjectType => objectType;

public virtual ICollection<Property> Properties()
{
return new Property[]
public virtual ICollection<Property> Properties() =>
new Property[]
{
new Property("tar", "Target",
() => new BehaviorTargetProperty(targetEntity, targetEntityIsActivator),
Expand Down Expand Up @@ -530,12 +524,8 @@ public virtual ICollection<Property> Properties()
PropertyGUIs.BehaviorCondition(property);
})
};
}

public virtual ICollection<Property> DeprecatedProperties()
{
return System.Array.Empty<Property>();
}
public virtual ICollection<Property> DeprecatedProperties() => System.Array.Empty<Property>();

public abstract Behaviour MakeComponent(GameObject gameObject);
}
Expand Down Expand Up @@ -673,15 +663,9 @@ public abstract class Sensor : PropertiesObject

public virtual PropertiesObjectType ObjectType => objectType;

public virtual ICollection<Property> Properties()
{
return new Property[] { };
}
public virtual ICollection<Property> Properties() => new Property[] { };

public virtual ICollection<Property> DeprecatedProperties()
{
return System.Array.Empty<Property>();
}
public virtual ICollection<Property> DeprecatedProperties() => Array.Empty<Property>();

public abstract ISensorComponent MakeComponent(GameObject gameObject);
}
Expand Down Expand Up @@ -813,9 +797,8 @@ public abstract class DynamicEntity : Entity
public bool xRay = false;
public float health = 100;

public override ICollection<Property> Properties()
{
return Property.JoinProperties(base.Properties(), new Property[]
public override ICollection<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("xra", "X-Ray?",
() => xRay,
Expand All @@ -826,7 +809,6 @@ public override ICollection<Property> Properties()
v => health = (float)v,
PropertyGUIs.Float)
});
}

// update the DynamicEntity's appearance in the Editor
public virtual void UpdateEntityEditor() { }
Expand Down
6 changes: 2 additions & 4 deletions Assets/Base/Substance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ public class Substance : DynamicEntity
public Material highlightMaterial;
public VoxelFace defaultPaint;

public override ICollection<Property> Properties()
{
return Property.JoinProperties(base.Properties(), new Property[]
public override ICollection<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("piv", "Pivot",
() => pivot,
v => {pivot = (Pivot)v;},
PropertyGUIs.PivotProp),
});
}

public override EntityComponent InitEntityGameObject(VoxelArray voxelArray, bool storeComponent = true)
{
Expand Down
12 changes: 4 additions & 8 deletions Assets/Base/WorldProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ private void UpdateEnvironment()
GetReflectionProbe().RenderProbe();
}

public ICollection<Property> Properties()
{
return new Property[]
public ICollection<Property> Properties() =>
new Property[]
{
new Property("sky", "Sky",
() => RenderSettings.skybox,
Expand Down Expand Up @@ -123,11 +122,9 @@ public ICollection<Property> Properties()
v => RenderSettings.fogColor = (Color) v,
PropertyGUIs.Color)
};
}

public ICollection<Property> DeprecatedProperties()
{
return new Property[]
public ICollection<Property> DeprecatedProperties() =>
new Property[]
{
new Property("fdn", "Fog density",
() => RenderSettings.fog ? Mathf.Sqrt(RenderSettings.fogDensity) : 0.0f,
Expand All @@ -146,5 +143,4 @@ public ICollection<Property> DeprecatedProperties()
},
PropertyGUIs.Slider(0, 1)),
};
}
}
6 changes: 2 additions & 4 deletions Assets/Behaviors/Carryable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ public class CarryableBehavior : GenericEntityBehavior<CarryableBehavior, Carrya
public float throwSpeed = 0;
public float throwAngle = 25;

public override ICollection<Property> Properties()
{
return Property.JoinProperties(base.Properties(), new Property[]
public override ICollection<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("ths", "Throw speed",
() => throwSpeed,
Expand All @@ -31,7 +30,6 @@ public override ICollection<Property> Properties()
v => throwAngle = (float)v,
PropertyGUIs.Float),
});
}
}


Expand Down
6 changes: 2 additions & 4 deletions Assets/Behaviors/CharacterComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ public class CharacterBehavior : BasePhysicsBehavior
BehaviorType.NotBaseTypeRule(typeof(PlayerObject))));
public override BehaviorType BehaviorObjectType => objectType;

public override ICollection<Property> Properties()
{
return Property.JoinProperties(base.Properties(), new Property[]
public override ICollection<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("den", "Density",
() => density,
v => density = (float)v,
PropertyGUIs.Float)
});
}

public override Behaviour MakeComponent(GameObject gameObject)
{
Expand Down
6 changes: 2 additions & 4 deletions Assets/Behaviors/Force.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public enum ForceBehaviorMode
public float strength = 10;
public Target target = new Target(Target.UP);

public override ICollection<Property> Properties()
{
return Property.JoinProperties(base.Properties(), new Property[]
public override ICollection<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("fmo", "Mode",
() => mode,
Expand All @@ -50,7 +49,6 @@ public override ICollection<Property> Properties()
v => target = (Target)v,
PropertyGUIs.Target)
});
}
}

public class ForceComponent : BehaviorComponent<ForceBehavior>
Expand Down
6 changes: 2 additions & 4 deletions Assets/Behaviors/HaloComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ public class HaloBehavior : GenericEntityBehavior<HaloBehavior, HaloComponent>
public float size = 3;
public Color color = Color.white; // scaled by INTENSITY

public override ICollection<Property> Properties()
{
return Property.JoinProperties(base.Properties(), new Property[]
public override ICollection<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("siz", "Size",
() => size,
Expand All @@ -26,7 +25,6 @@ public override ICollection<Property> Properties()
v => color = (Color)v,
PropertyGUIs.Color)
});
}
}

public class HaloComponent : BehaviorComponent<HaloBehavior>
Expand Down
12 changes: 4 additions & 8 deletions Assets/Behaviors/HurtHeal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ public class HurtHealBehavior : GenericEntityBehavior<HurtHealBehavior, HurtHeal
public float rate = 0;
public (float, float) healthRange = (0, 200);

public override ICollection<Property> Properties()
{
return Property.JoinProperties(base.Properties(), new Property[]
public override ICollection<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("num", "Amount",
() => amount,
Expand All @@ -33,11 +32,9 @@ public override ICollection<Property> Properties()
v => healthRange = ((float, float))v,
PropertyGUIs.FloatRange)
});
}

public override ICollection<Property> DeprecatedProperties()
{
return Property.JoinProperties(base.DeprecatedProperties(), new Property[]
public override ICollection<Property> DeprecatedProperties() =>
Property.JoinProperties(base.DeprecatedProperties(), new Property[]
{
new Property("min", "Min health",
() => healthRange.Item1,
Expand All @@ -48,7 +45,6 @@ public override ICollection<Property> DeprecatedProperties()
v => healthRange.Item2 = (float)v,
PropertyGUIs.Float)
});
}
}

public class HurtHealComponent : BehaviorComponent<HurtHealBehavior>
Expand Down
12 changes: 4 additions & 8 deletions Assets/Behaviors/LightComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ public class LightBehavior : GenericEntityBehavior<LightBehavior, LightComponent
public bool shadows = false;
public bool halo = false; // deprecated

public override ICollection<Property> Properties()
{
return Property.JoinProperties(base.Properties(), new Property[]
public override ICollection<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("siz", "Size",
() => size,
Expand All @@ -37,18 +36,15 @@ public override ICollection<Property> Properties()
v => shadows = (bool)v,
PropertyGUIs.Toggle)
});
}

public override ICollection<Property> DeprecatedProperties()
{
return Property.JoinProperties(base.DeprecatedProperties(), new Property[]
public override ICollection<Property> DeprecatedProperties() =>
Property.JoinProperties(base.DeprecatedProperties(), new Property[]
{
new Property("hal", "Halo?",
() => halo,
v => halo = (bool)v,
PropertyGUIs.Toggle)
});
}
}

public class LightComponent : BehaviorComponent<LightBehavior>
Expand Down
6 changes: 2 additions & 4 deletions Assets/Behaviors/LookAt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ public class LookAtBehavior : GenericEntityBehavior<LookAtBehavior, LookAtCompon
public float speed = 120;
public bool yaw = true, pitch = false;

public override ICollection<Property> Properties()
{
return Property.JoinProperties(base.Properties(), new Property[]
public override ICollection<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("vel", "Speed",
() => speed,
Expand All @@ -41,7 +40,6 @@ public override ICollection<Property> Properties()
v => (yaw, pitch) = ((bool, bool))v,
PropertyGUIs.DoubleToggle)
});
}
}

public class LookAtComponent : MotionComponent<LookAtBehavior>
Expand Down
6 changes: 2 additions & 4 deletions Assets/Behaviors/Move.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ public class MoveBehavior : GenericEntityBehavior<MoveBehavior, MoveComponent>
public Target target = new Target(Target.NORTH);
public float speed = 1;

public override ICollection<Property> Properties()
{
return Property.JoinProperties(base.Properties(), new Property[]
public override ICollection<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("vel", "Speed",
() => speed,
Expand All @@ -28,7 +27,6 @@ public override ICollection<Property> Properties()
v => target = (Target)v,
PropertyGUIs.Target)
});
}
}

public class MoveComponent : MotionComponent<MoveBehavior>
Expand Down
6 changes: 2 additions & 4 deletions Assets/Behaviors/MoveWith.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ public class MoveWithBehavior : GenericEntityBehavior<MoveWithBehavior, MoveWith
public EntityReference target = new EntityReference(null);
public bool followRotation = true;

public override ICollection<Property> Properties()
{
return Property.JoinProperties(base.Properties(), new Property[]
public override ICollection<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("par", "Parent",
() => target,
Expand All @@ -27,7 +26,6 @@ public override ICollection<Property> Properties()
v => followRotation = (bool)v,
PropertyGUIs.Toggle)
});
}
}

public class MoveWithComponent : MotionComponent<MoveWithBehavior>
Expand Down
Loading

0 comments on commit b772d52

Please sign in to comment.