Skip to content

Commit

Permalink
Merge pull request #219 from VCityTeam/dev-unstable
Browse files Browse the repository at this point in the history
Editor
  • Loading branch information
valentinMachado authored Sep 10, 2021
2 parents 3635f2f + 96beda3 commit ca078ff
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 314 deletions.
336 changes: 45 additions & 291 deletions Doc/Devel/LocalGameTutorial.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ud-viz",
"version": "2.32.7",
"version": "2.32.8",
"description": "A collection of itowns plugins",
"main": "src",
"scripts": {
Expand Down
11 changes: 11 additions & 0 deletions src/Components/SystemUtils/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,15 @@ module.exports = {
throw new Error(e);
}
},

downloadImageOnDisk(url, filename) {
const imgResult = document.createElement('img');
imgResult.src = url;
const link = document.createElement('a');
link.href = imgResult.src;
link.download = filename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
},
};
4 changes: 4 additions & 0 deletions src/Game/Shared/GameObject/Components/Collider.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ const ColliderModule = class Collider {
body: this.body,
};
}

getUUID() {
return this.uuid;
}
};

ColliderModule.TYPE = 'Collider';
Expand Down
4 changes: 4 additions & 0 deletions src/Game/Shared/GameObject/Components/Render.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ const RenderModule = class Render {

return this.object3D;
}

getUUID() {
return this.uuid;
}
};

RenderModule.TYPE = 'Render';
Expand Down
4 changes: 4 additions & 0 deletions src/Game/Shared/GameObject/Components/WorldScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ const WorldScriptModule = class WorldScript {
return this.scripts;
}

getUUID() {
return this.uuid;
}

/**
* This component can be run on the server side
* @returns {Boolean}
Expand Down
32 changes: 32 additions & 0 deletions src/Game/Shared/GameObject/GameObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,15 @@ const GameObjectModule = class GameObject {
return obj;
}

getComponentByUUID(uuid) {
for (let key in this.components) {
const c = this.components[key];
if (c.getUUID() == uuid) return c;
}

return null;
}

/**
* Return a clone of this
* @returns {GameObject}
Expand Down Expand Up @@ -704,4 +713,27 @@ GameObjectModule.deepCopy = function (gameObject) {
return new GameObjectModule(cloneJSON);
};

GameObjectModule.findObject3D = function (uuid, obj, upSearch = true) {
let result;
if (upSearch) {
let current = obj;
while (current) {
if (current.userData.gameObjectUUID == uuid) {
result = current;
break;
}

current = current.parent;
}
} else {
obj.traverse(function (child) {
if (child.userData.gameObjectUUID == uuid) {
result = child;
}
});
}

return result;
};

module.exports = GameObjectModule;
57 changes: 38 additions & 19 deletions src/Templates/LocalGame/LocalGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,52 @@ import * as udviz from '../../index';
export class LocalGame {
constructor(fps) {
this.fps = fps || 30;

this.gameView = null;
}

getGameView() {
return this.gameView;
}

dispose() {
this.gameView.dispose();
}

start(world, configPath) {
start(world, configPath, options = {}) {
const fps = this.fps;

Components.SystemUtils.File.loadJSON(configPath).then(function (config) {
const assetsManager = new AssetsManager();
const _this = this;

assetsManager.loadFromConfig(config.assetsManager).then(function () {
const worldStateComputer = new Shared.WorldStateComputer(
assetsManager,
fps,
{ udviz: udviz, Shared: Shared }
);
return new Promise((resolve, reject) => {
Components.SystemUtils.File.loadJSON(configPath).then(function (config) {
const assetsManager = new AssetsManager();

worldStateComputer.load(world);
assetsManager.loadFromConfig(config.assetsManager).then(function () {
const worldStateComputer = new Shared.WorldStateComputer(
assetsManager,
fps,
{ udviz: udviz, Shared: Shared }
);

const gameView = new Views.GameView({
htmlParent: document.body,
assetsManager: assetsManager,
stateComputer: worldStateComputer,
config: config,
itownsControls: false,
});
worldStateComputer.load(world);

_this.gameView = new Views.GameView({
htmlParent: options.htmlParent || document.body,
assetsManager: assetsManager,
stateComputer: worldStateComputer,
config: config,
itownsControls: false,
});

//start gameview tick
gameView.onFirstState(worldStateComputer.computeCurrentState(), null);
//start gameview tick
_this.gameView.start(
worldStateComputer.computeCurrentState(),
options.avatarUUID
);

resolve();
});
});
});
}
Expand Down
4 changes: 3 additions & 1 deletion src/Views/GameView/GameView.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export class GameView extends View3D {

//stop update of gameobject
this.updateGameObject = true;
if (params.updateGameObject != undefined)
this.updateGameObject = params.updateGameObject;

//TODO place these attributes in a userData object
this.firstGameView = params.firstGameView || false; //first gameview of the application
Expand Down Expand Up @@ -85,7 +87,7 @@ export class GameView extends View3D {
* @param {WorldState} state first state of this view
* @param {uuid} avatarUUID uuid of the avatar GameObject
*/
onFirstState(state, avatarUUID) {
start(state, avatarUUID) {
//ref it
this.avatarUUID = avatarUUID;

Expand Down
6 changes: 4 additions & 2 deletions src/Views/View3D/View3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export class View3D {
el.style.bottom = bottom + 'px';
el.style.right = right + 'px';
});

this.onResize();
}

/**
Expand Down Expand Up @@ -376,8 +378,8 @@ export class View3D {
* Callback call on the resize event
*/
onResize() {
const w = window.innerWidth - this.rootHtml.offsetLeft;
const h = window.innerHeight - this.rootHtml.offsetTop;
const w = window.innerWidth - parseInt(this.rootWebGL.style.left);
const h = window.innerHeight - parseInt(this.rootWebGL.style.top);

//TODO remove this fonction
if (this.itownsView) this.itownsView.debugResize(w, h);
Expand Down

0 comments on commit ca078ff

Please sign in to comment.