This repository has been archived by the owner on Jan 4, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
SfxrSoundExporter.cs
executable file
·143 lines (110 loc) · 3.97 KB
/
SfxrSoundExporter.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
142
143
//
// Copyright (c) Jesse Freeman, Pixel Vision 8. All rights reserved.
//
// Licensed under the Microsoft Public License (MS-PL) except for a few
// portions of the code. See LICENSE file in the project root for full
// license information. Third-party libraries used by Pixel Vision 8 are
// under their own licenses. Please refer to those libraries for details
// on the license they use.
//
// Contributors
// --------------------------------------------------------
// This is the official list of Pixel Vision 8 contributors:
//
// Jesse Freeman - @JesseFreeman
// Christina-Antoinette Neofotistou @CastPixel
// Christer Kaitila - @McFunkypants
// Pedro Medeiros - @saint11
// Shawn Rakowski - @shwany
//
using PixelVision8.Player;
using PixelVision8.Runner;
using System.Text;
using PixelVision8.Runner.Exporters;
namespace PixelVision8.Editor
{
public class SfxrSoundExporter : AbstractExporter
{
private readonly PixelVision targetEngine;
private StringBuilder sb;
private SfxrSoundChip _sfxrSoundChip;
public SfxrSoundExporter(string fileName, PixelVision targetEngine) : base(fileName)
{
this.targetEngine = targetEngine;
_sfxrSoundChip = targetEngine.SoundChip as SfxrSoundChip;
// CalculateSteps();
}
public override void CalculateSteps()
{
base.CalculateSteps();
// Create a new string builder
Steps.Add(CreateStringBuilder);
Steps.Add(SaveGameData);
// Save the final string builder
Steps.Add(CloseStringBuilder);
}
private void SaveGameData()
{
var soundChip = targetEngine.SoundChip;
sb.Append("\"version\":\"v2\",");
JsonUtil.GetLineBreak(sb, 1);
JsonUtil.indentLevel++;
sb.Append("\"sounds\": [");
var total = soundChip.TotalSounds;
for (var i = 0; i < total; i++)
{
var sound = _sfxrSoundChip.ReadSound(i);
// if (sound != null)
// {
JsonUtil.indentLevel++;
// {
// "name":"Melody",
// "settings":"0,.5,,.2,,.2,.3,.1266,,,,,,,,,,,,,,,,,,1,,,,,,"
// },
sb.Append("{");
JsonUtil.GetLineBreak(sb, 1);
sb.Append("\"name\":\"");
sb.Append(sound.name);
sb.Append("\",");
JsonUtil.GetLineBreak(sb, 1);
sb.Append("\"settings\":");
sb.Append("\"" + sound.param + "\"");
JsonUtil.GetLineBreak(sb, 1);
sb.Append("}");
// sb.Append(sound.ReadSettings());
if (i < total - 1) sb.Append(",");
JsonUtil.GetLineBreak(sb, 1);
JsonUtil.indentLevel--;
// }
}
JsonUtil.indentLevel--;
JsonUtil.GetLineBreak(sb, 1);
sb.Append("]");
CurrentStep++;
}
private void CreateStringBuilder()
{
sb = new StringBuilder();
sb.Append("{");
JsonUtil.indentLevel++;
JsonUtil.GetLineBreak(sb);
sb.Append("\"SoundChip\":");
JsonUtil.GetLineBreak(sb);
sb.Append("{");
JsonUtil.GetLineBreak(sb, 1);
// JsonUtil.indentLevel++;
CurrentStep++;
}
private void CloseStringBuilder()
{
JsonUtil.indentLevel--;
JsonUtil.GetLineBreak(sb);
sb.Append("}");
JsonUtil.indentLevel--;
JsonUtil.GetLineBreak(sb, 1);
sb.Append("}");
Bytes = Encoding.UTF8.GetBytes(sb.ToString());
CurrentStep++;
}
}
}