mirror of
https://github.com/jiojciojsioe3/a3cjroijsiojiorj.git
synced 2024-11-22 10:51:50 +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;
|
||||
|
@ -30,7 +30,10 @@ class Loader{
|
||||
)
|
||||
snd.sfxLoudGain.setVolume(1.2)
|
||||
|
||||
snd.buffer.load("/assets/audio/" + assets.audioOgg).then(() => {
|
||||
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
|
||||
@ -53,7 +56,7 @@ class Loader{
|
||||
var image = document.createElement("img")
|
||||
this.promises.push(pageEvents.load(image))
|
||||
image.id = name
|
||||
image.src = "/assets/img/" + name
|
||||
image.src = gameConfig.assets_baseurl + "img/" + name
|
||||
this.assetsDiv.appendChild(image)
|
||||
assets.image[id] = image
|
||||
})
|
||||
@ -79,10 +82,6 @@ class Loader{
|
||||
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 => {
|
||||
@ -113,13 +112,15 @@ class Loader{
|
||||
}, 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