2020-10-29 13:07:56 +08:00
|
|
|
class CustomSongs{
|
2021-05-28 01:23:19 +08:00
|
|
|
constructor(touchEnabled, noPage){
|
|
|
|
this.loaderDiv = document.createElement("div")
|
|
|
|
this.loaderDiv.innerHTML = assets.pages["loadsong"]
|
|
|
|
var loadingText = this.loaderDiv.querySelector("#loading-text")
|
|
|
|
this.setAltText(loadingText, strings.loading)
|
|
|
|
|
|
|
|
this.locked = false
|
|
|
|
this.mode = "main"
|
|
|
|
|
|
|
|
if(noPage){
|
|
|
|
this.noPage = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-10-29 13:07:56 +08:00
|
|
|
this.touchEnabled = touchEnabled
|
|
|
|
loader.changePage("customsongs", true)
|
|
|
|
if(touchEnabled){
|
|
|
|
this.getElement("view-outer").classList.add("touch-enabled")
|
|
|
|
}
|
|
|
|
|
|
|
|
var tutorialTitle = this.getElement("view-title")
|
|
|
|
this.setAltText(tutorialTitle, strings.customSongs.title)
|
|
|
|
|
|
|
|
var tutorialContent = this.getElement("view-content")
|
|
|
|
strings.customSongs.description.forEach(string => {
|
|
|
|
tutorialContent.appendChild(document.createTextNode(string))
|
|
|
|
tutorialContent.appendChild(document.createElement("br"))
|
|
|
|
})
|
|
|
|
|
|
|
|
this.items = []
|
|
|
|
this.linkLocalFolder = document.getElementById("link-localfolder")
|
2021-05-28 01:23:19 +08:00
|
|
|
this.hasLocal = (typeof showDirectoryPicker === "function" || "webkitdirectory" in HTMLInputElement.prototype) && !(/Android|iPhone|iPad/.test(navigator.userAgent))
|
2020-12-04 18:52:35 +08:00
|
|
|
this.selected = -1
|
|
|
|
|
2020-10-29 13:07:56 +08:00
|
|
|
if(this.hasLocal){
|
|
|
|
this.browse = document.getElementById("browse")
|
|
|
|
pageEvents.add(this.browse, "change", this.browseChange.bind(this))
|
|
|
|
this.setAltText(this.linkLocalFolder, strings.customSongs.localFolder)
|
|
|
|
pageEvents.add(this.linkLocalFolder, ["mousedown", "touchstart"], this.localFolder.bind(this))
|
|
|
|
this.items.push(this.linkLocalFolder)
|
2020-12-04 18:52:35 +08:00
|
|
|
if(this.selected === -1){
|
|
|
|
this.linkLocalFolder.classList.add("selected")
|
|
|
|
this.selected = this.items.length - 1
|
|
|
|
}
|
2020-10-29 13:07:56 +08:00
|
|
|
}else{
|
|
|
|
this.linkLocalFolder.parentNode.removeChild(this.linkLocalFolder)
|
|
|
|
}
|
|
|
|
|
2020-12-21 21:02:56 +08:00
|
|
|
var groupGdrive = document.getElementById("group-gdrive")
|
2020-10-29 13:07:56 +08:00
|
|
|
this.linkGdriveFolder = document.getElementById("link-gdrivefolder")
|
2020-12-21 21:02:56 +08:00
|
|
|
this.linkGdriveAccount = document.getElementById("link-gdriveaccount")
|
|
|
|
this.linkPrivacy = document.getElementById("link-privacy")
|
2020-10-29 13:07:56 +08:00
|
|
|
if(gameConfig.google_credentials.gdrive_enabled){
|
|
|
|
this.setAltText(this.linkGdriveFolder, strings.customSongs.gdriveFolder)
|
|
|
|
pageEvents.add(this.linkGdriveFolder, ["mousedown", "touchstart"], this.gdriveFolder.bind(this))
|
|
|
|
this.items.push(this.linkGdriveFolder)
|
2020-12-04 18:52:35 +08:00
|
|
|
if(this.selected === -1){
|
|
|
|
this.linkGdriveFolder.classList.add("selected")
|
|
|
|
this.selected = this.items.length - 1
|
|
|
|
}
|
2020-12-21 21:02:56 +08:00
|
|
|
this.setAltText(this.linkGdriveAccount, strings.customSongs.gdriveAccount)
|
|
|
|
pageEvents.add(this.linkGdriveAccount, ["mousedown", "touchstart"], this.gdriveAccount.bind(this))
|
|
|
|
this.items.push(this.linkGdriveAccount)
|
|
|
|
this.setAltText(this.linkPrivacy, strings.account.privacy)
|
|
|
|
pageEvents.add(this.linkPrivacy, ["mousedown", "touchstart"], this.openPrivacy.bind(this))
|
|
|
|
this.items.push(this.linkPrivacy)
|
2020-10-29 13:07:56 +08:00
|
|
|
}else{
|
2020-12-21 21:02:56 +08:00
|
|
|
groupGdrive.style.display = "none"
|
2020-12-23 01:05:56 +08:00
|
|
|
this.linkPrivacy.parentNode.removeChild(this.linkPrivacy)
|
2020-10-29 13:07:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this.endButton = this.getElement("view-end-button")
|
|
|
|
this.setAltText(this.endButton, strings.session.cancel)
|
2020-11-04 08:12:46 +08:00
|
|
|
pageEvents.add(this.endButton, ["mousedown", "touchstart"], event => this.onEnd(event, true))
|
2020-10-29 13:07:56 +08:00
|
|
|
this.items.push(this.endButton)
|
2020-12-04 18:52:35 +08:00
|
|
|
if(this.selected === -1){
|
|
|
|
this.endButton.classList.add("selected")
|
|
|
|
this.selected = this.items.length - 1
|
|
|
|
}
|
2020-10-29 13:07:56 +08:00
|
|
|
|
2021-05-28 01:23:19 +08:00
|
|
|
if(DataTransferItem.prototype.getAsFileSystemHandle || DataTransferItem.prototype.webkitGetAsEntry){
|
2020-11-04 08:12:46 +08:00
|
|
|
this.dropzone = document.getElementById("dropzone")
|
|
|
|
var dropContent = this.dropzone.getElementsByClassName("view-content")[0]
|
|
|
|
dropContent.innerText = strings.customSongs.dropzone
|
|
|
|
this.dragging = false
|
|
|
|
pageEvents.add(document, "dragover", event => {
|
|
|
|
event.preventDefault()
|
|
|
|
if(!this.locked){
|
|
|
|
event.dataTransfer.dropEffect = "copy"
|
|
|
|
this.dropzone.classList.add("dragover")
|
|
|
|
this.dragging = true
|
|
|
|
}else{
|
|
|
|
event.dataTransfer.dropEffect = "none"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
pageEvents.add(document, "dragleave", () => {
|
|
|
|
this.dropzone.classList.remove("dragover")
|
|
|
|
this.dragging = false
|
|
|
|
})
|
|
|
|
pageEvents.add(document, "drop", this.filesDropped.bind(this))
|
|
|
|
}
|
|
|
|
|
|
|
|
this.errorDiv = document.getElementById("customsongs-error")
|
|
|
|
pageEvents.add(this.errorDiv, ["mousedown", "touchstart"], event => {
|
|
|
|
if(event.target === event.currentTarget){
|
|
|
|
this.hideError()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
var errorTitle = this.errorDiv.getElementsByClassName("view-title")[0]
|
|
|
|
this.setAltText(errorTitle, strings.customSongs.importError)
|
|
|
|
this.errorContent = this.errorDiv.getElementsByClassName("view-content")[0]
|
|
|
|
this.errorEnd = this.errorDiv.getElementsByClassName("view-end-button")[0]
|
|
|
|
this.setAltText(this.errorEnd, strings.tutorial.ok)
|
|
|
|
pageEvents.add(this.errorEnd, ["mousedown", "touchstart"], () => this.hideError(true))
|
2020-10-29 13:07:56 +08:00
|
|
|
|
|
|
|
this.keyboard = new Keyboard({
|
|
|
|
confirm: ["enter", "space", "don_l", "don_r"],
|
|
|
|
previous: ["left", "up", "ka_l"],
|
|
|
|
next: ["right", "down", "ka_r"],
|
2020-11-04 08:12:46 +08:00
|
|
|
backEsc: ["escape"]
|
2020-10-29 13:07:56 +08:00
|
|
|
}, this.keyPressed.bind(this))
|
|
|
|
this.gamepad = new Gamepad({
|
|
|
|
confirmPad: ["b", "ls", "rs"],
|
|
|
|
previous: ["u", "l", "lb", "lt", "lsu", "lsl"],
|
|
|
|
next: ["d", "r", "rb", "rt", "lsd", "lsr"],
|
|
|
|
back: ["start", "a"]
|
|
|
|
}, this.keyPressed.bind(this))
|
|
|
|
|
|
|
|
pageEvents.send("custom-songs")
|
|
|
|
}
|
|
|
|
getElement(name){
|
|
|
|
return loader.screen.getElementsByClassName(name)[0]
|
|
|
|
}
|
|
|
|
setAltText(element, text){
|
|
|
|
element.innerText = text
|
|
|
|
element.setAttribute("alt", text)
|
|
|
|
}
|
2020-11-04 08:16:45 +08:00
|
|
|
localFolder(event){
|
2020-11-04 08:12:46 +08:00
|
|
|
if(event){
|
|
|
|
if(event.type === "touchstart"){
|
|
|
|
event.preventDefault()
|
|
|
|
}else if(event.which !== 1){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(this.locked || this.mode !== "main"){
|
2020-10-29 13:07:56 +08:00
|
|
|
return
|
|
|
|
}
|
2020-11-04 08:12:46 +08:00
|
|
|
this.changeSelected(this.linkLocalFolder)
|
2021-05-28 01:23:19 +08:00
|
|
|
if(typeof showDirectoryPicker === "function"){
|
|
|
|
return showDirectoryPicker().then(file => {
|
|
|
|
this.walkFilesystem(file).then(files => this.importLocal(files)).then(e => {
|
2021-05-30 12:13:36 +08:00
|
|
|
db.setItem("customFolder", [file])
|
2021-05-28 01:23:19 +08:00
|
|
|
}).catch(e => {
|
|
|
|
if(e !== "cancel"){
|
|
|
|
return Promise.reject(e)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}, () => {})
|
|
|
|
}else{
|
|
|
|
this.browse.click()
|
|
|
|
}
|
2020-10-29 13:07:56 +08:00
|
|
|
}
|
|
|
|
browseChange(event){
|
|
|
|
var files = []
|
|
|
|
for(var i = 0; i < event.target.files.length; i++){
|
|
|
|
files.push(new LocalFile(event.target.files[i]))
|
|
|
|
}
|
2020-11-04 08:12:46 +08:00
|
|
|
this.importLocal(files)
|
|
|
|
}
|
2021-05-30 12:13:36 +08:00
|
|
|
walkFilesystem(file, path="", output=[]){
|
|
|
|
if(file.kind === "directory"){
|
|
|
|
return filePermission(file).then(file => {
|
|
|
|
var values = file.values()
|
|
|
|
var walkValues = () => values.next().then(generator => {
|
|
|
|
if(generator.done){
|
|
|
|
return output
|
|
|
|
}
|
|
|
|
return this.walkFilesystem(generator.value, path + file.name + "/", output).then(() => walkValues())
|
|
|
|
})
|
|
|
|
return walkValues()
|
|
|
|
}, () => Promise.resolve())
|
|
|
|
}else{
|
|
|
|
output.push(new FilesystemFile(file, path + file.name))
|
|
|
|
return Promise.resolve(output)
|
|
|
|
}
|
2021-05-28 01:23:19 +08:00
|
|
|
}
|
2020-11-04 08:12:46 +08:00
|
|
|
filesDropped(event){
|
|
|
|
event.preventDefault()
|
|
|
|
this.dropzone.classList.remove("dragover")
|
|
|
|
this.dragging = false
|
|
|
|
if(this.locked){
|
|
|
|
return
|
|
|
|
}
|
2021-05-28 01:23:19 +08:00
|
|
|
var allFiles = []
|
2020-11-04 08:12:46 +08:00
|
|
|
var dropPromises = []
|
2021-05-30 12:13:36 +08:00
|
|
|
var dbItems = []
|
|
|
|
for(var i = 0; i < event.dataTransfer.items.length; i++){
|
2021-05-28 01:23:19 +08:00
|
|
|
var item = event.dataTransfer.items[i]
|
|
|
|
let promise
|
|
|
|
if(item.getAsFileSystemHandle){
|
|
|
|
promise = item.getAsFileSystemHandle().then(file => {
|
2021-05-30 12:13:36 +08:00
|
|
|
dbItems.push(file)
|
|
|
|
return this.walkFilesystem(file)
|
2021-05-28 01:23:19 +08:00
|
|
|
})
|
|
|
|
}else{
|
|
|
|
var entry = item.webkitGetAsEntry()
|
|
|
|
if(entry){
|
|
|
|
promise = this.walkEntry(entry)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(promise){
|
|
|
|
dropPromises.push(promise.then(files => {
|
|
|
|
allFiles = allFiles.concat(files)
|
|
|
|
}))
|
2020-11-04 08:12:46 +08:00
|
|
|
}
|
|
|
|
}
|
2021-05-30 12:13:36 +08:00
|
|
|
Promise.all(dropPromises).then(() => this.importLocal(allFiles)).then(() => {
|
|
|
|
if(dbItems.length){
|
|
|
|
db.setItem("customFolder", dbItems)
|
|
|
|
}
|
|
|
|
})
|
2021-05-28 01:23:19 +08:00
|
|
|
}
|
|
|
|
walkEntry(entry, path="", output=[]){
|
|
|
|
return new Promise(resolve => {
|
|
|
|
if(entry.isFile){
|
|
|
|
entry.file(file => {
|
|
|
|
output.push(new LocalFile(file, path + file.name))
|
|
|
|
return resolve()
|
|
|
|
}, resolve)
|
|
|
|
}else if(entry.isDirectory){
|
|
|
|
var dirReader = entry.createReader()
|
|
|
|
dirReader.readEntries(entries => {
|
|
|
|
var dirPromises = []
|
|
|
|
for(var i = 0; i < entries.length; i++){
|
|
|
|
dirPromises.push(this.walkEntry(entries[i], path + entry.name + "/", output))
|
|
|
|
}
|
|
|
|
return Promise.all(dirPromises).then(resolve)
|
|
|
|
}, resolve)
|
|
|
|
}else{
|
|
|
|
return resolve()
|
|
|
|
}
|
|
|
|
}).then(() => output)
|
2020-11-04 08:12:46 +08:00
|
|
|
}
|
|
|
|
importLocal(files){
|
2020-10-29 13:07:56 +08:00
|
|
|
if(!files.length){
|
2021-05-28 01:23:19 +08:00
|
|
|
return Promise.resolve("cancel")
|
2020-10-29 13:07:56 +08:00
|
|
|
}
|
|
|
|
this.locked = true
|
|
|
|
this.loading(true)
|
|
|
|
|
|
|
|
var importSongs = new ImportSongs()
|
2021-05-28 01:23:19 +08:00
|
|
|
return importSongs.load(files).then(this.songsLoaded.bind(this), e => {
|
2020-10-29 13:07:56 +08:00
|
|
|
this.browse.parentNode.reset()
|
|
|
|
this.locked = false
|
|
|
|
this.loading(false)
|
2020-11-04 08:12:46 +08:00
|
|
|
if(e === "nosongs"){
|
|
|
|
this.showError(strings.customSongs.noSongs)
|
|
|
|
}else if(e !== "cancel"){
|
2020-10-29 13:07:56 +08:00
|
|
|
return Promise.reject(e)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-11-04 08:12:46 +08:00
|
|
|
gdriveFolder(event){
|
|
|
|
if(event){
|
|
|
|
if(event.type === "touchstart"){
|
|
|
|
event.preventDefault()
|
|
|
|
}else if(event.which !== 1){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(this.locked || this.mode !== "main"){
|
2020-10-29 13:07:56 +08:00
|
|
|
return
|
|
|
|
}
|
2020-11-04 08:12:46 +08:00
|
|
|
this.changeSelected(this.linkGdriveFolder)
|
2020-10-29 13:07:56 +08:00
|
|
|
this.locked = true
|
|
|
|
this.loading(true)
|
|
|
|
var importSongs = new ImportSongs(true)
|
|
|
|
if(!gpicker){
|
|
|
|
var gpickerPromise = loader.loadScript("/src/js/gpicker.js").then(() => {
|
|
|
|
gpicker = new Gpicker()
|
|
|
|
})
|
|
|
|
}else{
|
|
|
|
var gpickerPromise = Promise.resolve()
|
|
|
|
}
|
|
|
|
gpickerPromise.then(() => {
|
|
|
|
return gpicker.browse(locked => {
|
|
|
|
this.locked = locked
|
|
|
|
this.loading(locked)
|
2020-11-04 08:12:46 +08:00
|
|
|
}, error => {
|
|
|
|
this.showError(error)
|
2020-10-29 13:07:56 +08:00
|
|
|
})
|
|
|
|
}).then(files => importSongs.load(files))
|
|
|
|
.then(this.songsLoaded.bind(this))
|
|
|
|
.catch(e => {
|
|
|
|
this.locked = false
|
|
|
|
this.loading(false)
|
2020-11-04 08:12:46 +08:00
|
|
|
if(e === "nosongs"){
|
|
|
|
this.showError(strings.customSongs.noSongs)
|
|
|
|
}else if(e !== "cancel"){
|
2020-10-29 13:07:56 +08:00
|
|
|
return Promise.reject(e)
|
|
|
|
}
|
2020-12-21 21:02:56 +08:00
|
|
|
}).finally(() => {
|
|
|
|
var addRemove = !gpicker || !gpicker.oauthToken ? "add" : "remove"
|
|
|
|
this.linkGdriveAccount.classList[addRemove]("hiddenbtn")
|
2020-10-29 13:07:56 +08:00
|
|
|
})
|
|
|
|
}
|
2020-12-21 21:02:56 +08:00
|
|
|
gdriveAccount(event){
|
|
|
|
if(event){
|
|
|
|
if(event.type === "touchstart"){
|
|
|
|
event.preventDefault()
|
|
|
|
}else if(event.which !== 1){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(this.locked || this.mode !== "main"){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.changeSelected(this.linkGdriveAccount)
|
|
|
|
this.locked = true
|
|
|
|
this.loading(true)
|
|
|
|
if(!gpicker){
|
|
|
|
var gpickerPromise = loader.loadScript("/src/js/gpicker.js").then(() => {
|
|
|
|
gpicker = new Gpicker()
|
|
|
|
})
|
|
|
|
}else{
|
|
|
|
var gpickerPromise = Promise.resolve()
|
|
|
|
}
|
|
|
|
gpickerPromise.then(() => {
|
|
|
|
return gpicker.switchAccounts(locked => {
|
|
|
|
this.locked = locked
|
|
|
|
this.loading(locked)
|
|
|
|
}, error => {
|
|
|
|
this.showError(error)
|
|
|
|
})
|
|
|
|
}).then(() => {
|
|
|
|
this.locked = false
|
|
|
|
this.loading(false)
|
|
|
|
}).catch(error => {
|
|
|
|
if(error !== "cancel"){
|
|
|
|
this.showError(error)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
openPrivacy(event){
|
|
|
|
if(event){
|
|
|
|
if(event.type === "touchstart"){
|
|
|
|
event.preventDefault()
|
|
|
|
}else if(event.which !== 1){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(this.locked || this.mode !== "main"){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.changeSelected(this.linkPrivacy)
|
|
|
|
open("privacy")
|
|
|
|
}
|
2020-10-29 13:07:56 +08:00
|
|
|
loading(show){
|
2021-05-28 09:55:53 +08:00
|
|
|
if(this.noPage){
|
|
|
|
return
|
|
|
|
}
|
2020-10-29 13:07:56 +08:00
|
|
|
if(show){
|
|
|
|
loader.screen.appendChild(this.loaderDiv)
|
2020-12-21 21:02:56 +08:00
|
|
|
}else if(this.loaderDiv.parentNode){
|
|
|
|
this.loaderDiv.parentNode.removeChild(this.loaderDiv)
|
2020-10-29 13:07:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
songsLoaded(songs){
|
2020-10-31 19:47:42 +08:00
|
|
|
if(songs){
|
|
|
|
var length = songs.length
|
|
|
|
assets.songs = songs
|
|
|
|
assets.customSongs = true
|
2021-05-28 01:23:19 +08:00
|
|
|
assets.customSelected = this.noPage ? +localStorage.getItem("customSelected") : 0
|
2020-10-31 19:47:42 +08:00
|
|
|
}
|
2021-05-28 09:55:53 +08:00
|
|
|
if(!this.noPage){
|
|
|
|
assets.sounds["se_don"].play()
|
|
|
|
}
|
2020-10-29 13:07:56 +08:00
|
|
|
this.clean()
|
|
|
|
setTimeout(() => {
|
|
|
|
new SongSelect("customSongs", false, this.touchEnabled)
|
|
|
|
pageEvents.send("import-songs", length)
|
|
|
|
}, 500)
|
|
|
|
}
|
|
|
|
keyPressed(pressed, name){
|
|
|
|
if(!pressed || this.locked){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var selected = this.items[this.selected]
|
2020-11-04 08:12:46 +08:00
|
|
|
if(this.mode === "main"){
|
|
|
|
if(name === "confirm" || name === "confirmPad"){
|
|
|
|
if(selected === this.endButton){
|
|
|
|
this.onEnd(null, true)
|
|
|
|
}else if(name !== "confirmPad"){
|
|
|
|
if(selected === this.linkLocalFolder){
|
|
|
|
assets.sounds["se_don"].play()
|
|
|
|
this.localFolder()
|
|
|
|
}else if(selected === this.linkGdriveFolder){
|
|
|
|
assets.sounds["se_don"].play()
|
|
|
|
this.gdriveFolder()
|
2020-12-21 21:02:56 +08:00
|
|
|
}else if(selected === this.linkGdriveAccount){
|
|
|
|
assets.sounds["se_don"].play()
|
|
|
|
this.gdriveAccount()
|
|
|
|
}else if(selected === this.linkPrivacy){
|
|
|
|
assets.sounds["se_don"].play()
|
|
|
|
this.openPrivacy()
|
2020-11-04 08:12:46 +08:00
|
|
|
}
|
2020-10-29 13:07:56 +08:00
|
|
|
}
|
2020-11-04 08:12:46 +08:00
|
|
|
}else if(name === "previous" || name === "next"){
|
|
|
|
selected.classList.remove("selected")
|
2020-12-23 01:05:56 +08:00
|
|
|
do{
|
|
|
|
this.selected = this.mod(this.items.length, this.selected + (name === "next" ? 1 : -1))
|
|
|
|
}while(this.items[this.selected] === this.linkPrivacy && name !== "previous")
|
2020-11-04 08:12:46 +08:00
|
|
|
this.items[this.selected].classList.add("selected")
|
|
|
|
assets.sounds["se_ka"].play()
|
|
|
|
}else if(name === "back" || name === "backEsc"){
|
|
|
|
if(!this.dragging || name !== "backEsc"){
|
|
|
|
this.onEnd()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else if(this.mode === "error"){
|
|
|
|
if(name === "confirm" || name === "confirmPad" || name === "back" || name === "backEsc"){
|
|
|
|
this.hideError(name === "confirm" || name === "confirmPad")
|
2020-10-29 13:07:56 +08:00
|
|
|
}
|
2020-11-04 08:12:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
changeSelected(button){
|
|
|
|
var selected = this.items[this.selected]
|
|
|
|
if(selected !== button){
|
2020-10-29 13:07:56 +08:00
|
|
|
selected.classList.remove("selected")
|
2020-11-04 08:12:46 +08:00
|
|
|
this.selected = this.items.findIndex(item => item === button)
|
2020-10-29 13:07:56 +08:00
|
|
|
this.items[this.selected].classList.add("selected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mod(length, index){
|
|
|
|
return ((index % length) + length) % length
|
|
|
|
}
|
2020-11-04 08:12:46 +08:00
|
|
|
onEnd(event, confirm){
|
|
|
|
if(this.locked || this.mode !== "main"){
|
2020-10-29 13:07:56 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
var touched = false
|
|
|
|
if(event){
|
|
|
|
if(event.type === "touchstart"){
|
|
|
|
event.preventDefault()
|
|
|
|
touched = true
|
|
|
|
}else if(event.which !== 1){
|
|
|
|
return
|
|
|
|
}
|
2020-11-04 08:12:46 +08:00
|
|
|
}else{
|
|
|
|
touched = this.touchEnabled
|
2020-10-29 13:07:56 +08:00
|
|
|
}
|
|
|
|
this.clean()
|
2021-05-28 01:23:19 +08:00
|
|
|
if(!this.noPage){
|
|
|
|
assets.sounds[confirm ? "se_don" : "se_cancel"].play()
|
|
|
|
}
|
|
|
|
return new Promise(resolve => setTimeout(() => {
|
2020-10-29 13:07:56 +08:00
|
|
|
new SongSelect("customSongs", false, touched)
|
2021-05-28 01:23:19 +08:00
|
|
|
resolve()
|
|
|
|
}, 500))
|
2020-10-29 13:07:56 +08:00
|
|
|
}
|
2020-11-04 08:12:46 +08:00
|
|
|
showError(text){
|
2020-12-21 21:02:56 +08:00
|
|
|
this.locked = false
|
|
|
|
this.loading(false)
|
2021-05-28 01:23:19 +08:00
|
|
|
if(this.noPage || this.mode === "error"){
|
2020-11-04 08:12:46 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
this.mode = "error"
|
|
|
|
this.errorContent.innerText = text
|
|
|
|
this.errorDiv.style.display = "flex"
|
|
|
|
assets.sounds["se_pause"].play()
|
|
|
|
}
|
|
|
|
hideError(confirm){
|
|
|
|
if(this.mode !== "error"){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.mode = "main"
|
|
|
|
this.errorDiv.style.display = ""
|
|
|
|
assets.sounds[confirm ? "se_don" : "se_cancel"].play()
|
|
|
|
}
|
2020-10-29 13:07:56 +08:00
|
|
|
clean(){
|
2021-05-28 01:23:19 +08:00
|
|
|
delete this.loaderDiv
|
|
|
|
if(this.noPage){
|
|
|
|
return
|
|
|
|
}
|
2020-10-29 13:07:56 +08:00
|
|
|
this.keyboard.clean()
|
|
|
|
this.gamepad.clean()
|
|
|
|
pageEvents.remove(this.browse, "change")
|
|
|
|
if(this.hasLocal){
|
|
|
|
pageEvents.remove(this.linkLocalFolder, ["mousedown", "touchstart"])
|
|
|
|
}
|
|
|
|
if(gameConfig.google_credentials.gdrive_enabled){
|
|
|
|
pageEvents.remove(this.linkGdriveFolder, ["mousedown", "touchstart"])
|
2020-12-21 21:02:56 +08:00
|
|
|
pageEvents.remove(this.linkGdriveAccount, ["mousedown", "touchstart"])
|
|
|
|
pageEvents.remove(this.linkPrivacy, ["mousedown", "touchstart"])
|
2020-10-29 13:07:56 +08:00
|
|
|
}
|
|
|
|
pageEvents.remove(this.endButton, ["mousedown", "touchstart"])
|
2020-11-04 08:12:46 +08:00
|
|
|
pageEvents.remove(this.errorDiv, ["mousedown", "touchstart"])
|
|
|
|
pageEvents.remove(this.errorEnd, ["mousedown", "touchstart"])
|
|
|
|
if(DataTransferItem.prototype.webkitGetAsEntry){
|
|
|
|
pageEvents.remove(document, ["dragover", "dragleave", "drop"])
|
|
|
|
delete this.dropzone
|
|
|
|
}
|
2020-10-29 13:07:56 +08:00
|
|
|
delete this.browse
|
|
|
|
delete this.linkLocalFolder
|
|
|
|
delete this.linkGdriveFolder
|
2020-12-21 21:02:56 +08:00
|
|
|
delete this.linkGdriveAccount
|
|
|
|
delete this.linkPrivacy
|
2020-10-29 13:07:56 +08:00
|
|
|
delete this.endButton
|
|
|
|
delete this.items
|
2020-11-04 08:12:46 +08:00
|
|
|
delete this.errorDiv
|
|
|
|
delete this.errorContent
|
|
|
|
delete this.errorEnd
|
2020-10-29 13:07:56 +08:00
|
|
|
}
|
|
|
|
}
|