2025-05-03 20:36:17 +08:00

186 lines
5.0 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[ScriptPath("res://Scripts/Bullets/DrillTriple.cs")]
public class DrillTriple : Control
{
public new class MethodName : Control.MethodName
{
public new static readonly StringName _EnterTree = "_EnterTree";
public static readonly StringName Blue = "Blue";
public static readonly StringName Flip = "Flip";
}
public new class PropertyName : Control.PropertyName
{
public static readonly StringName pivot = "pivot";
public static readonly StringName drills = "drills";
}
public new class SignalName : Control.SignalName
{
}
[Export(PropertyHint.None, "")]
private Node2D pivot;
[Export(PropertyHint.None, "")]
private Blank[] drills;
public override void _EnterTree()
{
Blue();
}
private void Blue()
{
int num = Main.RandomRange(0, 2);
for (int i = 0; i < drills.Length; i++)
{
drills[i].grazed = false;
if (i == num)
{
drills[i].Modulate = Main.colorCyan;
drills[i].type = IBullet.Type.Blue;
}
else
{
drills[i].Modulate = Main.colorWhite;
drills[i].type = IBullet.Type.Normal;
}
}
}
public void Flip()
{
pivot.RotationDegrees += 180f;
Blue();
}
[EditorBrowsable(EditorBrowsableState.Never)]
internal static List<MethodInfo> GetGodotMethodList()
{
return new List<MethodInfo>(3)
{
new MethodInfo(MethodName._EnterTree, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, null, null),
new MethodInfo(MethodName.Blue, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, null, null),
new MethodInfo(MethodName.Flip, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, null, null)
};
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
{
if (method == MethodName._EnterTree && args.Count == 0)
{
_EnterTree();
ret = default(godot_variant);
return true;
}
if (method == MethodName.Blue && args.Count == 0)
{
Blue();
ret = default(godot_variant);
return true;
}
if (method == MethodName.Flip && args.Count == 0)
{
Flip();
ret = default(godot_variant);
return true;
}
return base.InvokeGodotClassMethod(in method, args, out ret);
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override bool HasGodotClassMethod(in godot_string_name method)
{
if (method == MethodName._EnterTree)
{
return true;
}
if (method == MethodName.Blue)
{
return true;
}
if (method == MethodName.Flip)
{
return true;
}
return base.HasGodotClassMethod(in method);
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override bool SetGodotClassPropertyValue(in godot_string_name name, in godot_variant value)
{
if (name == PropertyName.pivot)
{
pivot = VariantUtils.ConvertTo<Node2D>(in value);
return true;
}
if (name == PropertyName.drills)
{
drills = VariantUtils.ConvertToSystemArrayOfGodotObject<Blank>(in value);
return true;
}
return base.SetGodotClassPropertyValue(in name, in value);
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override bool GetGodotClassPropertyValue(in godot_string_name name, out godot_variant value)
{
if (name == PropertyName.pivot)
{
value = VariantUtils.CreateFrom(in pivot);
return true;
}
if (name == PropertyName.drills)
{
GodotObject[] array = drills;
value = VariantUtils.CreateFromSystemArrayOfGodotObject(array);
return true;
}
return base.GetGodotClassPropertyValue(in name, out value);
}
[EditorBrowsable(EditorBrowsableState.Never)]
internal static List<PropertyInfo> GetGodotPropertyList()
{
return new List<PropertyInfo>
{
new PropertyInfo(Variant.Type.Object, PropertyName.pivot, PropertyHint.NodeType, "Node2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Array, PropertyName.drills, PropertyHint.TypeString, "24/34:Node2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true)
};
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void SaveGodotObjectData(GodotSerializationInfo info)
{
base.SaveGodotObjectData(info);
info.AddProperty(PropertyName.pivot, Variant.From(in pivot));
StringName name = PropertyName.drills;
GodotObject[] array = drills;
info.AddProperty(name, Variant.CreateFrom(array));
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void RestoreGodotObjectData(GodotSerializationInfo info)
{
base.RestoreGodotObjectData(info);
if (info.TryGetProperty(PropertyName.pivot, out var value))
{
pivot = value.As<Node2D>();
}
if (info.TryGetProperty(PropertyName.drills, out var value2))
{
drills = value2.AsGodotObjectArray<Blank>();
}
}
}