-
Notifications
You must be signed in to change notification settings - Fork 0
/
vt2pico8.lua
51 lines (43 loc) · 1.46 KB
/
vt2pico8.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
local inspect = require("inspect")
local parser = require("parser")
local converter = require("converter")
local logger = require("logger")
local writer = require("writer")
local vt2name = arg[1]
local p8name = arg[2]
local append = arg[3]
print("\nVortex Tracker 2 to PICO-8 music converter v1.0 by Roman \"Megus\" Petrov\n")
if vt2name == nil or p8name == nil then
print("Usage: lua vt2pico8.lua vt2file p8file [-append]")
return
end
local modules = parser.load(vt2name)
if modules == nil then
print("Can't open " .. vt2name .. "\n")
return
end
-- TODO: Check, if it was really loaded
print("Converting " .. vt2name .. "...")
local patterns, order = converter.convert(modules)
local errorLog = logger.errorLog()
local warningLog = logger.warningLog()
if warningLog ~= "" then
print("\nWarnings:\n\n" .. warningLog .. "\nThese warnings are just for your information, you don't have to change anything in the module\n")
end
if errorLog ~= "" then
print("\nFatal errors:\n\n" .. errorLog .. "\nFix these errors and try to convert again, P8 file is not saved\n")
end
-- Try to read existing P8 file
if errorLog == "" then
local successString = "Saved " .. p8name
local oldP8 = parser.readFile(p8name)
if oldP8 ~= nil then
successString = "Updated " .. p8name
end
local newP8 = writer.writeP8(oldP8, patterns, order, append == "-append")
local file = io.open(p8name, "w")
file:write(newP8)
io.close(file)
--print(newP8)
print(successString .. "\n")
end