|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const uid = require('../util/uid'); |
|
|
const xmlEscape = require('../util/xml-escape'); |
|
|
|
|
|
class Variable { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor (id, name, type, isCloud) { |
|
|
this.id = id || uid(); |
|
|
this.name = name; |
|
|
this.type = type; |
|
|
this.isCloud = isCloud; |
|
|
switch (this.type) { |
|
|
case Variable.SCALAR_TYPE: |
|
|
this.value = 0; |
|
|
break; |
|
|
case Variable.LIST_TYPE: |
|
|
this.value = []; |
|
|
break; |
|
|
case Variable.BROADCAST_MESSAGE_TYPE: |
|
|
this.value = this.name; |
|
|
break; |
|
|
default: |
|
|
console.warn(`Invalid variable type: ${this.type}`); |
|
|
} |
|
|
} |
|
|
|
|
|
toXML (isLocal) { |
|
|
isLocal = (isLocal === true); |
|
|
return `<variable type="${this.type}" id="${this.id}" islocal="${isLocal |
|
|
}" iscloud="${this.isCloud}">${xmlEscape(this.name)}</variable>`; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static get SCALAR_TYPE () { |
|
|
return ''; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static get LIST_TYPE () { |
|
|
return 'list'; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static get BROADCAST_MESSAGE_TYPE () { |
|
|
return 'broadcast_msg'; |
|
|
} |
|
|
} |
|
|
|
|
|
module.exports = Variable; |
|
|
|