|
| 1 | +-- Dark Energy Processor Live Simulator beatmap project loader |
| 2 | +-- Part of Live Simulator: 2 |
| 3 | +-- See copyright notice in main.lua |
| 4 | + |
| 5 | +local AquaShine, NoteLoader = ... |
| 6 | +local love = love |
| 7 | +local LuaStoryboard = require("luastoryboard2") |
| 8 | +local DEPLSLoader = {ProjectLoader = true} |
| 9 | +local DEPLSBeatmap = {} |
| 10 | +DEPLSBeatmap.__index = NoteLoader.NoteLoaderNoteObject._derive(DEPLSBeatmap) |
| 11 | + |
| 12 | +------------------ |
| 13 | +-- DEPLS Loader -- |
| 14 | +------------------ |
| 15 | + |
| 16 | +function DEPLSLoader.GetLoaderName() |
| 17 | + return "DEPLS Beatmap Project" |
| 18 | +end |
| 19 | + |
| 20 | +function DEPLSLoader.LoadNoteFromFilename(file) |
| 21 | + local this = {} |
| 22 | + this.project_dir = file |
| 23 | + |
| 24 | + -- At least one DEPLS beatmap project must have "beatmap.*" |
| 25 | + -- file which is supported by NoteLoader2 |
| 26 | + for _, v in ipairs(love.filesystem.getDirectoryItems(file)) do |
| 27 | + if v:find("^beatmap%.[^%.]+$") == 1 then |
| 28 | + -- Looks like we have one here. Try to load it |
| 29 | + -- NoteLoader will return nil if it's not supported |
| 30 | + this.note_object = NoteLoader.NoteLoader(file.."/"..v) |
| 31 | + end |
| 32 | + |
| 33 | + if this.note_object then break end |
| 34 | + end |
| 35 | + |
| 36 | + assert(this.note_object, "No beatmap file found") |
| 37 | + return setmetatable(this, DEPLSBeatmap) |
| 38 | +end |
| 39 | + |
| 40 | +-------------------------- |
| 41 | +-- DEPLS Beatmap Object -- |
| 42 | +-------------------------- |
| 43 | + |
| 44 | +function DEPLSBeatmap.GetNotesList(this) |
| 45 | + return this.note_object:GetNotesList() |
| 46 | +end |
| 47 | + |
| 48 | +function DEPLSBeatmap.GetName(this) |
| 49 | + if not(this.name) then |
| 50 | + this.name = this.note_object:GetName() |
| 51 | + |
| 52 | + -- If it's named "beatmap", then it should take it from |
| 53 | + -- NoteLoader argument. In that case, don't use that name |
| 54 | + if this.name == "beatmap" then |
| 55 | + local cover_info = this:GetCoverArt() |
| 56 | + |
| 57 | + if cover_info and cover_info.title then |
| 58 | + this.name = cover_info.title |
| 59 | + else |
| 60 | + this.name = NoteLoader._GetBasenameWOExt(this.project_dir) |
| 61 | + end |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + return this.name |
| 66 | +end |
| 67 | + |
| 68 | +function DEPLSBeatmap.GetBeatmapTypename(this) |
| 69 | + if not(this.typename) then |
| 70 | + this.typename = "DEPLS Project: "..this.note_object:GetBeatmapTypename() |
| 71 | + end |
| 72 | + |
| 73 | + return this.typename |
| 74 | +end |
| 75 | + |
| 76 | +function DEPLSBeatmap.GetCoverArt(this) |
| 77 | + if not(this.cover_loaded) then |
| 78 | + local cover_info = this.project_dir.."/cover.txt" |
| 79 | + local cover_img = this.project_dir.."/cover.png" |
| 80 | + |
| 81 | + if love.filesystem.isFile(cover_info) and love.filesystem.isFile(cover_img) then |
| 82 | + local line = love.filesystem.lines(cover_info) |
| 83 | + |
| 84 | + this.cover = {} |
| 85 | + this.cover.image = love.graphics.newImage(cover_img) |
| 86 | + this.cover.title = line() |
| 87 | + this.cover.arrangement = line() |
| 88 | + else |
| 89 | + this.cover = this.note_object:GetCoverArt() |
| 90 | + end |
| 91 | + |
| 92 | + this.cover_loaded = true |
| 93 | + end |
| 94 | + |
| 95 | + return this.cover |
| 96 | +end |
| 97 | + |
| 98 | +function DEPLSBeatmap.GetCustomUnitInformation(this) |
| 99 | + if not(this.custom_unit) then |
| 100 | + local image_cache = {} |
| 101 | + this.custom_unit = {} |
| 102 | + this.note_object_custom_unit = this.note_object:GetCustomUnitInformation(this) |
| 103 | + |
| 104 | + for i = 1, 9 do |
| 105 | + local filename = this.project_dir.."/unit_pos_"..i..".txt" |
| 106 | + |
| 107 | + if love.filesystem.isFile(filename) then |
| 108 | + local image_name = love.filesystem.read(filename) |
| 109 | + |
| 110 | + if not(image_cache[image_name]) then |
| 111 | + image_cache[image_name] = love.graphics.newImage(this.project_dir.."/"..image_name) |
| 112 | + end |
| 113 | + |
| 114 | + this.custom_unit[i] = image_cache[image_name] |
| 115 | + else |
| 116 | + local image_name = "unit_pos_"..i..".png" |
| 117 | + filename = this.project_dir.."/"..image_name |
| 118 | + |
| 119 | + if not(image_cache[image_name]) and love.filesystem.isFile(filename) then |
| 120 | + image_cache[image_name] = love.graphics.newImage(filename) |
| 121 | + end |
| 122 | + |
| 123 | + this.custom_unit[i] = image_cache[image_name] |
| 124 | + end |
| 125 | + |
| 126 | + this.custom_unit[i] = this.custom_unit[i] or this.note_object_custom_unit[i] |
| 127 | + end |
| 128 | + end |
| 129 | + |
| 130 | + return this.custom_unit |
| 131 | +end |
| 132 | + |
| 133 | +function DEPLSBeatmap.GetScoreInformation(this) |
| 134 | + return this.note_object:GetScoreInformation() |
| 135 | +end |
| 136 | + |
| 137 | +function DEPLSBeatmap.GetStoryboard(this) |
| 138 | + -- 1. Get "storyboard.lua" file |
| 139 | + local storyboard_file = this.project_dir.."/storyboard.lua" |
| 140 | + |
| 141 | + if love.filesystem.isFile(storyboard_file) then |
| 142 | + return LuaStoryboard.Load(storyboard_file) |
| 143 | + end |
| 144 | + |
| 145 | + return this.note_object:GetStoryboard() |
| 146 | +end |
| 147 | + |
| 148 | +function DEPLSBeatmap.GetBackgroundID(this) |
| 149 | + local bgobj = this:GetCustomBackground() |
| 150 | + |
| 151 | + if bgobj then |
| 152 | + return -1 |
| 153 | + end |
| 154 | + |
| 155 | + local bgidname = this.project_dir.."/background.txt" |
| 156 | + if not(this.bgid_loaded) and love.filesystem.isFile(bgidname) then |
| 157 | + this.bgid = tonumber(love.filesystem.read(bgidname)) |
| 158 | + this.bgid_loaded = true |
| 159 | + end |
| 160 | + |
| 161 | + return this.bgid or 0 |
| 162 | +end |
| 163 | + |
| 164 | +local supported_img_fmts = {".png", ".jpg", ".bmp"} |
| 165 | +function DEPLSBeatmap.GetCustomBackground(this) |
| 166 | + if not(this.bg_loaded) then |
| 167 | + for _, ext in ipairs(supported_img_fmts) do |
| 168 | + local bgname = this.project_dir.."/background"..ext |
| 169 | + |
| 170 | + if love.filesystem.isFile(bgname) then |
| 171 | + this.background = {} |
| 172 | + this.background[0] = love.graphics.newImage(bgname) |
| 173 | + |
| 174 | + for i = 1, 4 do |
| 175 | + bgname = this.project_dir.."/background-"..i..ext |
| 176 | + |
| 177 | + if love.filesystem.isFile(bgname) then |
| 178 | + this.background[i] = love.graphics.newImage(bgname) |
| 179 | + end |
| 180 | + end |
| 181 | + |
| 182 | + if not(this.background[1] and this.background[2]) then |
| 183 | + AquaShine.Log("NoteLoader2/load_depls", "Non-balanced background (only contain left or right part). Removed") |
| 184 | + this.backgound[1], this.background[2] = nil, nil |
| 185 | + end |
| 186 | + |
| 187 | + if not(this.background[3] and this.background[4]) then |
| 188 | + AquaShine.Log("NoteLoader2/load_depls", "Non-balanced background (only contain top or bottom part). Removed") |
| 189 | + this.backgound[3], this.background[4] = nil, nil |
| 190 | + end |
| 191 | + |
| 192 | + break |
| 193 | + end |
| 194 | + end |
| 195 | + |
| 196 | + this.bg_loaded = true |
| 197 | + end |
| 198 | + |
| 199 | + return this.background |
| 200 | +end |
| 201 | + |
| 202 | +local supported_video_fmts = {".ogg", ".ogv"} |
| 203 | +if AquaShine.FFmpegExt then |
| 204 | + supported_video_fmts[#supported_video_fmts + 1] = ".mp4" |
| 205 | + supported_video_fmts[#supported_video_fmts + 1] = ".mkv" |
| 206 | + supported_video_fmts[#supported_video_fmts + 1] = ".avi" |
| 207 | + supported_video_fmts[#supported_video_fmts + 1] = ".flv" |
| 208 | +end |
| 209 | +function DEPLSBeatmap.GetVideoBackground(this) |
| 210 | + if not(this.video_loaded) then |
| 211 | + for _, v in ipairs(supported_video_fmts) do |
| 212 | + local name = this.project_folder.."/video_background"..v |
| 213 | + |
| 214 | + if love.filesystem.isFile(name) then |
| 215 | + local message |
| 216 | + this.video, message = AquaShine.LoadVideo(name) |
| 217 | + |
| 218 | + if not(this.video) then |
| 219 | + AquaShine.Log("NoteLoader2/load_depls", "Failed to load video: %s", message) |
| 220 | + end |
| 221 | + |
| 222 | + break |
| 223 | + end |
| 224 | + end |
| 225 | + |
| 226 | + this.video_loaded = true |
| 227 | + end |
| 228 | + |
| 229 | + return this.video |
| 230 | +end |
| 231 | + |
| 232 | +function DEPLSBeatmap.GetScorePerTap(this) |
| 233 | + return this.note_object:GetScorePerTap() |
| 234 | +end |
| 235 | + |
| 236 | +function DEPLSBeatmap.GetStamina(this) |
| 237 | + return this.note_object:GetStamina() |
| 238 | +end |
| 239 | + |
| 240 | +function DEPLSBeatmap.GetNotesStyle(this) |
| 241 | + return this.note_object:GetNotesStyle() |
| 242 | +end |
| 243 | + |
| 244 | +function DEPLSBeatmap.GetBeatmapAudio(this) |
| 245 | + if not(this.audio_loaded) then |
| 246 | + -- 1. Load songFile.wav/ogg/mp3 file |
| 247 | + this.audio = AquaShine.LoadAudio(this.project_dir.."/songFile.wav") |
| 248 | + |
| 249 | + if not(this.audio) then |
| 250 | + -- 2. Load embedded audio from beatmap |
| 251 | + this.audio = this.note_object:GetBeatmapAudio() |
| 252 | + |
| 253 | + if not(this.audio) then |
| 254 | + -- 3. Load from audio/ folder |
| 255 | + this.audio = AquaShine.LoadAudio("audio/"..AquaShine.Basename(this.project_dir)..".wav") |
| 256 | + end |
| 257 | + end |
| 258 | + |
| 259 | + this.audio_loaded = true |
| 260 | + end |
| 261 | + |
| 262 | + return this.audio |
| 263 | +end |
| 264 | + |
| 265 | +function DEPLSBeatmap.GetLiveClearSound(this) |
| 266 | + return AquaShine.LoadAudio(this.project_dir.."/live_clear.wav") or this.note_object:GetLiveClearSound() |
| 267 | +end |
| 268 | + |
| 269 | +function DEPLSBeatmap.GetStarDifficultyInfo(this) |
| 270 | + return this.note_object:GetStarDifficultyInfo() |
| 271 | +end |
| 272 | + |
| 273 | +function DEPLSBeatmap.ReleaseBeatmapAudio(this) |
| 274 | + this.audio_loaded, this.audio = false, nil |
| 275 | + return this.note_object:ReleaseBeatmapAudio() |
| 276 | +end |
| 277 | + |
| 278 | +return DEPLSLoader |
0 commit comments