Skip to content

Commit 7b1faa3

Browse files
committed
Refactor constants (#2)
- Move ASSETS_HOST to within constants.js - Add a backend directory to facilitate future communication with the backend - Add ability to toggle asset hosts
1 parent 7f9122c commit 7b1faa3

File tree

4 files changed

+36
-29
lines changed

4 files changed

+36
-29
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const LIVE_ASSETS_HOST = 'https://s3-ap-southeast-1.amazonaws.com/source-academy-assets/';
2+
3+
// placeholder URL
4+
const TEST_ASSETS_HOST = 'https://localhost:8080/source-academy-assets/';
5+
6+
// placeholder predicate
7+
export const ASSETS_HOST = true ? LIVE_ASSETS_HOST : TEST_ASSETS_HOST;
Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
module.exports = {
2-
screenWidth: 1920,
3-
screenHeight: 1080,
4-
dialogBoxHeight: 260,
5-
dialogBoxWidth: 1720,
6-
dialogBoxPadding: 25,
7-
fontSize: 44,
8-
innerDialogPadding: 46,
9-
avatarOffset: 46,
10-
nameBoxXPadding: 50,
11-
nameBoxHeight: 80,
12-
playerAvatarSize: 300,
13-
playerAvatarLineWidth: 10,
14-
playerAvatarOffset: 40,
15-
glowDistance: 30,
16-
textSpeed: 0.02,
17-
storyXMLPath: ASSETS_HOST + 'stories/',
18-
locationPath: ASSETS_HOST + 'locations/',
19-
objectPath: ASSETS_HOST + 'objects/',
20-
imgPath: ASSETS_HOST + 'images/',
21-
avatarPath: ASSETS_HOST + 'avatars/',
22-
uiPath: ASSETS_HOST + 'UI/',
23-
soundPath: ASSETS_HOST + 'sounds/',
24-
fadeTime: 0.3,
25-
nullFunction: function() {}
26-
};
1+
import {ASSETS_HOST} from '../backend/backend'
2+
3+
export const
4+
screenWidth = 1920,
5+
screenHeight = 1080,
6+
dialogBoxHeight = 260,
7+
dialogBoxWidth = 1720,
8+
dialogBoxPadding = 25,
9+
fontSize = 44,
10+
innerDialogPadding = 46,
11+
avatarOffset = 46,
12+
nameBoxXPadding = 50,
13+
nameBoxHeight = 80,
14+
playerAvatarSize = 300,
15+
playerAvatarLineWidth = 10,
16+
playerAvatarOffset = 40,
17+
glowDistance = 30,
18+
textSpeed = 0.02,
19+
storyXMLPath = ASSETS_HOST + 'stories/',
20+
locationPath = ASSETS_HOST + 'locations/',
21+
objectPath = ASSETS_HOST + 'objects/',
22+
imgPath = ASSETS_HOST + 'images/',
23+
avatarPath = ASSETS_HOST + 'avatars/',
24+
uiPath = ASSETS_HOST + 'UI/',
25+
soundPath = ASSETS_HOST + 'sounds/',
26+
fadeTime = 0.3,
27+
nullFunction = function() {};

src/components/academy/game/create-initializer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {LINKS} from '../../../utils/constants'
22
import {history} from '../../../utils/history'
3+
import {soundPath} from './constants/constants'
34

45
export default function (StoryXMLPlayer, story, username, attemptedAll) {
56
function saveToServer() {
@@ -45,7 +46,7 @@ export default function (StoryXMLPlayer, story, username, attemptedAll) {
4546
}
4647
},
4748
playSound: function (name) {
48-
var sound = new Audio(ASSETS_HOST + 'sounds/' + name + '.mp3');
49+
var sound = new Audio(soundPath + name + '.mp3');
4950
if (sound) {
5051
sound.play();
5152
}

src/components/academy/game/game.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import createInitializer from './create-initializer'
22

33
export default function(div, canvas, username, story, attemptedAll) {
4-
window.ASSETS_HOST =
5-
'https://s3-ap-southeast-1.amazonaws.com/source-academy-assets/';
64
var StoryXMLPlayer = require('./story-xml-player');
75
var container = document.getElementById('game-display')
86
var initialize = createInitializer(StoryXMLPlayer, story, username, attemptedAll)

0 commit comments

Comments
 (0)