mirror of
https://github.com/jiojciojsioe3/a3cjroijsiojiorj.git
synced 2024-12-22 17:26:13 +08:00
add assets_baseurl config option
This commit is contained in:
parent
6d07afaa11
commit
d1ae38e9c4
33
app.py
33
app.py
@ -27,6 +27,25 @@ def query_db(query, args=(), one=False):
|
||||
return (rv[0] if rv else None) if one else rv
|
||||
|
||||
|
||||
def get_config():
|
||||
if os.path.isfile('config.json'):
|
||||
try:
|
||||
config = json.load(open('config.json', 'r'))
|
||||
except ValueError:
|
||||
print 'WARNING: Invalid config.json, using default values'
|
||||
config = {}
|
||||
else:
|
||||
print 'WARNING: No config.json found, using default values'
|
||||
config = {}
|
||||
|
||||
if not config.get('songs_baseurl'):
|
||||
config['songs_baseurl'] = ''.join([request.host_url, 'songs']) + '/'
|
||||
if not config.get('assets_baseurl'):
|
||||
config['assets_baseurl'] = ''.join([request.host_url, 'assets']) + '/'
|
||||
|
||||
return config
|
||||
|
||||
|
||||
def parse_osu(osu):
|
||||
osu_lines = open(osu, 'r').read().replace('\x00', '').split('\n')
|
||||
sections = {}
|
||||
@ -110,7 +129,7 @@ def route_index():
|
||||
version = None
|
||||
if os.path.isfile('version.json'):
|
||||
version = json.load(open('version.json', 'r'))
|
||||
return render_template('index.html', version=version)
|
||||
return render_template('index.html', version=version, config=get_config())
|
||||
|
||||
|
||||
@app.route('/api/preview')
|
||||
@ -165,17 +184,7 @@ def route_api_songs():
|
||||
|
||||
@app.route('/api/config')
|
||||
def route_api_config():
|
||||
if os.path.isfile('config.json'):
|
||||
config = json.load(open('config.json', 'r'))
|
||||
else:
|
||||
print 'WARNING: No config.json found, using default values'
|
||||
config = {
|
||||
'songs_baseurl': ''.join([request.host_url, 'songs']) + '/'
|
||||
}
|
||||
|
||||
if not config.get('songs_baseurl'):
|
||||
config['songs_baseurl'] = ''.join([request.host_url, 'songs']) + '/'
|
||||
|
||||
config = get_config()
|
||||
return jsonify(config)
|
||||
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
{
|
||||
"songs_baseurl": ""
|
||||
"songs_baseurl": "",
|
||||
"assets_baseurl": ""
|
||||
}
|
||||
|
@ -1,11 +1,3 @@
|
||||
@font-face{
|
||||
font-family: TnT;
|
||||
src: url("/assets/fonts/TnT.ttf") format("truetype");
|
||||
}
|
||||
@font-face{
|
||||
font-family: Kozuka;
|
||||
src: url("/assets/fonts/Kozuka.otf") format("truetype");
|
||||
}
|
||||
html,
|
||||
body{
|
||||
margin: 0;
|
||||
|
@ -15,7 +15,7 @@ class Loader{
|
||||
this.screen.innerHTML = page
|
||||
this.loaderPercentage = document.querySelector("#loader .percentage")
|
||||
this.loaderProgress = document.querySelector("#loader .progress")
|
||||
|
||||
|
||||
snd.buffer = new SoundBuffer()
|
||||
snd.musicGain = snd.buffer.createGain()
|
||||
snd.sfxGain = snd.buffer.createGain()
|
||||
@ -29,97 +29,98 @@ class Loader{
|
||||
0.5
|
||||
)
|
||||
snd.sfxLoudGain.setVolume(1.2)
|
||||
|
||||
snd.buffer.load("/assets/audio/" + assets.audioOgg).then(() => {
|
||||
this.oggNotSupported = false
|
||||
}, () => {
|
||||
this.oggNotSupported = true
|
||||
}).then(() => {
|
||||
|
||||
assets.fonts.forEach(name => {
|
||||
var font = document.createElement("h1")
|
||||
font.style.fontFamily = name
|
||||
font.appendChild(document.createTextNode("I am a font"))
|
||||
this.assetsDiv.appendChild(font)
|
||||
this.promises.push(new Promise((resolve, reject) => {
|
||||
FontDetect.onFontLoaded(name, resolve, reject, {msTimeout: 90000})
|
||||
}))
|
||||
})
|
||||
var fontDetectDiv = document.getElementById("fontdetectHelper")
|
||||
fontDetectDiv.parentNode.removeChild(fontDetectDiv)
|
||||
|
||||
assets.img.forEach(name => {
|
||||
var id = this.getFilename(name)
|
||||
var image = document.createElement("img")
|
||||
this.promises.push(pageEvents.load(image))
|
||||
image.id = name
|
||||
image.src = "/assets/img/" + name
|
||||
this.assetsDiv.appendChild(image)
|
||||
assets.image[id] = image
|
||||
})
|
||||
|
||||
assets.audioSfx.forEach(name => {
|
||||
this.promises.push(this.loadSound(name, snd.sfxGain))
|
||||
})
|
||||
assets.audioMusic.forEach(name => {
|
||||
this.promises.push(this.loadSound(name, snd.musicGain))
|
||||
})
|
||||
assets.audioSfxLR.forEach(name => {
|
||||
this.promises.push(this.loadSound(name, snd.sfxGain).then(sound => {
|
||||
var id = this.getFilename(name)
|
||||
assets.sounds[id + "_p1"] = assets.sounds[id].copy(snd.sfxGainL)
|
||||
assets.sounds[id + "_p2"] = assets.sounds[id].copy(snd.sfxGainR)
|
||||
}))
|
||||
})
|
||||
assets.audioSfxLoud.forEach(name => {
|
||||
this.promises.push(this.loadSound(name, snd.sfxLoudGain))
|
||||
})
|
||||
|
||||
this.promises.push(this.ajax("/api/songs").then(songs => {
|
||||
assets.songs = JSON.parse(songs)
|
||||
}))
|
||||
|
||||
this.promises.push(this.ajax("/api/config").then(conf => {
|
||||
gameConfig = JSON.parse(conf)
|
||||
}))
|
||||
|
||||
assets.views.forEach(name => {
|
||||
var id = this.getFilename(name)
|
||||
this.promises.push(this.ajax("src/views/" + name).then(page => {
|
||||
assets.pages[id] = page
|
||||
}))
|
||||
})
|
||||
|
||||
this.promises.push(this.canvasTest.blurPerformance().then(result => {
|
||||
perf.blur = result
|
||||
if(result > 1000 / 50){
|
||||
// Less than 50 fps with blur enabled
|
||||
disableBlur = true
|
||||
}
|
||||
}))
|
||||
|
||||
this.promises.forEach(promise => {
|
||||
promise.then(this.assetLoaded.bind(this))
|
||||
})
|
||||
|
||||
Promise.all(this.promises).then(() => {
|
||||
this.canvasTest.drawAllImages().then(result => {
|
||||
perf.allImg = result
|
||||
perf.load = (+new Date) - this.startTime
|
||||
this.canvasTest.clean()
|
||||
this.clean()
|
||||
this.callback()
|
||||
this.promises.push(this.ajax("/api/config").then(conf => {
|
||||
gameConfig = JSON.parse(conf)
|
||||
|
||||
snd.buffer.load(gameConfig.assets_baseurl + "audio/" + assets.audioOgg).then(() => {
|
||||
this.oggNotSupported = false
|
||||
}, () => {
|
||||
this.oggNotSupported = true
|
||||
}).then(() => {
|
||||
|
||||
assets.fonts.forEach(name => {
|
||||
var font = document.createElement("h1")
|
||||
font.style.fontFamily = name
|
||||
font.appendChild(document.createTextNode("I am a font"))
|
||||
this.assetsDiv.appendChild(font)
|
||||
this.promises.push(new Promise((resolve, reject) => {
|
||||
FontDetect.onFontLoaded(name, resolve, reject, {msTimeout: 90000})
|
||||
}))
|
||||
})
|
||||
}, this.errorMsg.bind(this))
|
||||
|
||||
})
|
||||
var fontDetectDiv = document.getElementById("fontdetectHelper")
|
||||
fontDetectDiv.parentNode.removeChild(fontDetectDiv)
|
||||
|
||||
assets.img.forEach(name => {
|
||||
var id = this.getFilename(name)
|
||||
var image = document.createElement("img")
|
||||
this.promises.push(pageEvents.load(image))
|
||||
image.id = name
|
||||
image.src = gameConfig.assets_baseurl + "img/" + name
|
||||
this.assetsDiv.appendChild(image)
|
||||
assets.image[id] = image
|
||||
})
|
||||
|
||||
assets.audioSfx.forEach(name => {
|
||||
this.promises.push(this.loadSound(name, snd.sfxGain))
|
||||
})
|
||||
assets.audioMusic.forEach(name => {
|
||||
this.promises.push(this.loadSound(name, snd.musicGain))
|
||||
})
|
||||
assets.audioSfxLR.forEach(name => {
|
||||
this.promises.push(this.loadSound(name, snd.sfxGain).then(sound => {
|
||||
var id = this.getFilename(name)
|
||||
assets.sounds[id + "_p1"] = assets.sounds[id].copy(snd.sfxGainL)
|
||||
assets.sounds[id + "_p2"] = assets.sounds[id].copy(snd.sfxGainR)
|
||||
}))
|
||||
})
|
||||
assets.audioSfxLoud.forEach(name => {
|
||||
this.promises.push(this.loadSound(name, snd.sfxLoudGain))
|
||||
})
|
||||
|
||||
this.promises.push(this.ajax("/api/songs").then(songs => {
|
||||
assets.songs = JSON.parse(songs)
|
||||
}))
|
||||
|
||||
assets.views.forEach(name => {
|
||||
var id = this.getFilename(name)
|
||||
this.promises.push(this.ajax("src/views/" + name).then(page => {
|
||||
assets.pages[id] = page
|
||||
}))
|
||||
})
|
||||
|
||||
this.promises.push(this.canvasTest.blurPerformance().then(result => {
|
||||
perf.blur = result
|
||||
if(result > 1000 / 50){
|
||||
// Less than 50 fps with blur enabled
|
||||
disableBlur = true
|
||||
}
|
||||
}))
|
||||
|
||||
this.promises.forEach(promise => {
|
||||
promise.then(this.assetLoaded.bind(this))
|
||||
})
|
||||
|
||||
Promise.all(this.promises).then(() => {
|
||||
this.canvasTest.drawAllImages().then(result => {
|
||||
perf.allImg = result
|
||||
perf.load = (+new Date) - this.startTime
|
||||
this.canvasTest.clean()
|
||||
this.clean()
|
||||
this.callback()
|
||||
})
|
||||
}, this.errorMsg.bind(this))
|
||||
|
||||
})
|
||||
}))
|
||||
|
||||
}
|
||||
loadSound(name, gain){
|
||||
if(this.oggNotSupported && name.endsWith(".ogg")){
|
||||
name = name.slice(0, -4) + ".wav"
|
||||
}
|
||||
var id = this.getFilename(name)
|
||||
return gain.load("/assets/audio/" + name).then(sound => {
|
||||
return gain.load(gameConfig.assets_baseurl + "audio/" + name).then(sound => {
|
||||
assets.sounds[id] = sound
|
||||
})
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
<link rel="stylesheet" href="/src/css/loadsong.css?{{version.commit_short}}">
|
||||
<link rel="stylesheet" href="/src/css/game.css?{{version.commit_short}}">
|
||||
<link rel="stylesheet" href="/src/css/debug.css?{{version.commit_short}}">
|
||||
<link rel="stylesheet" href="{{config.assets_baseurl}}fonts/fonts.css?{{version.commit_short}}">
|
||||
|
||||
<script src="/src/js/lib/fontdetect.min.js?{{version.commit_short}}"></script>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user