Merge pull request #2 from lopezloo/issue/1

Add possibility to start app with specific game and vehicle
This commit is contained in:
aap 2022-01-03 15:31:21 +01:00 committed by GitHub
commit b29260e3d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 10 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
iii/*
vc/*
sa/*

View File

@ -8,9 +8,9 @@
<body> <body>
<div id="control"> <div id="control">
<a href="javascript: startVehicleViewerIII();">III</a> <a href="javascript: startVehicleViewerIII(defaultModel);">III</a>
<a href="javascript: startVehicleViewerVC();">VC</a> <a href="javascript: startVehicleViewerVC(defaultModel);">VC</a>
<a href="javascript: startVehicleViewerSA();">SA</a> <a href="javascript: startVehicleViewerSA(defaultModel);">SA</a>
</div> </div>
<canvas id="glcanvas" width="640" height="480" style="float:left"></canvas> <canvas id="glcanvas" width="640" height="480" style="float:left"></canvas>
<div style="float:left"> <div style="float:left">
@ -40,44 +40,95 @@
<script src="main.js"></script> <script src="main.js"></script>
<script src="loaddata.js"></script> <script src="loaddata.js"></script>
<script> <script>
var defaultModel = 'cheetah';
var initialGame = 'iii';
var initialModel = defaultModel;
var currentGame;
InitRW(); InitRW();
function function
startVehicleViewerIII() startVehicleViewerIII(model)
{ {
currentGame = 'iii';
DataDirPath = "iii/data"; DataDirPath = "iii/data";
ModelsDirPath = "iii/models"; ModelsDirPath = "iii/models";
TexturesDirPath = "iii/textures"; TexturesDirPath = "iii/textures";
loadCar = loadCarIII; loadCar = loadCarIII;
loadVehicleViewer("default.ide", function() { loadVehicleViewer("default.ide", function() {
SelectModel("cheetah"); if(parseInt(model)) {
SelectModelByID(model);
}
else {
SelectModel(model);
}
}); });
} }
function function
startVehicleViewerVC() startVehicleViewerVC(model)
{ {
currentGame = 'vc';
DataDirPath = "vc/data"; DataDirPath = "vc/data";
ModelsDirPath = "vc/models"; ModelsDirPath = "vc/models";
TexturesDirPath = "vc/textures"; TexturesDirPath = "vc/textures";
loadCar = loadCarVC; loadCar = loadCarVC;
loadVehicleViewer("default.ide", function() { loadVehicleViewer("default.ide", function() {
SelectModel("cheetah"); if(parseInt(model)) {
SelectModelByID(model);
}
else {
SelectModel(model);
}
}); });
} }
function function
startVehicleViewerSA() startVehicleViewerSA(model)
{ {
currentGame = 'sa';
DataDirPath = "sa/data"; DataDirPath = "sa/data";
ModelsDirPath = "sa/models"; ModelsDirPath = "sa/models";
TexturesDirPath = "sa/textures"; TexturesDirPath = "sa/textures";
loadCar = loadCarSA; loadCar = loadCarSA;
loadVehicleViewer("vehicles.ide", function() { loadVehicleViewer("vehicles.ide", function() {
SelectModel("cheetah"); if(parseInt(model)) {
SelectModelByID(model);
}
else {
SelectModel(model);
}
}); });
} }
startVehicleViewerIII(); var hash = window.location.hash;
if(hash.length !== '') {
hash = hash.substring(1).toLowerCase();
var hashParts = hash.split('/');
if(['iii', 'vc', 'sa'].includes(hashParts[0])) {
initialGame = hashParts[0];
if(hashParts.length > 1) {
initialModel = hashParts[1];
}
}
else {
// Invalid location hash, reset it
window.location.hash = '';
if(window.history) {
history.replaceState(null, null, ' ');
}
}
}
if(initialGame === 'iii') {
startVehicleViewerIII(initialModel);
}
else if(initialGame === 'vc') {
startVehicleViewerVC(initialModel);
}
else if(initialGame === 'sa') {
startVehicleViewerSA(initialModel);
}
</script> </script>
</html> </html>

View File

@ -68,6 +68,14 @@ SelectModel(model)
SetCarColors(CurrentModel.colors[0]); SetCarColors(CurrentModel.colors[0]);
loadCar(model + ".dff"); loadCar(model + ".dff");
window.location.hash = currentGame + '/' + model;
}
function
SelectModelByID(modelID) {
model = ModelInfos[modelID];
SelectModel(model.model);
} }
function function