253 lines
7.4 KiB
C#
253 lines
7.4 KiB
C#
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/Puzzles/CamOffset.cs")]
|
|
public class CamOffset : Area2D
|
|
{
|
|
public new class MethodName : Area2D.MethodName
|
|
{
|
|
public new static readonly StringName _Ready = "_Ready";
|
|
|
|
public new static readonly StringName _Process = "_Process";
|
|
|
|
public static readonly StringName Enter = "Enter";
|
|
|
|
public static readonly StringName Exit = "Exit";
|
|
}
|
|
|
|
public new class PropertyName : Area2D.PropertyName
|
|
{
|
|
public static readonly StringName offset = "offset";
|
|
|
|
public static readonly StringName returnOnExit = "returnOnExit";
|
|
|
|
public static readonly StringName step = "step";
|
|
|
|
public static readonly StringName inside = "inside";
|
|
}
|
|
|
|
public new class SignalName : Area2D.SignalName
|
|
{
|
|
}
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Vector2 offset;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private bool returnOnExit = true;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private float step = 0.01f;
|
|
|
|
private Entity inside;
|
|
|
|
public override void _Ready()
|
|
{
|
|
base.BodyEntered += Enter;
|
|
base.BodyExited += Exit;
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
if (Main.inEvent == null)
|
|
{
|
|
if (inside == Player.instance.controlling)
|
|
{
|
|
CameraController.instance.offset = CameraController.instance.offset.Lerp(offset, step * Main.deltaTime);
|
|
}
|
|
else if (returnOnExit)
|
|
{
|
|
CameraController.instance.offset = CameraController.instance.offset.Lerp(Room.current.camOffset, step * Main.deltaTime);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Enter(Node other)
|
|
{
|
|
if (other == Player.instance?.controlling)
|
|
{
|
|
inside = Player.instance.controlling;
|
|
}
|
|
}
|
|
|
|
private void Exit(Node other)
|
|
{
|
|
if (other == Player.instance?.controlling)
|
|
{
|
|
inside = null;
|
|
}
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
internal static List<MethodInfo> GetGodotMethodList()
|
|
{
|
|
return new List<MethodInfo>(4)
|
|
{
|
|
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.Enter, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, new List<PropertyInfo>
|
|
{
|
|
new PropertyInfo(Variant.Type.Object, "other", PropertyHint.None, "", PropertyUsageFlags.Default, new StringName("Node"), exported: false)
|
|
}, null),
|
|
new MethodInfo(MethodName.Exit, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, new List<PropertyInfo>
|
|
{
|
|
new PropertyInfo(Variant.Type.Object, "other", PropertyHint.None, "", PropertyUsageFlags.Default, new StringName("Node"), exported: false)
|
|
}, 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.Enter && args.Count == 1)
|
|
{
|
|
Enter(VariantUtils.ConvertTo<Node>(in args[0]));
|
|
ret = default(godot_variant);
|
|
return true;
|
|
}
|
|
if (method == MethodName.Exit && args.Count == 1)
|
|
{
|
|
Exit(VariantUtils.ConvertTo<Node>(in args[0]));
|
|
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.Enter)
|
|
{
|
|
return true;
|
|
}
|
|
if (method == MethodName.Exit)
|
|
{
|
|
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.offset)
|
|
{
|
|
offset = VariantUtils.ConvertTo<Vector2>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.returnOnExit)
|
|
{
|
|
returnOnExit = VariantUtils.ConvertTo<bool>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.step)
|
|
{
|
|
step = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.inside)
|
|
{
|
|
inside = VariantUtils.ConvertTo<Entity>(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.offset)
|
|
{
|
|
value = VariantUtils.CreateFrom(in offset);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.returnOnExit)
|
|
{
|
|
value = VariantUtils.CreateFrom(in returnOnExit);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.step)
|
|
{
|
|
value = VariantUtils.CreateFrom(in step);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.inside)
|
|
{
|
|
value = VariantUtils.CreateFrom(in inside);
|
|
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.Vector2, PropertyName.offset, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Bool, PropertyName.returnOnExit, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.step, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Object, PropertyName.inside, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false)
|
|
};
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override void SaveGodotObjectData(GodotSerializationInfo info)
|
|
{
|
|
base.SaveGodotObjectData(info);
|
|
info.AddProperty(PropertyName.offset, Variant.From(in offset));
|
|
info.AddProperty(PropertyName.returnOnExit, Variant.From(in returnOnExit));
|
|
info.AddProperty(PropertyName.step, Variant.From(in step));
|
|
info.AddProperty(PropertyName.inside, Variant.From(in inside));
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override void RestoreGodotObjectData(GodotSerializationInfo info)
|
|
{
|
|
base.RestoreGodotObjectData(info);
|
|
if (info.TryGetProperty(PropertyName.offset, out var value))
|
|
{
|
|
offset = value.As<Vector2>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.returnOnExit, out var value2))
|
|
{
|
|
returnOnExit = value2.As<bool>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.step, out var value3))
|
|
{
|
|
step = value3.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.inside, out var value4))
|
|
{
|
|
inside = value4.As<Entity>();
|
|
}
|
|
}
|
|
}
|