Merge pull request #63 from bui/game-config

add game config
This commit is contained in:
Bui 2018-10-28 08:33:36 +00:00 committed by GitHub
commit 6d07afaa11
9 changed files with 34 additions and 8 deletions

1
.gitignore vendored
View File

@ -46,3 +46,4 @@ public/api
taiko.db
version.json
public/index.html
config.json

16
app.py
View File

@ -163,6 +163,22 @@ def route_api_songs():
return jsonify(songs_out)
@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']) + '/'
return jsonify(config)
def make_preview(song_id, song_type):
song_path = 'public/songs/%s/main.mp3' % song_id
prev_path = 'public/songs/%s/preview.mp3' % song_id

3
config.example.json Normal file
View File

@ -0,0 +1,3 @@
{
"songs_baseurl": ""
}

View File

@ -125,3 +125,5 @@ var assets = {
"image": {},
"pages": {}
}
var gameConfig = {}

View File

@ -7,7 +7,7 @@ class Controller{
this.touchEnabled = touchEnabled
this.snd = this.multiplayer ? "_p" + this.multiplayer : ""
var backgroundURL = "/songs/" + this.selectedSong.folder + "/bg.png"
var backgroundURL = gameConfig.songs_baseurl + this.selectedSong.folder + "/bg.png"
if(selectedSong.type === "tja"){
this.parsedSongData = new ParseTja(songData, selectedSong.difficulty, selectedSong.offset)

View File

@ -78,6 +78,10 @@ class Loader{
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)

View File

@ -19,7 +19,7 @@ class loadSong{
resolve()
})
img.id = "music-bg"
img.src = "/songs/" + id + "/bg.png"
img.src = gameConfig.songs_baseurl + id + "/bg.png"
document.getElementById("assets").appendChild(img)
}))
@ -34,7 +34,7 @@ class loadSong{
songObj.sound.gain = snd.musicGain
resolve()
}else{
snd.musicGain.load("/songs/" + id + "/main.mp3").then(sound => {
snd.musicGain.load(gameConfig.songs_baseurl + id + "/main.mp3").then(sound => {
songObj.sound = sound
resolve()
}, reject)
@ -51,7 +51,7 @@ class loadSong{
})
}
getSongPath(selectedSong){
var directory = "/songs/" + selectedSong.folder + "/"
var directory = gameConfig.songs_baseurl + selectedSong.folder + "/"
if(selectedSong.type === "tja"){
return directory + "main.tja"
}else{

View File

@ -1,11 +1,11 @@
class SongSelect{
constructor(fromTutorial, fadeIn, touchEnabled){
this.touchEnabled = touchEnabled
loader.changePage("songselect")
this.canvas = document.getElementById("song-sel-canvas")
this.ctx = this.canvas.getContext("2d")
this.songSkin = {
"selected": {
background: "#ffdb2c",
@ -1363,7 +1363,7 @@ class SongSelect{
var previewFilename = prvTime > 0.1 ? "/preview.mp3" : "/main.mp3"
var loadPreview = previewFilename => {
return snd.previewGain.load("/songs/" + id + previewFilename)
return snd.previewGain.load(gameConfig.songs_baseurl + id + previewFilename)
}
songObj.preview_time = 0

View File

@ -751,7 +751,7 @@
setBackground(){
var gameDiv = document.getElementById("game")
var selectedSong = this.controller.selectedSong
var bg = "/songs/" + selectedSong.folder + "/bg.png"
var bg = gameConfig.songs_baseurl + selectedSong.folder + "/bg.png"
if(selectedSong.defaultBg){
var categories = {
"J-POP": 0,