-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSoundEditor.cs
141 lines (109 loc) · 2.5 KB
/
SoundEditor.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System.Collections.Generic;
using System.IO;
using System;
namespace Nitemare3D
{
public class SoundEditor : Scene
{
int soundCount;
int index = 0;
string name = "";
List<string> names = new List<string>();
void LoadSoundNames()
{
var lines = File.ReadAllLines("SoundConsts.cs");
for (int i = 0; i < names.Count; i++)
{
names[i] = lines[i + 4].Split(' ')[3];
}
}
float inputTime = .3f;
float inputTimer = .3f;
public override void Update()
{
GameWindow.DrawText(0, 150, "Name: " + name, 31);
GameWindow.DrawText(0, 160, "Left Click to play sound", 31);
if (name.Length > 0)
{
names[index] = name;
}
GameWindow.DrawText(0, 230, "Press F5 to save, F1 to exit", 31);
if(inputTimer > inputTime)
{
if(Input.text.Length > 0)
{
inputTimer = 0;
}
name += Input.text;
}
if(Input.text.Length > 0)
{
if(inputTimer > inputTime)
{
name += Input.text;
inputTimer = 0;
}
}
inputTimer += Time.dt;
if (Input.IsKeyDown(KeyboardKey.Left) && inputTimer > inputTime)
{
inputTimer = 0;
index--;
if(index < 0){index++;}
name = names[index];
}
if (Input.IsKeyDown(KeyboardKey.Right) && inputTimer > inputTime)
{
inputTimer = 0;
index++;
if(index > Dat.Snd.Count){index--;}
name = names[index];
}
if (Input.LeftClick() && inputTimer > inputTime)
{
inputTimer = 0;
SoundEffect.PlaySound(SoundEffect.soundOffset + index);
}
if (Input.IsKeyDown(KeyboardKey.F5) && inputTimer > inputTime)
{
GenerateCSFile();
inputTimer = 0;
}
if (Input.IsKeyDown(KeyboardKey.Backspace) && inputTimer > inputTime)
{
if (name.Length > 0)
{
name = name.Substring(0, name.Length - 1);
}
}
}
void GenerateCSFile()
{
var file = File.CreateText("SoundConsts.cs");
file.WriteLine("namespace Nitemare3D\n{\n\tpublic static class SoundConsts\n\t{");
for (int i = 0; i < names.Count; i++)
{
int index = SoundEffect.soundOffset + i;
file.WriteLine("\t\tpublic const int " + names[i].Replace("\n", string.Empty) + " = " + index + ";");
}
file.WriteLine("\t}\n}");
file.Close();
}
public override void Load()
{
soundCount = Dat.Snd.Count;
songid = 0;
//load sounds
for (int i = SoundEffect.soundOffset; i < Dat.Snd.Count; i++)
{
var dat = Dat.Snd[i];
names.Add("SND_" + i);
}
LoadSoundNames();
name = names[index];
}
public override void UnLoad()
{
}
}
}