Browse Source

added hide.tools.CdbAccess

Nicolas Cannasse 11 months ago
parent
commit
a8d10e9fd5
2 changed files with 30 additions and 0 deletions
  1. 1 0
      hide.hxml
  2. 29 0
      hide/tools/CdbAccess.hx

+ 1 - 0
hide.hxml

@@ -14,6 +14,7 @@ common.hxml
 --macro include("hxd.earcut")
 --macro include("hide.view")
 --macro include("hide.prefab")
+--macro include("hide.tools")
 --macro include("hrt")
 -dce no
 -debug

+ 29 - 0
hide/tools/CdbAccess.hx

@@ -0,0 +1,29 @@
+package hide.tools;
+
+class CdbAccess<T,Kind> {
+
+	public var all(get,never) : cdb.Types.ArrayRead<T>;
+	var map : Map<String,T> = [];
+	var lines : Array<T>;
+
+	public function new( sheet : String ) {
+		lines = hide.Ide.inst.getCDBContent(sheet);
+		var s = hide.Ide.inst.database.getSheet(sheet);
+		if( s.idCol != null ) {
+			for( l in lines ) {
+				var id : String = Reflect.field(l, s.idCol.name);
+				if( id != null && id != "" )
+					map.set(id, l);
+			}
+		}
+	}
+
+	function get_all() : cdb.Types.ArrayRead<T> {
+		return lines;
+	}
+
+	public function get( kind : Kind ) : T {
+		return map.get(cast kind);
+	}
+
+}