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