mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 23:03:12 +02:00
Use preOp function for all common checks/updates
This commit is contained in:
parent
3563efb584
commit
92d3944044
1 changed files with 44 additions and 26 deletions
|
@ -4,6 +4,27 @@
|
||||||
this.lightID = null;
|
this.lightID = null;
|
||||||
this.sound = null;
|
this.sound = null;
|
||||||
|
|
||||||
|
var DEFAULT_USER_DATA = {
|
||||||
|
creatingLight: false,
|
||||||
|
lightID: null,
|
||||||
|
lightDefaultProperties: {
|
||||||
|
type: "Light",
|
||||||
|
position: { x: 0, y: 0, z: 0 },
|
||||||
|
dimensions: { x: 5, y: 5, z: 5 },
|
||||||
|
isSpotlight: false,
|
||||||
|
color: { red: 255, green: 48, blue: 0 },
|
||||||
|
diffuseColor: { red: 255, green: 255, blue: 255 },
|
||||||
|
ambientColor: { red: 255, green: 255, blue: 255 },
|
||||||
|
specularColor: { red: 0, green: 0, blue: 0 },
|
||||||
|
constantAttenuation: 1,
|
||||||
|
linearAttenuation: 0,
|
||||||
|
quadraticAttenuation: 0,
|
||||||
|
intensity: 10,
|
||||||
|
exponent: 0,
|
||||||
|
cutoff: 180, // in degrees
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function copyObject(object) {
|
function copyObject(object) {
|
||||||
return JSON.parse(JSON.stringify(object));
|
return JSON.parse(JSON.stringify(object));
|
||||||
}
|
}
|
||||||
|
@ -30,6 +51,19 @@
|
||||||
Entities.editEntity(entityID, { userData: JSON.stringify(userData) });
|
Entities.editEntity(entityID, { userData: JSON.stringify(userData) });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks whether the userData is well-formed and updates it if not
|
||||||
|
this.checkUserData = function() {
|
||||||
|
var userData = getUserData(this.entityID);
|
||||||
|
if (!userData) {
|
||||||
|
userData = DEFAULT_USER_DATA;
|
||||||
|
} else if (!userData.lightDefaultProperties) {
|
||||||
|
userData.lightDefaultProperties = DEFAULT_USER_DATA.lightDefaultProperties;
|
||||||
|
} else if (typeof userData.creatingLight == 'undefined') {
|
||||||
|
userData.creatingLight = DEFAULT_USER_DATA.creatingLight;
|
||||||
|
}
|
||||||
|
updateUserData(this.entityID, userData);
|
||||||
|
}
|
||||||
|
|
||||||
// Download sound if needed
|
// Download sound if needed
|
||||||
this.maybeDownloadSound = function() {
|
this.maybeDownloadSound = function() {
|
||||||
if (this.sound === null) {
|
if (this.sound === null) {
|
||||||
|
@ -76,28 +110,6 @@
|
||||||
|
|
||||||
this.updateLightID = function() {
|
this.updateLightID = function() {
|
||||||
var userData = getUserData(this.entityID);
|
var userData = getUserData(this.entityID);
|
||||||
if (!userData) {
|
|
||||||
userData = {
|
|
||||||
lightID: null,
|
|
||||||
lightDefaultProperties: {
|
|
||||||
type: "Light",
|
|
||||||
position: { x: 0, y: 0, z: 0 },
|
|
||||||
dimensions: { x: 5, y: 5, z: 5 },
|
|
||||||
isSpotlight: false,
|
|
||||||
color: { red: 255, green: 48, blue: 0 },
|
|
||||||
diffuseColor: { red: 255, green: 255, blue: 255 },
|
|
||||||
ambientColor: { red: 255, green: 255, blue: 255 },
|
|
||||||
specularColor: { red: 0, green: 0, blue: 0 },
|
|
||||||
constantAttenuation: 1,
|
|
||||||
linearAttenuation: 0,
|
|
||||||
quadraticAttenuation: 0,
|
|
||||||
intensity: 10,
|
|
||||||
exponent: 0,
|
|
||||||
cutoff: 180, // in degrees
|
|
||||||
}
|
|
||||||
};
|
|
||||||
updateUserData(this.entityID, userData);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find valid light
|
// Find valid light
|
||||||
if (doesEntityExistNow(this.lightID)) {
|
if (doesEntityExistNow(this.lightID)) {
|
||||||
|
@ -169,14 +181,20 @@
|
||||||
print("Relative properties of light entity saved.");
|
print("Relative properties of light entity saved.");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.preload = function(entityID) {
|
// This function should be called before any callback is executed
|
||||||
|
this.preOperation = function(entityID) {
|
||||||
this.entityID = entityID;
|
this.entityID = entityID;
|
||||||
this.maybeDownloadSound();
|
this.maybeDownloadSound();
|
||||||
|
|
||||||
|
this.checkUserData();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.preload = function(entityID) {
|
||||||
|
this.preOperation(entityID);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.clickReleaseOnEntity = function(entityID, mouseEvent) {
|
this.clickReleaseOnEntity = function(entityID, mouseEvent) {
|
||||||
this.entityID = entityID;
|
this.preOperation(entityID);
|
||||||
this.maybeDownloadSound();
|
|
||||||
|
|
||||||
if (mouseEvent.isLeftButton) {
|
if (mouseEvent.isLeftButton) {
|
||||||
this.updateLightID();
|
this.updateLightID();
|
||||||
|
|
Loading…
Reference in a new issue