/** * Created by jimsugg on 9/11/16. */ import { DmObject, DmMediaStateContainer, DmContentItem, DmMediaContentItem, DmHtmlContentItem, DmMediaStateState, DmMediaState, DmEventState, DmEvent, DmTransitionState, DmTransition, DmCondition, DmConditionState, DmUserVariable, DmZoneState, DmZone, DmSignState, DmSign, DmEventData } from './baDmInterfaces'; import { BaDmId, BaDmIdNone, VideoMode, ZoneType, ContentItemType, MediaStateContainerType, EventType, CompareOperator, TransitionType } from './baDmDataTypes'; import { MediaType, DmMediaObject, MediaObject } from './baDmMediaObject'; import { newBaDmId } from './utils'; // The exports in this module are intended for internal use only - i.e., by other modules // in the baDataModel library only. Most of the exports are classes, which will be // created by selectors and returned to clients. // External users should not be using the exports fro this namespace // Note: DmState is exported as an opaque type in main.ts export namespace DmInternal { export interface DmMap { [id: string]: T; // really '[id:BaDmId] : T;' -- but Typescript doesn't like that, even though BaDmId = string } export interface DmState { sign: DmSign, zones: { zonesById: DmMap, allZones: Array }, mediaStates: DmMap, events: DmMap, transitions: DmMap } export class MediaStateContainer implements DmMediaStateContainer { id: BaDmId; type: MediaStateContainerType; constructor(id: BaDmId, type: MediaStateContainerType = MediaStateContainerType.Zone) { this.id = id; this.type = type; } } class ContentItem implements DmContentItem { id: BaDmId; name: string; type: ContentItemType; constructor(name: string, type: ContentItemType, id: BaDmId = undefined) { if (id === undefined) { this.id = newBaDmId(); } else { this.id = id; } this.name = name; this.type = type; } } export class MediaContentItem extends ContentItem implements DmMediaContentItem { media: DmMediaObject; volume: number; constructor(name: string, path: string, mediaType: MediaType, volume = 0, id?: BaDmId) { super(name, ContentItemType.Media, id); this.media = new MediaObject(path, mediaType); this.volume = volume; } } export class HtmlContentItem extends ContentItem implements DmHtmlContentItem { siteId: BaDmId; enableExternalData: boolean enableMouseEvents: boolean; displayCursor: boolean; hwzOn: boolean; constructor(name: string, siteId: BaDmId, enableExternalData = false, enableMouseEvents = false, displayCursor = false, hwzOn = false, id?: BaDmId) { super(name, ContentItemType.Html, id); this.siteId = siteId; this.enableExternalData = enableExternalData; this.enableMouseEvents = enableMouseEvents; this.displayCursor = displayCursor; this.hwzOn = hwzOn; } } export class MediaState implements DmMediaState { id: BaDmId; name: string; container: DmMediaStateContainer; contentItem: DmContentItem; constructor(state: DmMediaStateState) { this.id = state.id; this.name = state.name; this.container = state.container; this.contentItem = state.contentItem; } } export class BsEvent implements DmEvent { id: BaDmId; name: string; type: EventType; mediaStateId: BaDmId; data: DmEventData; constructor(state: DmEventState) { this.id = state.id; this.name = state.name; this.type = state.type; this.mediaStateId = state.mediaStateId; this.data = state.data; } } export class Transition implements DmTransition { id: BaDmId; name: string; eventId: BaDmId; targetMediaStateId: BaDmId; type: TransitionType; condition?: DmCondition; get isDefaultTarget() : boolean { return this.condition === undefined; } constructor(state: DmTransitionState) { this.id = state.id; this.name = state.name; this.eventId = state.eventId; this.targetMediaStateId = state.targetMediaStateId; this.type = state.type; if (state.condition) { this.condition = new Condition(state.condition); } else { this.condition = undefined; } } } export class Condition implements DmCondition { id: BaDmId; name: string; userVariable : DmUserVariable; compareOperator : CompareOperator; compareValue : string; get isTrue() : boolean { // TODO return false; } constructor(state: DmConditionState) { this.id = state.id; this.name = state.name; this.userVariable = state.userVariable; this.compareOperator = state.compareOperator; this.compareValue = state.compareValue; } } export class Zone implements DmZone { id: BaDmId; name: string; type: ZoneType; nonInteractive: boolean; initialMediaStateId: BaDmId; get containerObject() : DmMediaStateContainer { return {id: this.id, type: MediaStateContainerType.Zone}; } constructor(state: DmZoneState) { this.id = state.id; this.name = state.name; this.type = state.type; this.nonInteractive = state.nonInteractive; this.initialMediaStateId = state.initialMediaStateId; } } export class Sign implements DmSign { id: BaDmId; name: string; videoMode: VideoMode; constructor(state: DmSignState) { this.id = state.id; this.name = state.name; this.videoMode = state.videoMode; } } }