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
/
code-sfx-tool.lua
159 lines (99 loc) · 3.85 KB
/
code-sfx-tool.lua
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
-- Create table to store the workspace tool logic
SFXTool = {}
SFXTool.__index = SFXTool
LoadScript("code-drop-down-menu")
LoadScript("code-instrument-panel")
LoadScript("code-sound-panel")
LoadScript("code-waveform-panel")
LoadScript("code-edit-panel")
LoadScript("pixel-vision-os-sound-progress-modal-v1")
function SFXTool:Init()
-- Create a new table for the instance with default properties
local _sfxTool = {
toolName = "Sound Editor",
runnerName = SystemName(),
rootPath = ReadMetadata("RootPath", "/"),
rootDirectory = ReadMetadata("directory", nil),
targetFile = ReadMetadata("file", nil),
invalid = true,
success = false,
playSound = false,
originalSounds = {},
canExport = ProgressModal ~= nil,
currentID = 0,
powerMetaSpriteId = FindMetaSpriteId("powerbuttonon")
}
pixelVisionOS:ResetUndoHistory(_sfxTool)
-- Create a global reference of the new workspace tool
setmetatable(_sfxTool, SFXTool)
if(_sfxTool.rootDirectory ~= nil) then
_sfxTool.targetFilePath = NewWorkspacePath(_sfxTool.targetFile)
-- Load only the game data we really need
_sfxTool.success = gameEditor.Load(_sfxTool.rootDirectory, {SaveFlags.System, SaveFlags.Sounds})
end
if(_sfxTool.success == true) then
local pathSplit = string.split(_sfxTool.rootDirectory, "/")
-- Update title with file path
_sfxTool.toolTitle = pathSplit[#pathSplit] .. "/sounds.json"
_sfxTool:CreateDropDownMenu()
_sfxTool:CreateInstrumentPanel()
_sfxTool:CreateSoundPanel()
_sfxTool:CreateWaveformPanel()
_sfxTool:CreateEditPanel()
if(SessionID() == ReadSaveData("sessionID", "") and _sfxTool.rootDirectory == ReadSaveData("rootDirectory", "")) then
_sfxTool.currentID = tonumber(ReadSaveData("currentID", "0"))
end
editorUI:ChangeNumberStepperValue(_sfxTool.channelIDStepper, 0)
_sfxTool:LoadSound(_sfxTool.currentID, true, false)
_sfxTool:ResetDataValidation()
else
pixelVisionOS:LoadError(_sfxTool.toolName)
end
-- Return the new instance of the editor ui
return _sfxTool
end
function SFXTool:InvalidateData()
-- Only everything if it needs to be
if(self.invalid == true)then
return
end
pixelVisionOS:ChangeTitle(self.toolTitle .."*", "toolbariconfile")
pixelVisionOS:EnableMenuItem(self.SaveShortcut, true)
self.invalid = true
end
function SFXTool:ResetDataValidation()
-- Only everything if it needs to be
if(self.invalid == false)then
return
end
pixelVisionOS:ChangeTitle(self.toolTitle, "toolbariconfile")
self.invalid = false
pixelVisionOS:EnableMenuItem(self.SaveShortcut, false)
end
function SFXTool:Refresh()
for i = 1, self.totalKnobs do
local knob = self.knobData[i]
local value = self.soundData[knob.propID] ~= "" and tonumber(self.soundData[knob.propID]) or 0
local percent = ((knob.range - 1) + value) / knob.range
self:UpdateKnobTooltip(knob, percent)
editorUI:ChangeKnob(knob.knobUI, percent, false)
end
self:UpdateSoundTemplates()
self:UpdateWaveButtons()
self:UpdatePlayButton()
end
function SFXTool:Draw()
-- TODO this is not working
if(gameEditor:IsChannelPlaying(0)) then
DrawMetaSprite(self.powerMetaSpriteId, 16, 88)
end
end
function SFXTool:Shutdown()
-- Make sure all sounds are stopped before shutting down
self:OnStopSound()
-- Save the current session ID
WriteSaveData("sessionID", SessionID())
WriteSaveData("rootDirectory", self.rootDirectory)
-- Make sure we don't save paths in the tmp directory
WriteSaveData("currentID", self.currentID)
end