Skip to content

Commit

Permalink
Remove absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Popov72 committed Nov 18, 2019
1 parent 8766107 commit c942b18
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 34 deletions.
5 changes: 0 additions & 5 deletions babylonJS/public/TRN.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
<script src="lib/pako/pako_inflate.js"></script>

<script src='dist/trn_babylon.js' defer></script>

<style type="text/css" media="all">@import "/resources/css/panel.css?ver=3";</style>
<style type="text/css" media="all">@import "/resources/css/progressbar.css";</style>
<style type="text/css" media="all">@import "/resources/css/help.css?ver=2";</style>
<style type="text/css" media="all">@import "/resources/css/cccontrol.css?ver=1";</style>
</head>

<body>
Expand Down
2 changes: 1 addition & 1 deletion babylonJS/src/Behaviour/ParticleSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class ParticleSystem extends Behaviour {
}
}

const promise = fetch(`/resources/particle/${pname}.json`).then((response) => {
const promise = fetch(`${this.gameData.relpath}resources/particle/${pname}.json`).then((response) => {
if (response.ok) {
response.json().then((json) => {
positions.forEach((obj, idx) => {
Expand Down
4 changes: 2 additions & 2 deletions babylonJS/src/ShaderManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export class ShaderManager extends ShaderManagerBase {

protected _uniforms: Map<string, Set<string>>;

constructor() {
super();
constructor(dirPath?: string) {
super(dirPath);

this._uniforms = new Map();
}
Expand Down
5 changes: 4 additions & 1 deletion babylonJS/src/TRN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Engine as BEngine
} from "babylonjs";

import Browser from "../../src/Utils/Browser";
import Engine from "../../src/Proxy/Engine";
import { IMesh } from "../../src/Proxy/IMesh";
import { IScene } from "../../src/Proxy/IScene";
Expand All @@ -18,11 +19,13 @@ import SceneParser from "./SceneParser";

declare var glMatrix: any;

const relPath = Browser.QueryString.relpath || "";

glMatrix.glMatrix.setMatrixArrayType(Array);

const canvas = document.createElement("canvas"),
engine = new BEngine(canvas, true),
shdMgr = new ShaderManager();
shdMgr = new ShaderManager(relPath + "resources/shader/");

Engine.registerFunctions({
"makeNode": (name?: string, scene?: IScene) => new Node(undefined, name, scene as Scene),
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
}
jQuery('#levels').html(js.join(''));
} else {
fetch('/resources/level/TRLevels.xml').then((response) => {
fetch('resources/level/TRLevels.xml').then((response) => {
response.text().then((txt) => {
const root = jQuery.parseXML(txt);
var levels = jQuery(root).find('game[id="' + game + '"] > levels > level');
Expand Down Expand Up @@ -228,7 +228,7 @@
if (gamepath == 'TR4Cut') {
gamepath = 'TR4';
}
let url = engine + '/public/TRN.html?engine=' + engine + '&trgame=' + game + '&level=' + gamepath.toLowerCase() + '/' + level + '&autostart=' + (type == 'cutscene' ? '0' : '1');
let url = engine + '/public/TRN.html?relpath=../../&engine=' + engine + '&trgame=' + game + '&level=' + gamepath.toLowerCase() + '/' + level + '&autostart=' + (type == 'cutscene' ? '0' : '1');
if (game == 'TR4Cut') {
url += '&cutscene=' + ot.attr('cindex');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Behaviour/CutScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class CutScene extends Behaviour {
} else {
promises.push(...this.helper.prepareLevel(this.confMgr.trversion, this.confMgr.levelName as string, 0, []));
promises.push(
Misc.loadSoundAsync(this.sceneData.soundPath + this.sceneData.levelShortFileNameNoExt.toUpperCase()).then((ret: any) => {
Misc.loadSoundAsync(this.gameData.relpath + this.sceneData.soundPath + this.sceneData.levelShortFileNameNoExt.toUpperCase()).then((ret: any) => {
if (!ret || ret.code < 0) {
console.log('Error decoding sound data for cutscene.');
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/Behaviour/CutSceneControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export default class CutSceneControl {
}

public init() {
return fetch('/resources/template/cccontrol.html').then((response) => {
jQuery(`<style type="text/css" media="all">@import "${this._gameData.relpath}resources/css/cccontrol.css";</style>`).appendTo(jQuery(document.body));
return fetch(this._gameData.relpath + 'resources/template/cccontrol.html').then((response) => {
return response.text().then((html) => {
jQuery(document.body).append(html);
});
Expand Down
12 changes: 7 additions & 5 deletions src/Behaviour/CutSceneTR4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ declare var glMatrix: any;

export default class CutSceneTR4 {

private gameData: IGameData;
private sceneData: any;
private objMgr: ObjectManager;
private scene: IScene;
Expand All @@ -24,6 +25,7 @@ export default class CutSceneTR4 {
private lara: IMesh;

constructor(gameData: IGameData, cutscene: CutSceneData, helper: CutSceneHelper, lara: IMesh) {
this.gameData = gameData;
this.sceneData = gameData.sceneData;
this.objMgr = gameData.objMgr;
this.confMgr = gameData.confMgr;
Expand All @@ -34,7 +36,7 @@ export default class CutSceneTR4 {
}

public makeTR4Cutscene(icutscene: number): Promise<any> {
return fetch('/resources/level/tr4/TR4_cutscenes/cut' + icutscene + '.json').then((response) => {
return fetch(this.gameData.relpath + 'resources/level/tr4/TR4_cutscenes/cut' + icutscene + '.json').then((response) => {
return response.json().then((data) => {
const cutscene: Array<any> = [];

Expand All @@ -45,9 +47,9 @@ export default class CutSceneTR4 {

// get the sound for this cut scene
if (cutscene[0].info.audio) {
soundPromise = Misc.loadSoundAsync(this.sceneData.soundPath + cutscene[0].info.audio + '.aac').then((ret: any) => {
if (ret.code < 0) {
console.log('Error decoding sound data for cutscene.');
soundPromise = Misc.loadSoundAsync(this.gameData.relpath + this.sceneData.soundPath + cutscene[0].info.audio + '.aac').then((ret: any) => {
if (!ret || ret.code < 0) {
console.log('Error decoding sound data for cutscene.', ret);
} else {
this.cutscene.sound = ret.sound;
this.cutscene.soundbuffer = ret.soundbuffer;
Expand All @@ -57,7 +59,7 @@ export default class CutSceneTR4 {

if (cutscene[0].index == 1) {
// we play cutscene 1 followed by cutscene 2, so need to retrieve data for cutscene 2
return fetch('/resources/level/tr4/TR4_cutscenes/cut' + (icutscene + 1) + '.json').then((response) => {
return fetch(this.gameData.relpath + 'resources/level/tr4/TR4_cutscenes/cut' + (icutscene + 1) + '.json').then((response) => {
return response.json().then((data) => {
cutscene.push(data);
cutscene[1].index = icutscene + 1;
Expand Down
2 changes: 1 addition & 1 deletion src/Loading/LevelConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ export default class LevelConverter {
"out" : this.confMgr.globalColor('water > colorout')
};
this.sc.data.rversion = this.sc.data.trlevel.rversion;
this.sc.data.soundPath = "/resources/sound/" + this.sc.data.rversion.toLowerCase() + "/";
this.sc.data.soundPath = "resources/sound/" + this.sc.data.rversion.toLowerCase() + "/";

this.helper = new LevelConverterHelper(this.sc, this.objects);

Expand Down
10 changes: 6 additions & 4 deletions src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Play from "./Player/Play";
import { ConfigManager } from "./ConfigManager";

const showTiles = false;
const relPath = Browser.QueryString.relpath || "";

function setContainerDimensions() {
if (!showTiles) {
Expand Down Expand Up @@ -48,19 +49,20 @@ jQuery(document).on('keydown', function(event) {
});

function loadAndPlayLevel(level: string | any) {
const progressbar = new ProgressBar(document.getElementById('container') as Element);
const progressbar = new ProgressBar(document.getElementById('container') as Element, relPath);

progressbar.show();

fetch('/resources/level/TRLevels.xml').then((response) => {
fetch(relPath + 'resources/level/TRLevels.xml').then((response) => {
response.text().then((txt) => {
const confMgr = new ConfigManager(jQuery.parseXML(txt));

MasterLoader.loadLevel(level, confMgr).then((res) => {
if (!showTiles) {
const play = new Play(document.getElementById('container') as Element);
(window as any).play = play;
fetch('/resources/template/help.html').then((response) => {
jQuery(`<style type="text/css" media="all">@import "${relPath}resources/css/help.css";</style>`).appendTo(jQuery(document.body));
fetch(relPath + 'resources/template/help.html').then((response) => {
response.text().then((html) => {
jQuery(html).appendTo(document.body);
});
Expand Down Expand Up @@ -124,7 +126,7 @@ function handleFileSelect(evt: Event) {
}

if (Browser.QueryString.level) {
loadAndPlayLevel('/resources/level/' + Browser.QueryString.level);
loadAndPlayLevel(relPath + 'resources/level/' + Browser.QueryString.level);
} else {
jQuery('body').prepend('<input type="file" id="files" multiple="multiple" _style="display: none" />');

Expand Down
1 change: 1 addition & 0 deletions src/Player/IGameData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SystemLight } from "./SystemLight";
import Play from "./Play";

export default interface IGameData {
"relpath": string;
"play": Play;

"curFrame": number;
Expand Down
1 change: 1 addition & 0 deletions src/Player/Play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default class Play {

constructor(container: Element) {
this.gameData = {
"relpath": Browser.QueryString.relpath || "/",
"play": this,

"curFrame": 0,
Expand Down
4 changes: 2 additions & 2 deletions src/ShaderManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export class ShaderManager {
protected _level: RawLevel;
protected _globalLightsInFragment: boolean;

constructor() {
this._fpath = '/resources/shader/';
constructor(dirPath?: string) {
this._fpath = dirPath || 'resources/shader/';
this._fileCache = {};
this._level = <any>null;
this._globalLightsInFragment = true;
Expand Down
3 changes: 2 additions & 1 deletion src/Utils/Panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export class Panel {
this._renderer = renderer;
this._show = false;

fetch('/resources/template/panel.html').then((response) => {
jQuery(`<style type="text/css" media="all">@import "${gameData.relpath}resources/css/panel.css?ver=3";</style>`).appendTo(domElement);
fetch(gameData.relpath + 'resources/template/panel.html').then((response) => {
response.text().then((html) => {
this._elem = jQuery(html);
this._elem.appendTo(domElement);
Expand Down
5 changes: 3 additions & 2 deletions src/Utils/ProgressBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ export class ProgressBar {
protected _showStart: boolean;
protected _callback: any;

constructor(domElement: Element) {
constructor(domElement: Element, relpath: string = "") {
this._elem = jQuery('');
this._show = false;
this._showStart = false;

fetch('/resources/template/progressbar.html').then((response) => {
jQuery(`<style type="text/css" media="all">@import "${relpath}resources/css/progressbar.css";</style>`).appendTo(domElement);
fetch(relpath + 'resources/template/progressbar.html').then((response) => {
response.text().then((html) => {
this._elem = jQuery(html);
this._elem.appendTo(domElement);
Expand Down
5 changes: 0 additions & 5 deletions threeJS/public/TRN.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
<script src="lib/pako/pako_inflate.js"></script>

<script src='dist/trn_three.js' defer></script>

<style type="text/css" media="all">@import "/resources/css/panel.css?ver=3";</style>
<style type="text/css" media="all">@import "/resources/css/progressbar.css";</style>
<style type="text/css" media="all">@import "/resources/css/help.css?ver=2";</style>
<style type="text/css" media="all">@import "/resources/css/cccontrol.css?ver=1";</style>
</head>

<body>
Expand Down
5 changes: 4 additions & 1 deletion threeJS/src/TRN.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Browser from "../../src/Utils/Browser";
import Engine from "../../src/Proxy/Engine";
import { IMesh } from "../../src/Proxy/IMesh";
import { ShaderManager } from "../../src/ShaderManager";
Expand All @@ -12,9 +13,11 @@ import SceneParser from "./SceneParser";

declare var glMatrix: any;

const relPath = Browser.QueryString.relpath || "";

glMatrix.glMatrix.setMatrixArrayType(Array);

const shdMgr = new ShaderManager();
const shdMgr = new ShaderManager(relPath + "resources/shader/");

Engine.registerFunctions({
"makeNode": () => new Node(),
Expand Down

0 comments on commit c942b18

Please sign in to comment.