ManiaMap.Godot
Procedural generation of metroidvania style maps for Godot .NET.
CollectableResource.cs
1using Godot;
2
4{
8 [Tool]
9 [GlobalClass]
10 public partial class CollectableResource : Resource
11 {
12 private bool _editId;
16 [Export] public bool EditId { get => _editId; set => SetValidatedField(ref _editId, value); }
17
21 [Export] public int Id { get; set; } = Rand.GetRandomId();
22
23 private void SetValidatedField<T>(ref T field, T value)
24 {
25 field = value;
26 NotifyPropertyListChanged();
27 }
28
29 public override void _ValidateProperty(Godot.Collections.Dictionary property)
30 {
31 base._ValidateProperty(property);
32 var name = property["name"].AsStringName();
33
34 if (name == PropertyName.Id)
35 {
36 var flag = EditId ? PropertyUsageFlags.None : PropertyUsageFlags.ReadOnly;
37 property["usage"] = (int)(PropertyUsageFlags.Default | flag);
38 }
39 }
40 }
41}
A reference for a collectable with a unique ID.
bool EditId
If true, the Id property becomes editable in the inspector.
int Id
The unique ID associated with the collectable.
Contains the random number generator used for ID and random seed assignments.
Definition: Rand.cs:10
static int GetRandomId()
Returns a random positive integer ID.
Definition: Rand.cs:26