Moodlight update

This commit is contained in:
MyNameIsBatman 2021-09-14 02:56:25 -03:00
parent 50499e6d21
commit 88e304227a
5 changed files with 32 additions and 108 deletions

View File

@ -1,64 +1,8 @@
export class MoodlightFromServer export class MoodlightFromServer
{ {
private readonly _id: number = 0; constructor(public id: number,
private _type: number = 0; public bgOnly: boolean,
private _color: number = 0; public color: string,
private _intensity: number = 0; public brightness: number)
private _isParsed: boolean = false; {}
private _htmlColor: string = null;
constructor(k: number)
{
this._id = k;
}
public parsed(): void
{
this._isParsed = true;
}
public get id(): number
{
return this._id;
}
public get type(): number
{
return this._type;
}
public set type(k: number)
{
if(!this._isParsed) this._type = k;
}
public get color(): number
{
return this._color;
}
public set color(k: number)
{
if(!this._isParsed) this._color = k;
}
public get intensity(): number
{
return this._intensity;
}
public set intensity(k: number)
{
if(!this._isParsed) this._intensity = k;
}
public set htmlColor(color: string)
{
this._htmlColor = color;
}
public get htmlColor(): string
{
return this._htmlColor;
}
} }

View File

@ -35,33 +35,20 @@ export class RoomDimmerPresetsMessageParser implements IMessageParser
return true; return true;
} }
public parse(k: IMessageDataWrapper): boolean public parse(wrapper: IMessageDataWrapper): boolean
{ {
const totalPresets = k.readInt(); const totalPresets = wrapper.readInt();
this._selectedPresetId = k.readInt(); this._selectedPresetId = wrapper.readInt();
let _local_3 = 0; for(let i = 0; i < totalPresets; i++)
while(_local_3 < totalPresets)
{ {
const presetId = k.readInt(); const presetId = wrapper.readInt();
const isBackGroundOnly = k.readInt(); // Background only? 2: 1 const bgOnly = wrapper.readInt() === 2;
const color = k.readString(); const color = wrapper.readString();
const colorForSWF = parseInt(color.substr(1), 16); const brightness = wrapper.readInt();
const intensity = k.readInt();
const _local_9 = new MoodlightFromServer(presetId); this._presets.push(new MoodlightFromServer(presetId, bgOnly, color, brightness));
_local_9.type = isBackGroundOnly;
_local_9.color = colorForSWF;
_local_9.intensity = intensity;
_local_9.parsed();
_local_9.htmlColor = color;
this._presets.push(_local_9);
_local_3++;
} }
return true; return true;

View File

@ -31,10 +31,10 @@ export class RoomSessionDimmerPresetsEvent extends RoomSessionEvent
this._selectedPresetId = k; this._selectedPresetId = k;
} }
public storePreset(k: number, _arg_2: number, _arg_3: number, _arg_4: number): void public storePreset(id: number, bgOnly: boolean, color: string, brightness: number): void
{ {
const _local_5:RoomSessionDimmerPresetsEventPresetItem = new RoomSessionDimmerPresetsEventPresetItem(k, _arg_2, _arg_3, _arg_4); const _local_5:RoomSessionDimmerPresetsEventPresetItem = new RoomSessionDimmerPresetsEventPresetItem(id, bgOnly, color, brightness);
this._presets[(k - 1)] = _local_5; this._presets[(id - 1)] = _local_5;
} }
public getPreset(k: number):RoomSessionDimmerPresetsEventPresetItem public getPreset(k: number):RoomSessionDimmerPresetsEventPresetItem

View File

@ -1,16 +1,16 @@
export class RoomSessionDimmerPresetsEventPresetItem export class RoomSessionDimmerPresetsEventPresetItem
{ {
private _id: number; private _id: number;
private _type: number; private _bgOnly: boolean;
private _color: number; private _color: string;
private _light: number; private _brightness: number;
constructor(k: number, _arg_2: number, _arg_3: number, _arg_4: number) constructor(id: number, bgOnly: boolean, color: string, brightness: number)
{ {
this._id = k; this._id = id;
this._type = _arg_2; this._bgOnly = bgOnly;
this._color = _arg_3; this._color = color;
this._light = _arg_4; this._brightness = brightness;
} }
public get id(): number public get id(): number
@ -18,18 +18,18 @@
return this._id; return this._id;
} }
public get type(): number public get bgOnly(): boolean
{ {
return this._type; return this._bgOnly;
} }
public get color(): number public get color(): string
{ {
return this._color; return this._color;
} }
public get light(): number public get brightness(): number
{ {
return this._light; return this._brightness;
} }
} }

View File

@ -29,18 +29,11 @@ export class RoomDimmerPresetsHandler extends BaseHandler
event.selectedPresetId = parser.selectedPresetId; event.selectedPresetId = parser.selectedPresetId;
let i = 0; for(let i = 0; i < parser.presetCount; i++)
while(i < parser.presetCount)
{ {
const preset = parser.getPreset(i); const preset = parser.getPreset(i);
if(preset) if(preset) event.storePreset(preset.id, preset.bgOnly, preset.color, preset.brightness);
{
event.storePreset(preset.id, preset.type, preset.color, preset.intensity);
}
i++;
} }
this.listener && this.listener.events.dispatchEvent(event); this.listener && this.listener.events.dispatchEvent(event);