-
Notifications
You must be signed in to change notification settings - Fork 0
/
LightDisplay.cs
101 lines (90 loc) · 2.64 KB
/
LightDisplay.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using Godot;
using GCol = Godot.Collections;
namespace FauxLight;
[Tool, GlobalClass]
public partial class LightDisplay : Node2D
{
public LightDisplay()
{
var shader = new ShaderMaterial() { Shader = GD.Load<Shader>("res://shaders/FauxLights.gdshader") };
shader.SetShaderParameter("handle_scale", true);
_lightHub = new(shader);
BackBufferCopy backBufferCopy = new() { CopyMode = BackBufferCopy.CopyModeEnum.Viewport };
AddChild(backBufferCopy);
AddChild(_lightHub);
}
[ExportGroup("Sources"), Export]
public GCol.Array<LightSource?> Sources
{
get => _lightHub.Sources;
set => _lightHub.Sources = value;
}
[Export]
public Texture2D? Texture
{
get => _lightHub.Texture;
set => _lightHub.Texture = value;
}
[ExportGroup("Dither"), Export(PropertyHint.Range, "0,1000")]
public int QuantizeSize
{
get => _lightHub.QuantizeSize;
set => _lightHub.QuantizeSize = value;
}
[Export(PropertyHint.Range, "1,16,1")]
public int Divisions
{
get => _lightHub.Divisions;
set => _lightHub.Divisions = value;
}
[Export(PropertyHint.Range, "1,3,1")]
public int Pattern
{
get => _lightHub.Pattern;
set => _lightHub.Pattern = value;
}
[Export]
public bool Dither
{
get => _lightHub.Dither;
set => _lightHub.Dither = value;
}
private LightMesh _lightHub;
public override void _Ready()
{
MoveChild(_lightHub, -1);
ChildEnteredTree += OnChildEnteredTree;
if (!Engine.IsEditorHint())
{
//Engine.TimeScale = 0.2;
}
}
private void OnChildEnteredTree(Node node)
{
if (_lightHub.GetIndex() != GetChildCount() - 1)
CallDeferred(MethodName.MoveChild, _lightHub, -1);
}
public override bool _PropertyCanRevert(StringName property)
{
if (property == PropertyName.Dither ||
property == PropertyName.Divisions ||
property == PropertyName.Pattern ||
property == PropertyName.QuantizeSize)
{
return true;
}
return base._PropertyCanRevert(property);
}
public override Variant _PropertyGetRevert(StringName property)
{
if (property == PropertyName.Dither)
return false;
else if (property == PropertyName.Divisions)
return 1;
else if (property == PropertyName.Pattern)
return 1;
else if (property == PropertyName.QuantizeSize)
return 1;
return base._PropertyGetRevert(property);
}
}