mirror of
https://github.com/jiojciojsioe3/a3cjroijsiojiorj.git
synced 2024-11-15 07:21:50 +08:00
Dynamic songskin loading for categories
This commit is contained in:
parent
d98b2d9697
commit
85d6e70ff6
10
app.py
10
app.py
@ -188,8 +188,9 @@ def route_admin():
|
|||||||
@admin_required(level=50)
|
@admin_required(level=50)
|
||||||
def route_admin_songs():
|
def route_admin_songs():
|
||||||
songs = db.songs.find({})
|
songs = db.songs.find({})
|
||||||
|
categories = db.categories.find({})
|
||||||
user = db.users.find_one({'username': session['username']})
|
user = db.users.find_one({'username': session['username']})
|
||||||
return render_template('admin_songs.html', songs=list(songs), admin=user)
|
return render_template('admin_songs.html', songs=list(songs), admin=user, categories=list(categories))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/admin/songs/<int:id>')
|
@app.route('/admin/songs/<int:id>')
|
||||||
@ -358,7 +359,7 @@ def route_api_songs():
|
|||||||
song['category'] = db.categories.find_one({'id': song['category_id']})['title']
|
song['category'] = db.categories.find_one({'id': song['category_id']})['title']
|
||||||
else:
|
else:
|
||||||
song['category'] = None
|
song['category'] = None
|
||||||
del song['category_id']
|
#del song['category_id']
|
||||||
|
|
||||||
if song['skin_id']:
|
if song['skin_id']:
|
||||||
song['song_skin'] = db.song_skins.find_one({'id': song['skin_id']}, {'_id': False, 'id': False})
|
song['song_skin'] = db.song_skins.find_one({'id': song['skin_id']}, {'_id': False, 'id': False})
|
||||||
@ -368,6 +369,11 @@ def route_api_songs():
|
|||||||
|
|
||||||
return jsonify(songs)
|
return jsonify(songs)
|
||||||
|
|
||||||
|
@app.route('/api/categories')
|
||||||
|
@app.cache.cached(timeout=15)
|
||||||
|
def route_api_categories():
|
||||||
|
categories = list(db.categories.find({},{'_id': False}))
|
||||||
|
return jsonify(categories)
|
||||||
|
|
||||||
@app.route('/api/config')
|
@app.route('/api/config')
|
||||||
@app.cache.cached(timeout=15)
|
@app.cache.cached(timeout=15)
|
||||||
|
BIN
public/assets/img/bg_genre_def.png
Normal file
BIN
public/assets/img/bg_genre_def.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
@ -83,6 +83,7 @@ var assets = {
|
|||||||
"bg_genre_5.png",
|
"bg_genre_5.png",
|
||||||
"bg_genre_6.png",
|
"bg_genre_6.png",
|
||||||
"bg_genre_7.png",
|
"bg_genre_7.png",
|
||||||
|
"bg_genre_def.png",
|
||||||
"bg_score_p1.png",
|
"bg_score_p1.png",
|
||||||
"bg_score_p2.png",
|
"bg_score_p2.png",
|
||||||
"bg_settings.png",
|
"bg_settings.png",
|
||||||
@ -157,7 +158,8 @@ var assets = {
|
|||||||
"songs": [],
|
"songs": [],
|
||||||
"sounds": {},
|
"sounds": {},
|
||||||
"image": {},
|
"image": {},
|
||||||
"pages": {}
|
"pages": {},
|
||||||
|
"categories": {}
|
||||||
}
|
}
|
||||||
|
|
||||||
var gameConfig = {}
|
var gameConfig = {}
|
||||||
|
@ -104,6 +104,10 @@ class Loader{
|
|||||||
assets.pages[id] = page
|
assets.pages[id] = page
|
||||||
}), url)
|
}), url)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.addPromise(this.ajax("/api/categories").then(categories => {
|
||||||
|
assets.categories = JSON.parse(categories)
|
||||||
|
}), "/api/categories")
|
||||||
|
|
||||||
this.addPromise(this.ajax("/api/songs").then(songs => {
|
this.addPromise(this.ajax("/api/songs").then(songs => {
|
||||||
assets.songsDefault = JSON.parse(songs)
|
assets.songsDefault = JSON.parse(songs)
|
||||||
|
@ -96,14 +96,29 @@ class SongSelect{
|
|||||||
background: "#ff5716",
|
background: "#ff5716",
|
||||||
border: ["#ffa66b", "#b53000"],
|
border: ["#ffa66b", "#b53000"],
|
||||||
outline: "#9c2000"
|
outline: "#9c2000"
|
||||||
},
|
|
||||||
"default": {
|
|
||||||
sort: 7,
|
|
||||||
background: "#ececec",
|
|
||||||
border: ["#fbfbfb", "#8b8b8b"],
|
|
||||||
outline: "#656565"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let sortCount = 7;
|
||||||
|
|
||||||
|
for(let category of assets.categories){
|
||||||
|
if(!this.songSkin[category.title] && category.songSkin){
|
||||||
|
if(!category.songSkin.sort){
|
||||||
|
category.songSkin.sort = sortCount
|
||||||
|
sortCount += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
this.songSkin[category.title] = category.songSkin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.songSkin.default = {
|
||||||
|
sort: Object.keys(this.songSkin).length + 1,
|
||||||
|
background: "#ececec",
|
||||||
|
border: ["#fbfbfb", "#8b8b8b"],
|
||||||
|
outline: "#656565"
|
||||||
|
}
|
||||||
|
|
||||||
this.font = strings.font
|
this.font = strings.font
|
||||||
|
|
||||||
this.songs = []
|
this.songs = []
|
||||||
@ -118,6 +133,7 @@ class SongSelect{
|
|||||||
skin: song.category in this.songSkin ? this.songSkin[song.category] : this.songSkin.default,
|
skin: song.category in this.songSkin ? this.songSkin[song.category] : this.songSkin.default,
|
||||||
courses: song.courses,
|
courses: song.courses,
|
||||||
category: song.category,
|
category: song.category,
|
||||||
|
category_id: song.category_id,
|
||||||
preview: song.preview || 0,
|
preview: song.preview || 0,
|
||||||
type: song.type,
|
type: song.type,
|
||||||
offset: song.offset,
|
offset: song.offset,
|
||||||
@ -292,7 +308,7 @@ class SongSelect{
|
|||||||
this.songSelect = document.getElementById("song-select")
|
this.songSelect = document.getElementById("song-select")
|
||||||
var cat = this.songs[this.selectedSong].category
|
var cat = this.songs[this.selectedSong].category
|
||||||
var sort = cat in this.songSkin ? this.songSkin[cat].sort : 7
|
var sort = cat in this.songSkin ? this.songSkin[cat].sort : 7
|
||||||
this.songSelect.style.backgroundImage = "url('" + assets.image["bg_genre_" + sort].src + "')"
|
this.drawBackground(cat, sort)
|
||||||
|
|
||||||
this.previewId = 0
|
this.previewId = 0
|
||||||
this.previewList = Array(5)
|
this.previewList = Array(5)
|
||||||
@ -1201,7 +1217,8 @@ class SongSelect{
|
|||||||
if(this.songs[this.selectedSong].action !== "back"){
|
if(this.songs[this.selectedSong].action !== "back"){
|
||||||
var cat = this.songs[this.selectedSong].category
|
var cat = this.songs[this.selectedSong].category
|
||||||
var sort = cat in this.songSkin ? this.songSkin[cat].sort : 7
|
var sort = cat in this.songSkin ? this.songSkin[cat].sort : 7
|
||||||
this.songSelect.style.backgroundImage = "url('" + assets.image["bg_genre_" + sort].src + "')"
|
|
||||||
|
this.drawBackground(cat, sort)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(this.state.moveMS && ms < this.state.moveMS + changeSpeed){
|
if(this.state.moveMS && ms < this.state.moveMS + changeSpeed){
|
||||||
@ -2306,6 +2323,18 @@ class SongSelect{
|
|||||||
scoreStorage.eventLoop()
|
scoreStorage.eventLoop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drawBackground(cat, sort){
|
||||||
|
if(this.songSkin[cat] && this.songSkin[cat].bg_img){
|
||||||
|
this.songSelect.style.backgroundImage = "url('assets/img/" + this.songSkin[cat].bg_img + "')"
|
||||||
|
}else{
|
||||||
|
if(assets.image["bg_genre_" + sort]){
|
||||||
|
this.songSelect.style.backgroundImage = "url('" + assets.image["bg_genre_" + sort].src + "')"
|
||||||
|
}else{
|
||||||
|
this.songSelect.style.backgroundImage = "url('" + assets.image["bg_genre_def"].src + "')"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
drawClosedSong(config){
|
drawClosedSong(config){
|
||||||
var ctx = config.ctx
|
var ctx = config.ctx
|
||||||
|
Loading…
Reference in New Issue
Block a user