Skip to content

Commit

Permalink
v1.3.10 Bug corrections in the editor and in levels
Browse files Browse the repository at this point in the history
  • Loading branch information
adizanni committed Mar 15, 2022
1 parent 538ffe6 commit c181f43
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 13 deletions.
6 changes: 3 additions & 3 deletions dist/floor3d-card.js

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": "floor3d-card",
"version": "1.3.9",
"version": "1.3.10",
"description": "Lovelace floor3d-card",
"keywords": [
"home-assistant",
Expand Down
2 changes: 1 addition & 1 deletion src/const.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const CARD_VERSION = '1.3.9';
export const CARD_VERSION = '1.3.10';
11 changes: 9 additions & 2 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export class Floor3dCardEditor extends LitElement implements LovelaceCardEditor
}

public setConfig(config: Floor3dCardConfig): void {

console.log("Start editor config")

this._config = { ...config };

if (!config.entities) {
Expand Down Expand Up @@ -267,7 +270,9 @@ export class Floor3dCardEditor extends LitElement implements LovelaceCardEditor
this._fetchObjectList();
}

fireEvent(this, 'config-changed', { config: this._config });
console.log("End editor config")

//fireEvent(this, 'config-changed', { config: this._config });
}

get _show_warning(): boolean {
Expand Down Expand Up @@ -301,10 +306,10 @@ export class Floor3dCardEditor extends LitElement implements LovelaceCardEditor
}

protected shouldUpdate(): boolean {
console.log("Should Update start")
if (!this._initialized) {
this._initialize();
}

return true;
}

Expand Down Expand Up @@ -339,6 +344,8 @@ export class Floor3dCardEditor extends LitElement implements LovelaceCardEditor


private _config_changed(): void {

console.log("Config change start")
let preview_card: any = this._preview_card();

if (preview_card) {
Expand Down
30 changes: 26 additions & 4 deletions src/floor3d-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class Floor3dCard extends LitElement {
private _states?: string[];
private _color?: number[][];
private _raycasting: THREE.Object3D[];
private _raycastinglevels: THREE.Object3D[][];
private _initialmaterial?: THREE.Material[][];
private _clonedmaterial?: THREE.Material[][];
private _brightness?: number[];
Expand Down Expand Up @@ -187,7 +188,7 @@ export class Floor3dCard extends LitElement {
// https://lit-element.polymer-project.org/guide/properties#accessors-custom
public setConfig(config: Floor3dCardConfig): void {
// TODO Check for required fields and that they are of the proper format
console.log('Set Config');
console.log('floor3d-card: Set Config Start');

if (!config) {
throw new Error(localize('common.invalid_configuration'));
Expand All @@ -211,6 +212,8 @@ export class Floor3dCard extends LitElement {
i += 1;
});

console.log('floor3d-card: Set Config End');

if (this._config.show_warning) {
render(this._showWarning(localize('common.show_warning')), this._card);
return;
Expand Down Expand Up @@ -1111,7 +1114,7 @@ export class Floor3dCard extends LitElement {

this._bboxmodel.updateMatrixWorld(true);

this._content.innerText = 'Finished';
this._content.innerText = 'Finished with errors: check the console log';

if (this._config.show_axes) {
if (this._config.show_axes == 'yes') {
Expand Down Expand Up @@ -1202,12 +1205,15 @@ export class Floor3dCard extends LitElement {
private _initobjects(object: THREE.Object3D) {
console.log('Ïnit Objects, Levels and Raycasting');

let level = 0;
this._levels = [];
this._raycasting = [];
this._raycastinglevels = [];

console.log('Found level 0');

this._levels[0] = new THREE.Object3D();
this._raycastinglevels[0] = [];

const regex = /lvl(?<level>\d{3})/;

Expand All @@ -1227,14 +1233,17 @@ export class Floor3dCard extends LitElement {
if (!this._levels[Number(found.groups?.level)]) {
console.log('Found level ' + found.groups?.level);
this._levels[Number(found.groups?.level)] = new THREE.Object3D();
this._raycastinglevels[Number(found.groups?.level)] = [];
}

element.userData = { level: Number(found.groups?.level) };
element.name = element.name.slice(6);
this._levels[Number(found.groups?.level)].add(element);
level = Number(found.groups?.level);
} else {
element.userData = { level: 0 };
this._levels[0].add(element);
level = 0
}

element.receiveShadow = true;
Expand Down Expand Up @@ -1264,7 +1273,8 @@ export class Floor3dCard extends LitElement {
}
}

this._raycasting.push(element);
this._raycastinglevels[level].push(element);
//this._raycasting.push(element);

if (element instanceof THREE.Mesh) {
if (!Array.isArray((element as THREE.Mesh).material)) {
Expand Down Expand Up @@ -1294,9 +1304,13 @@ export class Floor3dCard extends LitElement {
});

this._displaylevels = [];
this._levels.forEach(() => {
this._levels.forEach((level, index) => {
if (level)
{
this._displaylevels.push(true);
this._raycasting = this._raycasting.concat(this._raycastinglevels[index]);
}
}
);
console.log('End Init Objects. Number of levels found: ' + this._levels.length);
}
Expand All @@ -1315,6 +1329,14 @@ export class Floor3dCard extends LitElement {
element.visible = this._displaylevels[i];
}
});

this._raycasting = [];

this._displaylevels.forEach((visible, index) => {
if (visible) {
this._raycasting = this._raycasting.concat(this._raycastinglevels[index]);
}
});
}

private _getLevelBar(): TemplateResult {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ export function createObjectGroupConfigArray(config): Floor3dCardConfig[] {
configArray.push(objectConfig);
} else {
if (entityConfig.entity != '') {
throw new Error('Object is empty for entity' + entityConfig.entity);
console.log('ERROR: Object is empty for entity' + entityConfig.entity);
}
}
} else {
if (entityConfig.entity != '') {
throw new Error('Object is empty for entity' + entityConfig.entity);
console.log('ERROR: Object is empty for entity' + entityConfig.entity);
}
}
}
Expand Down

0 comments on commit c181f43

Please sign in to comment.