aboutsummaryrefslogtreecommitdiffstats
path: root/Files.lua
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2014-03-13 16:14:10 +0100
committerpiernov <piernov@piernov.org>2014-03-13 16:14:10 +0100
commit9004e721dd27b2d1c330cf1ce35771ca3c91ac82 (patch)
treeb45e7ce8775e3badc84233a0079fd9628303559b /Files.lua
downloadMaiLÖVE-9004e721dd27b2d1c330cf1ce35771ca3c91ac82.tar.gz
MaiLÖVE-9004e721dd27b2d1c330cf1ce35771ca3c91ac82.tar.bz2
MaiLÖVE-9004e721dd27b2d1c330cf1ce35771ca3c91ac82.tar.xz
MaiLÖVE-9004e721dd27b2d1c330cf1ce35771ca3c91ac82.zip
Importation du projet
Diffstat (limited to 'Files.lua')
-rwxr-xr-xFiles.lua102
1 files changed, 102 insertions, 0 deletions
diff --git a/Files.lua b/Files.lua
new file mode 100755
index 0000000..8fc19fe
--- /dev/null
+++ b/Files.lua
@@ -0,0 +1,102 @@
+local Files = {}
+
+function Files.findSongs(folder, fileTree)
+ if folder == nil then folder = "" end
+ if fileTree == nil then fileTree = {} end
+ local filesTable = love.filesystem.getDirectoryItems(folder)
+ for i,v in ipairs(filesTable) do
+ local file = folder.."/"..v
+ if love.filesystem.isFile(file) and v:sub(-3) == ".sm" then
+ table.insert(fileTree, file)
+ elseif love.filesystem.isDirectory(file) then
+ fileTree = Files.findSongs(file, fileTree)
+ end
+ end
+ return fileTree
+end
+
+function Files.readNotesInfos(smInfo)
+
+ local pos = { mesure = 1, beat = 1, note = 1}
+ local state = 0
+ local numNotes = 0
+
+ for line in love.filesystem.lines(smInfo.file) do
+ line = line:gsub("//.*", "")
+
+ local info, text= line:match("^#(%u+):(.-);?%s*$")
+
+ if info == "NOTES" then
+ pos = { mesure = 1, beat = 1, note = 1}
+ state = 1
+ numNotes = numNotes + 1
+ if numNotes > 1 then
+ smInfo["notes"][numNotes] = Utils.copyTable(SMFileSchema.FileSchema["notes"][1])
+ end
+
+ elseif state > 0 and state < SMFileSchema.NotesInfos.noteData then
+
+ if state <= SMFileSchema.NotesInfos.difficultyMeter then
+ tmp = line:match("^%s*(.+):.*$")
+ elseif state == SMFileSchema.NotesInfos.radarValues then
+ tmp = {}
+ for i in line:gmatch("%d+%.%d+") do
+ table.insert(tmp,i)
+ end
+ end
+
+ if tmp then
+ smInfo["notes"][numNotes][state][2] = tmp
+ state = state + 1
+ end
+ elseif state == SMFileSchema.NotesInfos.noteData then
+ for c in line:gmatch"." do
+ if c == "," then
+ pos.beat = 1
+ pos.mesure = pos.mesure + 1
+ elseif c == ";" then
+ pos = { mesure = 1, beat = 1, note = 1}
+ elseif c:find("%w") then
+ if not smInfo["notes"][numNotes][SMFileSchema.NotesInfos.noteData][2][pos.mesure] then
+ smInfo["notes"][numNotes][SMFileSchema.NotesInfos.noteData][2][pos.mesure] = {}
+ end
+ if not smInfo["notes"][numNotes][SMFileSchema.NotesInfos.noteData][2][pos.mesure][pos.beat] then
+ smInfo["notes"][numNotes][SMFileSchema.NotesInfos.noteData][2][pos.mesure][pos.beat] = {}
+ end
+
+ table.insert(smInfo["notes"][numNotes][SMFileSchema.NotesInfos.noteData][2][pos.mesure][pos.beat], c)
+
+ if #smInfo["notes"][numNotes][SMFileSchema.NotesInfos.noteData][2][pos.mesure][pos.beat] >= SMFileSchema.NotesType[smInfo["notes"][numNotes][SMFileSchema.NotesInfos.notesType][2]] then
+ pos.beat = pos.beat + 1
+ end
+ end
+ end
+ end
+ end
+
+ return smInfo
+end
+
+function Files.getSMInfo(file)
+ local smInfo = Utils.copyTable(SMFileSchema.FileSchema)
+ smInfo.file = file
+ for line in love.filesystem.lines(smInfo.file) do
+ line = line:gsub("//.*", "")
+
+ local info, text= line:match("^#(%u+):(.-);?%s*$")
+
+ if info and info ~= "NOTES" then
+ if type(smInfo[info:lower()]) == "table" then
+ for i in text:gmatch("%d+%.%d+=%d+%.%d+") do
+ local beat, bpm = i:match("(%d+%.%d+)=(%d+%.%d+)")
+ smInfo[info:lower()][beat] = bpm
+ end
+ else
+ smInfo[info:lower()] = text
+ end
+ end
+ end
+ return smInfo
+end
+
+return Files