1 /** 2 * Retrograde Engine 3 * 4 * Authors: 5 * Mike Bierlee, m.bierlee@lostmoment.com 6 * Copyright: 2014-2021 Mike Bierlee 7 * License: 8 * This software is licensed under the terms of the MIT license. 9 * The full terms of the license can be found in the LICENSE.txt file. 10 */ 11 12 module retrograde.font; 13 14 import retrograde.entity; 15 import retrograde.file; 16 17 import std.conv; 18 19 class Font { 20 private string _fontName; 21 private uint _pointSize; 22 private ulong _index; 23 24 public @property string fontName() { 25 return _fontName; 26 } 27 28 public @property uint pointSize() { 29 return _pointSize; 30 } 31 32 public @property ulong index() { 33 return _index; 34 } 35 36 this(string fontName, uint pointSize, ulong index) { 37 this._fontName = fontName; 38 this._pointSize = pointSize; 39 this._index = index; 40 } 41 } 42 43 class FontComponent : EntityComponent, Snapshotable { 44 mixin EntityComponentIdentity!"FontComponent"; 45 46 private Font _font; 47 48 public @property Font font() { 49 return _font; 50 } 51 52 this(Font font) { 53 this._font = font; 54 } 55 56 public string[string] getSnapshotData() { 57 string[string] snapshotData; 58 if (_font !is null) { 59 snapshotData = [ 60 "fontName": _font.fontName, 61 "pointSize": to!string(_font.pointSize), 62 "index": to!string(_font.index) 63 ]; 64 } 65 66 return snapshotData; 67 } 68 } 69 70 class FontComponentFactory { 71 public abstract FontComponent create(File fontFile, uint pointSize, ulong index = 0); 72 } 73 74 class TextComponent : EntityComponent, Snapshotable { 75 mixin EntityComponentIdentity!"TextComponent"; 76 77 private string _text; 78 private bool _isChanged; 79 80 public @property void text(string newText) { 81 this._text = newText; 82 this._isChanged = true; 83 } 84 85 public @property string text() { 86 return this._text; 87 } 88 89 public @property bool isChanged() { 90 return this._isChanged; 91 } 92 93 public void clearChanged() { 94 this._isChanged = false; 95 } 96 97 this(string text = "") { 98 this.text = text; 99 } 100 101 public string[string] getSnapshotData() { 102 return [ 103 "text": this._text 104 ]; 105 } 106 }