taiko-web development has returned to GitHub. This Gitea instance will be shut down soon.
If your taiko-web fork is unavailable due to DMCA takedown, you can contact GitHub Support and ask for it to be deleted.
Browse Source

add assets_baseurl config option

Bui 3 months ago
parent
commit
d1ae38e9c4
5 changed files with 106 additions and 102 deletions
  1. 21
    12
      app.py
  2. 2
    1
      config.example.json
  3. 0
    8
      public/src/css/main.css
  4. 82
    81
      public/src/js/loader.js
  5. 1
    0
      templates/index.html

+ 21
- 12
app.py View File

@@ -27,6 +27,25 @@ def query_db(query, args=(), one=False):
27 27
     return (rv[0] if rv else None) if one else rv
28 28
 
29 29
 
30
+def get_config():
31
+    if os.path.isfile('config.json'):
32
+        try:
33
+            config = json.load(open('config.json', 'r'))
34
+        except ValueError:
35
+            print 'WARNING: Invalid config.json, using default values'
36
+            config = {}
37
+    else:
38
+        print 'WARNING: No config.json found, using default values'
39
+        config = {}
40
+
41
+    if not config.get('songs_baseurl'):
42
+        config['songs_baseurl'] = ''.join([request.host_url, 'songs']) + '/'
43
+    if not config.get('assets_baseurl'):
44
+        config['assets_baseurl'] = ''.join([request.host_url, 'assets']) + '/'
45
+
46
+    return config
47
+
48
+
30 49
 def parse_osu(osu):
31 50
     osu_lines = open(osu, 'r').read().replace('\x00', '').split('\n')
32 51
     sections = {}
@@ -110,7 +129,7 @@ def route_index():
110 129
     version = None
111 130
     if os.path.isfile('version.json'):
112 131
         version = json.load(open('version.json', 'r'))
113
-    return render_template('index.html', version=version)
132
+    return render_template('index.html', version=version, config=get_config())
114 133
 
115 134
 
116 135
 @app.route('/api/preview')
@@ -165,17 +184,7 @@ def route_api_songs():
165 184
 
166 185
 @app.route('/api/config')
167 186
 def route_api_config():
168
-    if os.path.isfile('config.json'):
169
-        config = json.load(open('config.json', 'r'))
170
-    else:
171
-        print 'WARNING: No config.json found, using default values'
172
-        config = {
173
-            'songs_baseurl': ''.join([request.host_url, 'songs']) + '/'
174
-        }
175
-
176
-    if not config.get('songs_baseurl'):
177
-        config['songs_baseurl'] = ''.join([request.host_url, 'songs']) + '/'
178
-
187
+    config = get_config()
179 188
     return jsonify(config)
180 189
 
181 190
 

+ 2
- 1
config.example.json View File

@@ -1,3 +1,4 @@
1 1
 {
2
-    "songs_baseurl": ""
2
+    "songs_baseurl": "",
3
+    "assets_baseurl": ""
3 4
 }

+ 0
- 8
public/src/css/main.css View File

@@ -1,11 +1,3 @@
1
[email protected]{
2
-	font-family: TnT;
3
-	src: url("/assets/fonts/TnT.ttf") format("truetype");
4
-}
5
[email protected]{
6
-	font-family: Kozuka;
7
-	src: url("/assets/fonts/Kozuka.otf") format("truetype");
8
-}
9 1
 html,
10 2
 body{
11 3
 	margin: 0;

+ 82
- 81
public/src/js/loader.js View File

@@ -15,7 +15,7 @@ class Loader{
15 15
 		this.screen.innerHTML = page
16 16
 		this.loaderPercentage = document.querySelector("#loader .percentage")
17 17
 		this.loaderProgress = document.querySelector("#loader .progress")
18
-		
18
+
19 19
 		snd.buffer = new SoundBuffer()
20 20
 		snd.musicGain = snd.buffer.createGain()
21 21
 		snd.sfxGain = snd.buffer.createGain()
@@ -29,97 +29,98 @@ class Loader{
29 29
 			0.5
30 30
 		)
31 31
 		snd.sfxLoudGain.setVolume(1.2)
32
-		
33
-		snd.buffer.load("/assets/audio/" + assets.audioOgg).then(() => {
34
-			this.oggNotSupported = false
35
-		}, () => {
36
-			this.oggNotSupported = true
37
-		}).then(() => {
38
-			
39
-			assets.fonts.forEach(name => {
40
-				var font = document.createElement("h1")
41
-				font.style.fontFamily = name
42
-				font.appendChild(document.createTextNode("I am a font"))
43
-				this.assetsDiv.appendChild(font)
44
-				this.promises.push(new Promise((resolve, reject) => {
45
-					FontDetect.onFontLoaded(name, resolve, reject, {msTimeout: 90000})
46
-				}))
47
-			})
48
-			var fontDetectDiv = document.getElementById("fontdetectHelper")
49
-			fontDetectDiv.parentNode.removeChild(fontDetectDiv)
50
-			
51
-			assets.img.forEach(name => {
52
-				var id = this.getFilename(name)
53
-				var image = document.createElement("img")
54
-				this.promises.push(pageEvents.load(image))
55
-				image.id = name
56
-				image.src = "/assets/img/" + name
57
-				this.assetsDiv.appendChild(image)
58
-				assets.image[id] = image
59
-			})
60
-			
61
-			assets.audioSfx.forEach(name => {
62
-				this.promises.push(this.loadSound(name, snd.sfxGain))
63
-			})
64
-			assets.audioMusic.forEach(name => {
65
-				this.promises.push(this.loadSound(name, snd.musicGain))
66
-			})
67
-			assets.audioSfxLR.forEach(name => {
68
-				this.promises.push(this.loadSound(name, snd.sfxGain).then(sound => {
32
+
33
+		this.promises.push(this.ajax("/api/config").then(conf => {
34
+			gameConfig = JSON.parse(conf)
35
+
36
+			snd.buffer.load(gameConfig.assets_baseurl + "audio/" + assets.audioOgg).then(() => {
37
+				this.oggNotSupported = false
38
+			}, () => {
39
+				this.oggNotSupported = true
40
+			}).then(() => {
41
+				
42
+				assets.fonts.forEach(name => {
43
+					var font = document.createElement("h1")
44
+					font.style.fontFamily = name
45
+					font.appendChild(document.createTextNode("I am a font"))
46
+					this.assetsDiv.appendChild(font)
47
+					this.promises.push(new Promise((resolve, reject) => {
48
+						FontDetect.onFontLoaded(name, resolve, reject, {msTimeout: 90000})
49
+					}))
50
+				})
51
+				var fontDetectDiv = document.getElementById("fontdetectHelper")
52
+				fontDetectDiv.parentNode.removeChild(fontDetectDiv)
53
+				
54
+				assets.img.forEach(name => {
69 55
 					var id = this.getFilename(name)
70
-					assets.sounds[id + "_p1"] = assets.sounds[id].copy(snd.sfxGainL)
71
-					assets.sounds[id + "_p2"] = assets.sounds[id].copy(snd.sfxGainR)
56
+					var image = document.createElement("img")
57
+					this.promises.push(pageEvents.load(image))
58
+					image.id = name
59
+					image.src = gameConfig.assets_baseurl + "img/" + name
60
+					this.assetsDiv.appendChild(image)
61
+					assets.image[id] = image
62
+				})
63
+				
64
+				assets.audioSfx.forEach(name => {
65
+					this.promises.push(this.loadSound(name, snd.sfxGain))
66
+				})
67
+				assets.audioMusic.forEach(name => {
68
+					this.promises.push(this.loadSound(name, snd.musicGain))
69
+				})
70
+				assets.audioSfxLR.forEach(name => {
71
+					this.promises.push(this.loadSound(name, snd.sfxGain).then(sound => {
72
+						var id = this.getFilename(name)
73
+						assets.sounds[id + "_p1"] = assets.sounds[id].copy(snd.sfxGainL)
74
+						assets.sounds[id + "_p2"] = assets.sounds[id].copy(snd.sfxGainR)
75
+					}))
76
+				})
77
+				assets.audioSfxLoud.forEach(name => {
78
+					this.promises.push(this.loadSound(name, snd.sfxLoudGain))
79
+				})
80
+				
81
+				this.promises.push(this.ajax("/api/songs").then(songs => {
82
+					assets.songs = JSON.parse(songs)
72 83
 				}))
73
-			})
74
-			assets.audioSfxLoud.forEach(name => {
75
-				this.promises.push(this.loadSound(name, snd.sfxLoudGain))
76
-			})
77
-			
78
-			this.promises.push(this.ajax("/api/songs").then(songs => {
79
-				assets.songs = JSON.parse(songs)
80
-			}))
81 84
 
82
-			this.promises.push(this.ajax("/api/config").then(conf => {
83
-				gameConfig = JSON.parse(conf)
84
-			}))
85
-			
86
-			assets.views.forEach(name => {
87
-				var id = this.getFilename(name)
88
-				this.promises.push(this.ajax("src/views/" + name).then(page => {
89
-					assets.pages[id] = page
85
+				assets.views.forEach(name => {
86
+					var id = this.getFilename(name)
87
+					this.promises.push(this.ajax("src/views/" + name).then(page => {
88
+						assets.pages[id] = page
89
+					}))
90
+				})
91
+				
92
+				this.promises.push(this.canvasTest.blurPerformance().then(result => {
93
+					perf.blur = result
94
+					if(result > 1000 / 50){
95
+						// Less than 50 fps with blur enabled
96
+						disableBlur = true
97
+					}
90 98
 				}))
91
-			})
92
-			
93
-			this.promises.push(this.canvasTest.blurPerformance().then(result => {
94
-				perf.blur = result
95
-				if(result > 1000 / 50){
96
-					// Less than 50 fps with blur enabled
97
-					disableBlur = true
98
-				}
99
-			}))
100
-			
101
-			this.promises.forEach(promise => {
102
-				promise.then(this.assetLoaded.bind(this))
103
-			})
104
-			
105
-			Promise.all(this.promises).then(() => {
106
-				this.canvasTest.drawAllImages().then(result => {
107
-					perf.allImg = result
108
-					perf.load = (+new Date) - this.startTime
109
-					this.canvasTest.clean()
110
-					this.clean()
111
-					this.callback()
99
+				
100
+				this.promises.forEach(promise => {
101
+					promise.then(this.assetLoaded.bind(this))
112 102
 				})
113
-			}, this.errorMsg.bind(this))
114
-			
115
-		})
103
+				
104
+				Promise.all(this.promises).then(() => {
105
+					this.canvasTest.drawAllImages().then(result => {
106
+						perf.allImg = result
107
+						perf.load = (+new Date) - this.startTime
108
+						this.canvasTest.clean()
109
+						this.clean()
110
+						this.callback()
111
+					})
112
+				}, this.errorMsg.bind(this))
113
+				
114
+			})
115
+		}))
116
+
116 117
 	}
117 118
 	loadSound(name, gain){
118 119
 		if(this.oggNotSupported && name.endsWith(".ogg")){
119 120
 			name = name.slice(0, -4) + ".wav"
120 121
 		}
121 122
 		var id = this.getFilename(name)
122
-		return gain.load("/assets/audio/" + name).then(sound => {
123
+		return gain.load(gameConfig.assets_baseurl + "audio/" + name).then(sound => {
123 124
 			assets.sounds[id] = sound
124 125
 		})
125 126
 	}

+ 1
- 0
templates/index.html View File

@@ -22,6 +22,7 @@
22 22
 	<link rel="stylesheet" href="/src/css/loadsong.css?{{version.commit_short}}">
23 23
 	<link rel="stylesheet" href="/src/css/game.css?{{version.commit_short}}">
24 24
 	<link rel="stylesheet" href="/src/css/debug.css?{{version.commit_short}}">
25
+	<link rel="stylesheet" href="{{config.assets_baseurl}}fonts/fonts.css?{{version.commit_short}}">
25 26
 	
26 27
 	<script src="/src/js/lib/fontdetect.min.js?{{version.commit_short}}"></script>
27 28
 	

Loading…
Cancel
Save