Skip to content

Commit 88cd236

Browse files
authored
Fix Curves function names clashing with Runes function names (#341)
* Add loadLib function - Rename loadLibs -> loadAllLibs - Make loadLib function that loads specific files * Use loadLib in saga * Add canvas initialisation for 3d and curves This seems to have gona missing from a previous commit. Whoops. * Refactor file dynamic loading * Add some documentation * expose translate and scale
1 parent f950cbd commit 88cd236

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

public/externalLibs/index.js

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ function dynamicallyLoadScript(url) {
1212
}
1313

1414
/**
15-
* Loads all the required libraries
15+
* Loads all libraries, including sound and graphics.
1616
*/
17-
function loadLibs() {
17+
function loadAllLibs() {
1818
const files = [
1919
// list library
2020
'/externalLibs/list.js',
@@ -39,4 +39,46 @@ function loadLibs() {
3939
}
4040
}
4141

42-
loadLibs();
42+
/**
43+
* Loads libraries according to the name provided.
44+
* This is to faciliate a lack of namespace clash for
45+
* graphics libraries (@see #341)
46+
*/
47+
function loadLib(externalLibraryName) {
48+
let files;
49+
switch(externalLibraryName) {
50+
case "TWO_DIM_RUNES":
51+
files = [
52+
// graphics
53+
'/externalLibs/graphics/gl-matrix.js',
54+
'/externalLibs/graphics/webGLgraphics.js',
55+
'/externalLibs/graphics/webGLrune.js',
56+
];
57+
break;
58+
case "THREE_DIM_RUNES":
59+
files = [
60+
// graphics
61+
'/externalLibs/graphics/gl-matrix.js',
62+
'/externalLibs/graphics/webGLgraphics.js',
63+
'/externalLibs/graphics/webGLrune.js',
64+
];
65+
break;
66+
case "CURVES":
67+
files = [
68+
// graphics
69+
'/externalLibs/graphics/gl-matrix.js',
70+
'/externalLibs/graphics/webGLhi_graph.js',
71+
'/externalLibs/graphics/webGLhi_graph_ce.js',
72+
'/externalLibs/graphics/webGLgraphics.js',
73+
'/externalLibs/graphics/webGLcurve.js',
74+
];
75+
break;
76+
default:
77+
break;
78+
}
79+
for (var i = 0; i < files.length; i++) {
80+
dynamicallyLoadScript(files[i]);
81+
}
82+
}
83+
84+
loadAllLibs();

src/reducers/externalLibraries.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ const libEntries: Array<[ExternalLibraryName, string[]]> = [
8585
'put_in_standard_position',
8686
'full_view_proportional',
8787
'squeeze_full_view',
88-
'squeeze_rectangular_portion'
88+
'squeeze_rectangular_portion',
89+
'translate',
90+
'scale'
8991
]
9092
],
9193
[

src/sagas/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,15 @@ function* workspaceSaga(): SagaIterator {
200200
const externalLibraryName = (action as actionTypes.IAction).payload.library.external.name
201201
switch (externalLibraryName) {
202202
case ExternalLibraryNames.TWO_DIM_RUNES:
203+
;(window as any).loadLib('TWO_DIM_RUNES')
203204
;(window as any).getReadyWebGLForCanvas('2d')
204205
break
205206
case ExternalLibraryNames.THREE_DIM_RUNES:
207+
;(window as any).loadLib('THREE_DIM_RUNES')
206208
;(window as any).getReadyWebGLForCanvas('3d')
207209
break
208210
case ExternalLibraryNames.CURVES:
211+
;(window as any).loadLib('CURVES')
209212
;(window as any).getReadyWebGLForCanvas('curve')
210213
break
211214
}

0 commit comments

Comments
 (0)