public static string getLevelDisplayName(string levelFile) { ObjectCreator oc = new ObjectCreator("FileObject"); FileObject file = oc.Create(); string MissionInfoObject = ""; if (file.openForRead(levelFile)) { bool inInfoBlock = false; while (!file.isEOF()) { string line = file.readLine(); line = line.Trim(); if (line == "new ScriptObject(MissionInfo) {") { inInfoBlock = true; } else if (line == "new LevelInfo(theLevelInfo) {") { inInfoBlock = true; } else if (inInfoBlock && line == "};") { inInfoBlock = false; MissionInfoObject = MissionInfoObject + line; break; } if (inInfoBlock) { MissionInfoObject = MissionInfoObject + line + " "; } } file.close(); } MissionInfoObject = "%MissionInfoObject = " + MissionInfoObject + "; return %MissionInfoObject;"; MissionInfoObject = omni.console.Eval(MissionInfoObject, true); file.delete(); string name = ""; if (((SimObject)MissionInfoObject)["LevelName"] != "") { name = ((SimObject)MissionInfoObject)["LevelName"]; } else { name = omni.Util.fileBase(levelFile); } MissionInfoObject.delete(); return(name); }
public static string getLevelInfo(string missionFile) { clearLoadInfo(); FileObject file = new FileObject(); string levelInfoObject = ""; if (file.openForRead(missionFile)) { bool inInfoBlock = false; while (!file.isEOF()) { string line = file.readLine().Trim(); if (line.Equals("new ScriptObject(LevelInfo) {")) { inInfoBlock = true; } else if (line.Equals("new LevelInfo(theLevelInfo) {")) { inInfoBlock = true; } else if (inInfoBlock && line.Equals("};")) { inInfoBlock = false; levelInfoObject += line; break; } if (inInfoBlock) { levelInfoObject += line + " "; } } file.close(); } file.delete(); if (!string.IsNullOrEmpty(levelInfoObject)) { levelInfoObject = "%levelInfoObject = " + levelInfoObject; Global.eval(levelInfoObject); //todo really? return(levelInfoObject); } // Didn't find our LevelInfo return(null); }
/// <summary> /// Extract the map description from the .mis file /// </summary> /// <param name="mission"></param> public static void buildLoadInfo(string mission) { clearLoadInfo(); string infoObject = ""; FileObject file = new FileObject(true); if (file.openForRead(mission)) { bool inInfoBlock = false; while (!file.isEOF()) { string line = file.readLine().Trim(); if (line.Equals("new ScriptObject(MissionInfo) {")) { inInfoBlock = true; } else if (line.Equals("new LevelInfo(theLevelInfo) {")) { inInfoBlock = true; } else if (inInfoBlock && line.Equals("};")) { inInfoBlock = false; infoObject = infoObject + line; break; } if (inInfoBlock) { infoObject = infoObject + line + " "; } } file.close(); } else { Global.error("Level file " + mission + " not found."); } // Will create the object "MissionInfo" Global.eval(infoObject); file.delete(); }
private void Close(FileObject file) { if (file != null) { try { file.close(); } catch (System.IO.IOException ioe) { throw ioe; } catch (Exception e) { throw e; } } }