ソースを参照

split Ide/IdeData and some refactor

Nicolas Cannasse 1 年間 前
コミット
cb95d7601a
6 ファイル変更308 行追加285 行削除
  1. 6 274
      hide/Ide.hx
  2. 58 5
      hide/comp/cdb/DataFiles.hx
  3. 16 1
      hide/comp/cdb/Editor.hx
  4. 225 0
      hide/tools/IdeData.hx
  5. 1 3
      hide/view/CdbTable.hx
  6. 2 2
      hrt/prefab/Object3D.hx

+ 6 - 274
hide/Ide.hx

@@ -1,13 +1,9 @@
 package hide;
 
 @:expose
-class Ide {
+class Ide extends hide.tools.IdeData {
 
-	public var currentConfig(get,never) : Config;
-	public var projectDir(get,never) : String;
-	public var resourceDir(get,never) : String;
 	public var initializing(default,null) : Bool;
-	public var appPath(get, null): String;
 
 	public var mouseX : Int = 0;
 	public var mouseY : Int = 0;
@@ -15,30 +11,13 @@ class Ide {
 	public var isWindows(get, never) : Bool;
 	public var isFocused(get, never) : Bool;
 
-	public var database : cdb.Database = new cdb.Database();
 	public var shaderLoader : hide.tools.ShaderLoader;
-	public var fileWatcher : hide.tools.FileWatcher;
 	public var isCDB = false;
 	public var isDebugger = false;
 
 	public var gamePad(default,null) : hxd.Pad;
 	public var localStorage(get,never) : js.html.Storage;
 
-	var databaseFile : String;
-	var databaseDiff : String;
-	var pakFile : hxd.fmt.pak.FileSystem;
-	var originDataBase : cdb.Database;
-	var dbWatcher : hide.tools.FileWatcher.FileWatchEvent;
-
-	var config : {
-		global : Config,
-		project : Config,
-		user : Config,
-		current : Config,
-	};
-	public var ideConfig(get, never) : hide.Config.HideGlobalConfig;
-	public var projectConfig(get, never) : hide.Config.HideProjectConfig;
-
 	var window : nw.Window;
 	var saveMenu : nw.Menu;
 	var layout : golden.Layout;
@@ -62,6 +41,7 @@ class Ide {
 	static var firstInit = true;
 
 	function new() {
+		super();
 		initPad();
 		isCDB = Sys.getEnv("HIDE_START_CDB") == "1" || nw.App.manifest.name == "CDB";
 		isDebugger = Sys.getEnv("HIDE_DEBUG") == "1";
@@ -88,7 +68,7 @@ class Ide {
 		inst = this;
 		window = nw.Window.get();
 		var cwd = Sys.getCwd();
-		config = Config.loadForProject(cwd, cwd+"/res");
+		initConfig(cwd);
 		var current = ideConfig.currentProject;
 		if( StringTools.endsWith(cwd,"package.nw") && sys.FileSystem.exists(cwd.substr(0,-10)+"res") )
 			cwd = cwd.substr(0,-11);
@@ -136,8 +116,6 @@ class Ide {
 		if( config.global.get("hide") == null )
 			error("Failed to load defaultProps.json");
 
-		fileWatcher = new hide.tools.FileWatcher();
-
 		if( !sys.FileSystem.exists(current) || !sys.FileSystem.isDirectory(current) ) {
 			if( current != "" ) js.Browser.alert(current+" no longer exists");
 			current = cwd;
@@ -492,30 +470,6 @@ class Ide {
 		};
 	}
 
-	function get_ideConfig() return cast config.global.source.hide;
-	function get_projectConfig() return cast config.user.source.hide;
-	function get_currentConfig() return config.user;
-
-	function get_appPath() {
-		if( appPath != null )
-			return appPath;
-		var path = js.Node.process.argv[0].split("\\").join("/").split("/");
-		path.pop();
-		var hidePath = path.join("/");
-		if( !sys.FileSystem.exists(hidePath + "/package.json") ) {
-			var prevPath = new haxe.io.Path(hidePath).dir;
-			if( sys.FileSystem.exists(prevPath + "/hide.js") )
-				return appPath = prevPath;
-			// nwjs launch
-			var path = Sys.getCwd().split("\\").join("/");
-			if( sys.FileSystem.exists(path+"/hide.js") )
-				return appPath = path;
-			message("Hide application path was not found");
-			Sys.exit(0);
-		}
-		return appPath = hidePath;
-	}
-
 	public function setClipboard( text : String ) {
 		nw.Clipboard.get().set(text, Text);
 	}
@@ -548,15 +502,6 @@ class Ide {
 				Reflect.deleteField(v, f);
 	}
 
-	public function getPath( relPath : String ) {
-		if( relPath == null )
-			return null;
-		relPath = relPath.split("${HIDE}").join(appPath);
-		if( haxe.io.Path.isAbsolute(relPath) )
-			return relPath;
-		return resourceDir+"/"+relPath;
-	}
-
 	static var textureCacheKey = "TextureCache";
 
 	public function getHideResPath(basePath:String) {
@@ -587,63 +532,9 @@ class Ide {
 		return tex;
 	}
 
-	public function resolveCDBValue( path : String, key : Dynamic, obj : Dynamic ) : Dynamic {
-
-		// allow Array as key (first choice)
-		if( Std.isOfType(key,Array) ) {
-			for( v in (key:Array<Dynamic>) ) {
-				var value = resolveCDBValue(path, v, obj);
-				if( value != null ) return value;
-			}
-			return null;
-		}
-		path += "."+key;
-
-		var path = path.split(".");
-		var sheet = database.getSheet(path.shift());
-		if( sheet == null )
-			return null;
-		while( path.length > 0 && sheet != null ) {
-			var f = path.shift();
-			var value : Dynamic;
-			if( f.charCodeAt(f.length-1) == "]".code ) {
-				var parts = f.split("[");
-				f = parts[0];
-				value = Reflect.field(obj, f);
-				if( value != null )
-					value = value[Std.parseInt(parts[1])];
-			} else
- 				value = Reflect.field(obj, f);
-			if( value == null )
-				return null;
-			var current = sheet;
-			sheet = null;
-			for( c in current.columns ) {
-				if( c.name == f ) {
-					switch( c.type ) {
-					case TRef(name):
-						sheet = database.getSheet(name);
-						var ref = sheet.index.get(value);
-						if( ref == null )
-							return null;
-						value = ref.obj;
-					case TProperties, TList:
-						sheet = current.getSub(c);
-					default:
-					}
-					break;
-				}
-			}
-			obj = value;
-		}
-		for( f in path )
-			obj = Reflect.field(obj, f);
-		return obj;
-	}
-
 	var showErrors = true;
 	var errorWindow :Element = null;
-	public function error( e : Dynamic ) {
+	override function error( e : Dynamic ) {
 		if( showErrors && !js.Browser.window.confirm(e) )
 			showErrors = false;
 
@@ -690,25 +581,8 @@ class Ide {
 		haxe.Timer.delay(() -> e.remove(), 5000);
 	}
 
-	function get_projectDir() return ideConfig.currentProject.split("\\").join("/");
-	function get_resourceDir() return projectDir+"/res";
-
-	function setProject( dir : String ) {
-		fileWatcher.dispose();
-
-		if( dir != ideConfig.currentProject ) {
-			ideConfig.currentProject = dir;
-			ideConfig.recentProjects.remove(dir);
-			ideConfig.recentProjects.unshift(dir);
-			if( ideConfig.recentProjects.length > 10 ) ideConfig.recentProjects.pop();
-			config.global.save();
-		}
-		try {
-			config = Config.loadForProject(projectDir, resourceDir);
-		} catch( e : Dynamic ) {
-			js.Browser.alert(e);
-			return;
-		}
+	override function setProject( dir : String ) {
+		super.setProject(dir);
 
 		setProgress();
 		shaderLoader = new hide.tools.ShaderLoader();
@@ -727,23 +601,7 @@ class Ide {
 		for ( plugin in plugins )
 			loadPlugin(plugin, function() {});
 
-		databaseFile = config.project.get("cdb.databaseFile");
-		databaseDiff = config.user.get("cdb.databaseDiff");
-		var pak = config.project.get("pak.dataFile");
-		pakFile = null;
-		if( pak != null ) {
-			pakFile = new hxd.fmt.pak.FileSystem();
-			try {
-				pakFile.loadPak(getPath(pak));
-			} catch( e : Dynamic ) {
-				error(""+e);
-			}
-		}
 		loadDatabase();
-		dbWatcher = fileWatcher.register(databaseFile,function() {
-			loadDatabase(true);
-			hide.comp.cdb.Editor.refreshAll(true);
-		});
 
 		if( config.project.get("debug.displayErrors")  ) {
 			js.Browser.window.onerror = function(msg, url, line, col, error) {
@@ -865,119 +723,6 @@ class Ide {
 		js.Browser.location.reload();
 	}
 
-	public function fileExists( path : String ) {
-		if( sys.FileSystem.exists(getPath(path)) ) return true;
-		if( pakFile != null && pakFile.exists(path) ) return true;
-		return false;
-	}
-
-	public function getFile( path : String ) {
-		var fullPath = getPath(path);
-		try {
-			return sys.io.File.getBytes(fullPath);
-		} catch( e : Dynamic ) {
-			if( pakFile != null )
-				return pakFile.get(path).getBytes();
-			throw e;
-		}
-	}
-
-	public function getFileText( path : String ) {
-		var fullPath = getPath(path);
-		try {
-			return sys.io.File.getContent(fullPath);
-		} catch( e : Dynamic ) {
-			if( pakFile != null )
-				return pakFile.get(path).getText();
-			throw e;
-		}
-	}
-
-	var lastDBContent = null;
-	function loadDatabase( ?checkExists ) {
-		var exists = fileExists(databaseFile);
-		if( checkExists && !exists )
-			return; // cancel load
-		var loadedDatabase = new cdb.Database();
-		if( !exists ) {
-			database = loadedDatabase;
-			return;
-		}
-		try {
-			lastDBContent = getFileText(databaseFile);
-			loadedDatabase.load(lastDBContent);
-		} catch( e : Dynamic ) {
-			error(e);
-			return;
-		}
-		database = loadedDatabase;
-		if( databaseDiff != null ) {
-			originDataBase = new cdb.Database();
-			lastDBContent = getFileText(databaseFile);
-			originDataBase.load(lastDBContent);
-			if( fileExists(databaseDiff) ) {
-				var d = new cdb.DiffFile();
-				d.apply(database,parseJSON(getFileText(databaseDiff)),config.project.get("cdb.view"));
-			}
-		}
-	}
-
-	public function saveDatabase( ?forcePrefabs ) {
-		hide.comp.cdb.DataFiles.save(function() {
-			if( databaseDiff != null ) {
-				sys.io.File.saveContent(getPath(databaseDiff), toJSON(new cdb.DiffFile().make(originDataBase,database)));
-				fileWatcher.ignorePrevChange(dbWatcher);
-			} else {
-				if( !sys.FileSystem.exists(getPath(databaseFile)) && fileExists(databaseFile) ) {
-					// was loaded from pak, cancel changes
-					loadDatabase();
-					hide.comp.cdb.Editor.refreshAll();
-					return;
-				}
-				lastDBContent = database.save();
-				sys.io.File.saveContent(getPath(databaseFile), lastDBContent);
-				fileWatcher.ignorePrevChange(dbWatcher);
-			}
-		}, forcePrefabs);
-	}
-
-	public function createDBSheet( ?index : Int ) {
-		var value = ask("Sheet name");
-		if( value == "" || value == null ) return null;
-		var s = database.createSheet(value, index);
-		if( s == null ) {
-			error("Name already exists");
-			return null;
-		}
-		saveDatabase();
-		hide.comp.cdb.Editor.refreshAll();
-		return s;
-	}
-
-	public function makeRelative( path : String ) {
-		path = path.split("\\").join("/");
-		if( StringTools.startsWith(path.toLowerCase(), resourceDir.toLowerCase()+"/") )
-			return path.substr(resourceDir.length+1);
-
-		// is already a relative path
-		if( path.charCodeAt(0) != "/".code && path.charCodeAt(1) != ":".code )
-			return path;
-
-		var resParts = resourceDir.split("/");
-		var pathParts = path.split("/");
-		for( i in 0...resParts.length ) {
-			if( pathParts[i].toLowerCase() != resParts[i].toLowerCase() ) {
-				if( pathParts[i].charCodeAt(pathParts[i].length-1) == ":".code )
-					return path; // drive letter change
-				var newPath = pathParts.splice(i, pathParts.length - i);
-				for( k in 0...resParts.length - i )
-					newPath.unshift("..");
-				return newPath.join("/");
-			}
-		}
-		return path;
-	}
-
 	public function getUnCachedUrl( path : String ) {
 		return "file://" + getPath(path) + "?t=" + fileWatcher.getVersion(path);
 	}
@@ -1039,19 +784,6 @@ class Ide {
 		}).appendTo(window.window.document.body).click();
 	}
 
-	public function parseJSON( str : String ) : Dynamic {
-		// remove comments
-		str = ~/^[ \t]+\/\/[^\n]*/gm.replace(str, "");
-		return haxe.Json.parse(str);
-	}
-
-	public function toJSON( v : Dynamic ) {
-		var str = haxe.Json.stringify(v, "\t");
-		str = ~/,\n\t+"__id__": [0-9]+/g.replace(str, "");
-		str = ~/\t+"__id__": [0-9]+,\n/g.replace(str, "");
-		return str;
-	}
-
 	public function loadPrefab<T:hrt.prefab.Prefab>( file : String, ?cl : Class<T>, ?checkExists ) : T {
 		if( file == null )
 			return null;

+ 58 - 5
hide/comp/cdb/DataFiles.hx

@@ -22,7 +22,7 @@ class DataFiles {
 	static var skip : Int = 0;
 	static var watching : Map<String, Bool> = new Map();
 
-	#if editor
+	#if (editor || cdb_datafiles)
 	static var base(get,never) : cdb.Database;
 	static function get_base() return Ide.inst.database;
 	#else
@@ -35,7 +35,7 @@ class DataFiles {
 				loadSheet(sheet);
 	}
 
-	#if editor
+	#if (editor || cdb_datafiles)
 	static function onFileChanged() {
 		if( skip > 0 ) {
 			skip--;
@@ -68,7 +68,7 @@ class DataFiles {
 	#end
 
 	static dynamic function getPath(file:String) {
-		#if editor
+		#if (editor || cdb_datafiles)
 		return Ide.inst.getPath(file);
 		#else
 		return "res/"+file;
@@ -153,7 +153,7 @@ class DataFiles {
 				var dir = getPath(path);
 				if( !sys.FileSystem.isDirectory(dir) )
 					return;
-				#if editor
+				#if (editor || cdb_datafiles)
 				if( !watching.exists(path) ) {
 					watching.set(path, true);
 					Ide.inst.fileWatcher.register(path, onFileChanged, true);
@@ -210,7 +210,60 @@ class DataFiles {
 			browseRec(r, 0);
 	}
 
-	#if editor
+	#if (editor || cdb_datafiles)
+
+	public static function resolveCDBValue( path : String, key : Dynamic, obj : Dynamic ) : Dynamic {
+		// allow Array as key (first choice)
+		if( Std.isOfType(key,Array) ) {
+			for( v in (key:Array<Dynamic>) ) {
+				var value = resolveCDBValue(path, v, obj);
+				if( value != null ) return value;
+			}
+			return null;
+		}
+		path += "."+key;
+
+		var path = path.split(".");
+		var sheet = base.getSheet(path.shift());
+		if( sheet == null )
+			return null;
+		while( path.length > 0 && sheet != null ) {
+			var f = path.shift();
+			var value : Dynamic;
+			if( f.charCodeAt(f.length-1) == "]".code ) {
+				var parts = f.split("[");
+				f = parts[0];
+				value = Reflect.field(obj, f);
+				if( value != null )
+					value = value[Std.parseInt(parts[1])];
+			} else
+ 				value = Reflect.field(obj, f);
+			if( value == null )
+				return null;
+			var current = sheet;
+			sheet = null;
+			for( c in current.columns ) {
+				if( c.name == f ) {
+					switch( c.type ) {
+					case TRef(name):
+						sheet = base.getSheet(name);
+						var ref = sheet.index.get(value);
+						if( ref == null )
+							return null;
+						value = ref.obj;
+					case TProperties, TList:
+						sheet = current.getSub(c);
+					default:
+					}
+					break;
+				}
+			}
+			obj = value;
+		}
+		for( f in path )
+			obj = Reflect.field(obj, f);
+		return obj;
+	}
 
 	public static function save( ?onSaveBase, ?force, ?prevSheetNames : Map<String,String> ) {
 		var ide = Ide.inst;

+ 16 - 1
hide/comp/cdb/Editor.hx

@@ -1623,6 +1623,7 @@ class Editor extends Component {
 	}
 
 	public function newColumn( sheet : cdb.Sheet, ?index : Int, ?onDone : cdb.Data.Column -> Void, ?col ) {
+		#if js
 		var modal = new hide.comp.cdb.ModalColumnForm(this, sheet, col, element);
 		modal.setCallback(function() {
 			var c = modal.getColumn(col);
@@ -1652,6 +1653,7 @@ class Editor extends Component {
 					t.refresh();
 			modal.closeModal();
 		});
+		#end
 	}
 
 	public function editColumn( sheet : cdb.Sheet, col : cdb.Data.Column ) {
@@ -2173,6 +2175,19 @@ class Editor extends Component {
 		return menu;
 	}
 
+	public function createDBSheet( ?index : Int ) {
+		var value = ide.ask("Sheet name");
+		if( value == "" || value == null ) return null;
+		var s = ide.database.createSheet(value, index);
+		if( s == null ) {
+			ide.error("Name already exists");
+			return null;
+		}
+		ide.saveDatabase();
+		refreshAll();
+		return s;
+	}
+
 	public function popupSheet( withMacro = true, ?sheet : cdb.Sheet, ?onChange : Void -> Void ) {
 		if( view != null )
 			return;
@@ -2183,7 +2198,7 @@ class Editor extends Component {
 		var content : Array<ContextMenu.ContextMenuItem> = [];
 		if (withMacro) {
 			content = content.concat([
-				{ label : "Add Sheet", click : function() { beginChanges(); var db = ide.createDBSheet(index+1); endChanges(); if( db != null ) onChange(); } },
+				{ label : "Add Sheet", click : function() { beginChanges(); var db = createDBSheet(index+1); endChanges(); if( db != null ) onChange(); } },
 				{ label : "Move Left", click : function() { beginChanges(); base.moveSheet(sheet,-1); endChanges(); onChange(); } },
 				{ label : "Move Right", click : function() { beginChanges(); base.moveSheet(sheet,1); endChanges(); onChange(); } },
 				{ label : "Rename", click : function() {

+ 225 - 0
hide/tools/IdeData.hx

@@ -0,0 +1,225 @@
+package hide.tools;
+
+class IdeData {
+
+	public var currentConfig(get,never) : Config;
+	public var projectDir(get,never) : String;
+	public var resourceDir(get,never) : String;
+	public var appPath(get, null): String;
+	public var database : cdb.Database = new cdb.Database();
+	public var fileWatcher : hide.tools.FileWatcher;
+
+	var databaseFile : String;
+	var databaseDiff : String;
+	var originDataBase : cdb.Database;
+	var dbWatcher : hide.tools.FileWatcher.FileWatchEvent;
+
+	var pakFile : hxd.fmt.pak.FileSystem;
+
+	var config : {
+		global : Config,
+		project : Config,
+		user : Config,
+		current : Config,
+	};
+
+	public var ideConfig(get, never) : hide.Config.HideGlobalConfig;
+	public var projectConfig(get, never) : hide.Config.HideProjectConfig;
+
+	public function new() {
+	}
+
+	function get_ideConfig() return cast config.global.source.hide;
+	function get_projectConfig() return cast config.user.source.hide;
+	function get_currentConfig() return config.user;
+	function get_projectDir() return ideConfig.currentProject.split("\\").join("/");
+	function get_resourceDir() return projectDir+"/res";
+
+	function initConfig( cwd : String ) {
+		config = Config.loadForProject(cwd, cwd+"/res");
+		fileWatcher = new hide.tools.FileWatcher();
+	}
+
+	function setProject( dir : String ) {
+		fileWatcher.dispose();
+		dbWatcher = null;
+		if( dir != ideConfig.currentProject ) {
+			ideConfig.currentProject = dir;
+			ideConfig.recentProjects.remove(dir);
+			ideConfig.recentProjects.unshift(dir);
+			if( ideConfig.recentProjects.length > 10 ) ideConfig.recentProjects.pop();
+			config.global.save();
+		}
+		config = Config.loadForProject(projectDir, resourceDir);
+		databaseFile = config.project.get("cdb.databaseFile");
+		databaseDiff = config.user.get("cdb.databaseDiff");
+
+		var pak = config.project.get("pak.dataFile");
+		pakFile = null;
+		if( pak != null ) {
+			pakFile = new hxd.fmt.pak.FileSystem();
+			try {
+				pakFile.loadPak(getPath(pak));
+			} catch( e : Dynamic ) {
+				error(""+e);
+			}
+		}
+	}
+
+	public function error( e : Dynamic ) {
+		throw e;
+	}
+
+	function fatalError( msg : String ) {
+		error(msg);
+		Sys.exit(0);
+	}
+
+	function get_appPath() {
+		if( appPath != null )
+			return appPath;
+		var path = js.Node.process.argv[0].split("\\").join("/").split("/");
+		path.pop();
+		var hidePath = path.join("/");
+		if( !sys.FileSystem.exists(hidePath + "/package.json") ) {
+			var prevPath = new haxe.io.Path(hidePath).dir;
+			if( sys.FileSystem.exists(prevPath + "/hide.js") )
+				return appPath = prevPath;
+			// nwjs launch
+			var path = Sys.getCwd().split("\\").join("/");
+			if( sys.FileSystem.exists(path+"/hide.js") )
+				return appPath = path;
+			fatalError("Hide application path was not found");
+		}
+		return appPath = hidePath;
+	}
+
+	public function makeRelative( path : String ) {
+		path = path.split("\\").join("/");
+		if( StringTools.startsWith(path.toLowerCase(), resourceDir.toLowerCase()+"/") )
+			return path.substr(resourceDir.length+1);
+
+		// is already a relative path
+		if( path.charCodeAt(0) != "/".code && path.charCodeAt(1) != ":".code )
+			return path;
+
+		var resParts = resourceDir.split("/");
+		var pathParts = path.split("/");
+		for( i in 0...resParts.length ) {
+			if( pathParts[i].toLowerCase() != resParts[i].toLowerCase() ) {
+				if( pathParts[i].charCodeAt(pathParts[i].length-1) == ":".code )
+					return path; // drive letter change
+				var newPath = pathParts.splice(i, pathParts.length - i);
+				for( k in 0...resParts.length - i )
+					newPath.unshift("..");
+				return newPath.join("/");
+			}
+		}
+		return path;
+	}
+
+	public function getPath( relPath : String ) {
+		if( relPath == null )
+			return null;
+		relPath = relPath.split("${HIDE}").join(appPath);
+		if( haxe.io.Path.isAbsolute(relPath) )
+			return relPath;
+		return resourceDir+"/"+relPath;
+	}
+
+	var lastDBContent = null;
+	function loadDatabase( ?checkExists ) {
+		var exists = fileExists(databaseFile);
+		if( checkExists && !exists )
+			return; // cancel load
+		var loadedDatabase = new cdb.Database();
+		if( !exists ) {
+			database = loadedDatabase;
+			return;
+		}
+		try {
+			lastDBContent = getFileText(databaseFile);
+			loadedDatabase.load(lastDBContent);
+		} catch( e : Dynamic ) {
+			error(e);
+			return;
+		}
+		database = loadedDatabase;
+		if( databaseDiff != null ) {
+			originDataBase = new cdb.Database();
+			lastDBContent = getFileText(databaseFile);
+			originDataBase.load(lastDBContent);
+			if( fileExists(databaseDiff) ) {
+				var d = new cdb.DiffFile();
+				d.apply(database,parseJSON(getFileText(databaseDiff)),config.project.get("cdb.view"));
+			}
+		}
+		if( dbWatcher == null )
+			dbWatcher = fileWatcher.register(databaseFile,function() {
+				loadDatabase(true);
+				hide.comp.cdb.Editor.refreshAll(true);
+			});
+	}
+
+	public function saveDatabase( ?forcePrefabs ) {
+		hide.comp.cdb.DataFiles.save(function() {
+			if( databaseDiff != null ) {
+				sys.io.File.saveContent(getPath(databaseDiff), toJSON(new cdb.DiffFile().make(originDataBase,database)));
+				fileWatcher.ignorePrevChange(dbWatcher);
+			} else {
+				if( !sys.FileSystem.exists(getPath(databaseFile)) && fileExists(databaseFile) ) {
+					// was loaded from pak, cancel changes
+					loadDatabase();
+					hide.comp.cdb.Editor.refreshAll();
+					return;
+				}
+				lastDBContent = database.save();
+				sys.io.File.saveContent(getPath(databaseFile), lastDBContent);
+				fileWatcher.ignorePrevChange(dbWatcher);
+			}
+		}, forcePrefabs);
+	}
+
+	public function fileExists( path : String ) {
+		if( sys.FileSystem.exists(getPath(path)) ) return true;
+		if( pakFile != null && pakFile.exists(path) ) return true;
+		return false;
+	}
+
+	public function getFile( path : String ) {
+		var fullPath = getPath(path);
+		try {
+			return sys.io.File.getBytes(fullPath);
+		} catch( e : Dynamic ) {
+			if( pakFile != null )
+				return pakFile.get(path).getBytes();
+			throw e;
+		}
+	}
+
+	public function getFileText( path : String ) {
+		var fullPath = getPath(path);
+		try {
+			return sys.io.File.getContent(fullPath);
+		} catch( e : Dynamic ) {
+			if( pakFile != null )
+				return pakFile.get(path).getText();
+			throw e;
+		}
+	}
+
+	public function parseJSON( str : String ) : Dynamic {
+		// remove comments
+		str = ~/^[ \t]+\/\/[^\n]*/gm.replace(str, "");
+		return haxe.Json.parse(str);
+	}
+
+	public function toJSON( v : Dynamic ) {
+		var str = haxe.Json.stringify(v, "\t");
+		str = ~/,\n\t+"__id__": [0-9]+/g.replace(str, "");
+		str = ~/\t+"__id__": [0-9]+,\n/g.replace(str, "");
+		return str;
+	}
+
+
+}

+ 1 - 3
hide/view/CdbTable.hx

@@ -206,13 +206,11 @@ class CdbTable extends hide.ui.View<{}> {
 		var sheets = getSheets();
 		if( sheets.length == 0 ) {
 			element.html("No CDB sheet created, <a href='#'>create one</a>");
-			#if js
 			element.find("a").click(function(_) {
-				var sheet = ide.createDBSheet();
+				var sheet = editor.createDBSheet();
 				if( sheet == null ) return;
 				rebuild();
 			});
-			#end
 			return;
 		}
 		element.addClass("cdb-view");

+ 2 - 2
hrt/prefab/Object3D.hx

@@ -169,7 +169,7 @@ class Object3D extends Prefab {
 				if( ranges != null ) {
 					for( key in Reflect.fields(ranges) ) {
 						var color = Std.parseInt(Reflect.field(ranges,key));
-						var value : Dynamic = ide.resolveCDBValue(sheet,key, props);
+						var value : Dynamic = hide.comp.cdb.DataFiles.resolveCDBValue(sheet,key, props);
 						if( value != null ) {
 							var mesh = new h3d.scene.Mesh(hrt.prefab.l3d.Spray.makePrimCircle(128, 0.99), ctx.local3d);
 							mesh.name = "$UI.RANGE";
@@ -189,7 +189,7 @@ class Object3D extends Prefab {
 				var huds : Dynamic = shared.scene.config.get("sceneeditor.huds");
 				var icon = Reflect.field(huds, sheet);
 				if( icon != null ) {
-					var t : Dynamic = ide.resolveCDBValue(sheet,icon, props);
+					var t : Dynamic = hide.comp.cdb.DataFiles.resolveCDBValue(sheet,icon, props);
 					if( t != null && (t.file != null || Std.isOfType(t,String)) ) {
 						var obj = Std.downcast(ctx.local2d, h2d.ObjectFollower);
 						if( obj == null || obj.follow != ctx.local3d ) {