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

353 lines
10 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[ScriptPath("res://Scripts/Bullets/Blank.cs")]
public class Blank : Node2D, IBullet
{
public new class MethodName : Node2D.MethodName
{
public new static readonly StringName _Ready = "_Ready";
public new static readonly StringName _Process = "_Process";
public static readonly StringName ShotAt = "ShotAt";
}
public new class PropertyName : Node2D.PropertyName
{
public static readonly StringName grazed = "grazed";
public static readonly StringName HP = "HP";
public static readonly StringName node = "node";
public static readonly StringName anim = "anim";
public static readonly StringName generatedFrom = "generatedFrom";
public static readonly StringName type = "type";
public static readonly StringName randomRotation = "randomRotation";
public static readonly StringName rotationOverTime = "rotationOverTime";
public static readonly StringName easeIn = "easeIn";
public static readonly StringName easing = "easing";
}
public new class SignalName : Node2D.SignalName
{
}
[Export(PropertyHint.None, "")]
private float randomRotation;
[Export(PropertyHint.None, "")]
private float rotationOverTime;
[Export(PropertyHint.None, "")]
private float easeIn;
private float easing;
[Export(PropertyHint.None, "")]
public bool grazed { get; set; }
[Export(PropertyHint.None, "")]
public int HP { get; set; } = 1;
public Node2D node { get; set; }
public Action<Node> onShot { get; set; }
public AnimationPlayer anim { get; set; }
public BulletGenerator generatedFrom { get; set; }
[Export(PropertyHint.None, "")]
public IBullet.Type type { get; set; }
public override void _Ready()
{
if (randomRotation > 0f)
{
base.RotationDegrees = Main.RandomRange(0f, randomRotation);
}
node = this;
if (easeIn == 0f)
{
easing = 1f;
easeIn = 1f;
}
}
public override void _Process(double delta)
{
if (rotationOverTime != 0f)
{
base.RotationDegrees += rotationOverTime * Main.deltaTime * easing / easeIn;
}
if (easing < easeIn)
{
easing += Main.deltaTime;
}
}
public void ShotAt()
{
}
[EditorBrowsable(EditorBrowsableState.Never)]
internal static List<MethodInfo> GetGodotMethodList()
{
return new List<MethodInfo>(3)
{
new MethodInfo(MethodName._Ready, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, null, null),
new MethodInfo(MethodName._Process, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, new List<PropertyInfo>
{
new PropertyInfo(Variant.Type.Float, "delta", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false)
}, null),
new MethodInfo(MethodName.ShotAt, 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._Ready && args.Count == 0)
{
_Ready();
ret = default(godot_variant);
return true;
}
if (method == MethodName._Process && args.Count == 1)
{
_Process(VariantUtils.ConvertTo<double>(in args[0]));
ret = default(godot_variant);
return true;
}
if (method == MethodName.ShotAt && args.Count == 0)
{
ShotAt();
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._Ready)
{
return true;
}
if (method == MethodName._Process)
{
return true;
}
if (method == MethodName.ShotAt)
{
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.grazed)
{
grazed = VariantUtils.ConvertTo<bool>(in value);
return true;
}
if (name == PropertyName.HP)
{
HP = VariantUtils.ConvertTo<int>(in value);
return true;
}
if (name == PropertyName.node)
{
node = VariantUtils.ConvertTo<Node2D>(in value);
return true;
}
if (name == PropertyName.anim)
{
anim = VariantUtils.ConvertTo<AnimationPlayer>(in value);
return true;
}
if (name == PropertyName.generatedFrom)
{
generatedFrom = VariantUtils.ConvertTo<BulletGenerator>(in value);
return true;
}
if (name == PropertyName.type)
{
type = VariantUtils.ConvertTo<IBullet.Type>(in value);
return true;
}
if (name == PropertyName.randomRotation)
{
randomRotation = VariantUtils.ConvertTo<float>(in value);
return true;
}
if (name == PropertyName.rotationOverTime)
{
rotationOverTime = VariantUtils.ConvertTo<float>(in value);
return true;
}
if (name == PropertyName.easeIn)
{
easeIn = VariantUtils.ConvertTo<float>(in value);
return true;
}
if (name == PropertyName.easing)
{
easing = VariantUtils.ConvertTo<float>(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.grazed)
{
value = VariantUtils.CreateFrom<bool>(grazed);
return true;
}
if (name == PropertyName.HP)
{
value = VariantUtils.CreateFrom<int>(HP);
return true;
}
if (name == PropertyName.node)
{
value = VariantUtils.CreateFrom<Node2D>(node);
return true;
}
if (name == PropertyName.anim)
{
value = VariantUtils.CreateFrom<AnimationPlayer>(anim);
return true;
}
if (name == PropertyName.generatedFrom)
{
value = VariantUtils.CreateFrom<BulletGenerator>(generatedFrom);
return true;
}
if (name == PropertyName.type)
{
value = VariantUtils.CreateFrom<IBullet.Type>(type);
return true;
}
if (name == PropertyName.randomRotation)
{
value = VariantUtils.CreateFrom(in randomRotation);
return true;
}
if (name == PropertyName.rotationOverTime)
{
value = VariantUtils.CreateFrom(in rotationOverTime);
return true;
}
if (name == PropertyName.easeIn)
{
value = VariantUtils.CreateFrom(in easeIn);
return true;
}
if (name == PropertyName.easing)
{
value = VariantUtils.CreateFrom(in easing);
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.Bool, PropertyName.grazed, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Int, PropertyName.HP, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Object, PropertyName.node, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Object, PropertyName.anim, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Object, PropertyName.generatedFrom, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Int, PropertyName.type, PropertyHint.Enum, "Normal,Blue,Orange,Green,Yellow,Block", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Float, PropertyName.randomRotation, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Float, PropertyName.rotationOverTime, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Float, PropertyName.easeIn, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Float, PropertyName.easing, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false)
};
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void SaveGodotObjectData(GodotSerializationInfo info)
{
base.SaveGodotObjectData(info);
info.AddProperty(PropertyName.grazed, Variant.From<bool>(grazed));
info.AddProperty(PropertyName.HP, Variant.From<int>(HP));
info.AddProperty(PropertyName.node, Variant.From<Node2D>(node));
info.AddProperty(PropertyName.anim, Variant.From<AnimationPlayer>(anim));
info.AddProperty(PropertyName.generatedFrom, Variant.From<BulletGenerator>(generatedFrom));
info.AddProperty(PropertyName.type, Variant.From<IBullet.Type>(type));
info.AddProperty(PropertyName.randomRotation, Variant.From(in randomRotation));
info.AddProperty(PropertyName.rotationOverTime, Variant.From(in rotationOverTime));
info.AddProperty(PropertyName.easeIn, Variant.From(in easeIn));
info.AddProperty(PropertyName.easing, Variant.From(in easing));
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void RestoreGodotObjectData(GodotSerializationInfo info)
{
base.RestoreGodotObjectData(info);
if (info.TryGetProperty(PropertyName.grazed, out var value))
{
grazed = value.As<bool>();
}
if (info.TryGetProperty(PropertyName.HP, out var value2))
{
HP = value2.As<int>();
}
if (info.TryGetProperty(PropertyName.node, out var value3))
{
node = value3.As<Node2D>();
}
if (info.TryGetProperty(PropertyName.anim, out var value4))
{
anim = value4.As<AnimationPlayer>();
}
if (info.TryGetProperty(PropertyName.generatedFrom, out var value5))
{
generatedFrom = value5.As<BulletGenerator>();
}
if (info.TryGetProperty(PropertyName.type, out var value6))
{
type = value6.As<IBullet.Type>();
}
if (info.TryGetProperty(PropertyName.randomRotation, out var value7))
{
randomRotation = value7.As<float>();
}
if (info.TryGetProperty(PropertyName.rotationOverTime, out var value8))
{
rotationOverTime = value8.As<float>();
}
if (info.TryGetProperty(PropertyName.easeIn, out var value9))
{
easeIn = value9.As<float>();
}
if (info.TryGetProperty(PropertyName.easing, out var value10))
{
easing = value10.As<float>();
}
}
}