Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SevenSegmentDisplayElectricElement.cs
浏览该文件的文档.
1using Engine;
2
3namespace Game {
6
7 public float m_voltage = 1f / 0f;
8
9 public GlowPoint[] m_glowPoints = new GlowPoint[7];
10
11 public Color m_color;
12
13 public Vector2[] m_centers = [
14 new(0f, 6f),
15 new(-4f, 3f),
16 new(-4f, -3f),
17 new(0f, -6f),
18 new(4f, -3f),
19 new(4f, 3f),
20 new(0f, 0f)
21 ];
22
23 public Vector2[] m_sizes = [
24 new(3.2f, 1f),
25 new(1f, 2.3f),
26 new(1f, 2.3f),
27 new(3.2f, 1f),
28 new(1f, 2.3f),
29 new(1f, 2.3f),
30 new(3.2f, 1f)
31 ];
32
33 public int[] m_patterns = [
34 63,
35 6,
36 91,
37 79,
38 102,
39 109,
40 125,
41 7,
42 127,
43 111,
44 119,
45 124,
46 57,
47 94,
48 121,
49 113
50 ];
51
52 public SevenSegmentDisplayElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace) :
53 base(subsystemElectricity, cellFace) => m_subsystemGlow = subsystemElectricity.Project.FindSubsystem<SubsystemGlow>(true);
54
55 public override void OnAdded() {
56 CellFace cellFace = CellFaces[0];
57 int data = Terrain.ExtractData(SubsystemElectricity.SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z));
58 int mountingFace = SevenSegmentDisplayBlock.GetMountingFace(data);
60 for (int i = 0; i < 7; i++) {
61 Vector3 v = new(cellFace.X + 0.5f, cellFace.Y + 0.5f, cellFace.Z + 0.5f);
62 Vector3 vector = CellFace.FaceToVector3(mountingFace);
63 Vector3 vector2 = mountingFace < 4 ? Vector3.UnitY : Vector3.UnitX;
64 Vector3 v2 = Vector3.Cross(vector, vector2);
65 m_glowPoints[i] = m_subsystemGlow.AddGlowPoint();
66 m_glowPoints[i].Position = v
67 - 0.4375f * CellFace.FaceToVector3(mountingFace)
68 + m_centers[i].X * 0.0625f * v2
69 + m_centers[i].Y * 0.0625f * vector2;
70 m_glowPoints[i].Forward = vector;
71 m_glowPoints[i].Right = v2 * m_sizes[i].X * 0.0625f;
72 m_glowPoints[i].Up = vector2 * m_sizes[i].Y * 0.0625f;
74 m_glowPoints[i].Size = 1.35f;
75 m_glowPoints[i].FarSize = 1.35f;
76 m_glowPoints[i].FarDistance = 1f;
77 m_glowPoints[i].Type = m_sizes[i].X > m_sizes[i].Y ? GlowPointType.HorizontalRectangle : GlowPointType.VerticalRectangle;
78 }
79 }
80
81 public override void OnRemoved() {
82 for (int i = 0; i < 7; i++) {
83 m_subsystemGlow.RemoveGlowPoint(m_glowPoints[i]);
84 }
85 }
86
87 public override bool Simulate() {
88 float voltage = m_voltage;
89 m_voltage = 0f;
90 foreach (ElectricConnection connection in Connections) {
91 if (connection.ConnectorType != ElectricConnectorType.Output
92 && connection.NeighborConnectorType != 0) {
94 }
95 }
96 if (m_voltage != voltage) {
97 int num = (int)MathF.Round(m_voltage * 15f);
98 for (int i = 0; i < 7; i++) {
99 m_glowPoints[i].Color = (m_patterns[num] & (1 << i)) != 0 ? m_color : Color.Transparent;
100 }
101 }
102 return false;
103 }
104 }
105}
static int Max(int x1, int x2)
ElectricConnectorType ConnectorType
ElectricConnectorType NeighborConnectorType
virtual float GetOutputVoltage(int face)
List< ElectricConnection > Connections
ReadOnlyList< CellFace > CellFaces
static readonly Color[] LedColors
MountedElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace)
SevenSegmentDisplayElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace) override void OnAdded()
virtual int GetCellValue(int x, int y, int z)
static int ExtractData(int value)
static Color Transparent
定义 Color.cs:5
static Vector3 Cross(Vector3 v1, Vector3 v2)
static readonly Vector3 UnitX
static Vector3 FaceToVector3(int face)