mdx-m3-viewer
Version:
A browser WebGL model viewer. Mainly focused on models of the games Warcraft 3 and Starcraft 2.
39 lines (31 loc) • 785 B
text/typescript
import BinaryStream from '../../../common/binarystream';
import { byteLengthUtf8 } from '../../../common/utf8';
/**
* A custom text trigger.
*/
export default class CustomTextTrigger {
text: string = '';
load(stream: BinaryStream) {
let textLength = stream.readInt32();
if (textLength) {
this.text = stream.read(textLength - 1);
stream.skip(1);
}
}
save(stream: BinaryStream) {
if (this.text.length) {
stream.writeInt32(byteLengthUtf8(this.text) + 1);
stream.write(this.text);
stream.skip(1);
} else {
stream.writeInt32(0);
}
}
getByteLength() {
let size = 4;
if (this.text.length) {
size += byteLengthUtf8(this.text) + 1;
}
return size;
}
}