public FDSSection GetLangDoc(string id, FileHandler Files, string lang = null, Dictionary <string, FDSSection> confs = null) { if (lang == null) { lang = CurrentLanguage; } if (confs == null) { confs = LanguageDocuments; } string idlow = id.ToLowerFast(); FDSSection doc; if (LanguageDocuments.TryGetValue(idlow, out doc)) { return(doc); } string path = "info/text/" + idlow + "_" + lang + ".fds"; if (Files.Exists(path)) { try { string dat = Files.ReadText(path); doc = new FDSSection(dat); LanguageDocuments[idlow] = doc; return(doc); } catch (Exception ex) { Utilities.CheckException(ex); SysConsole.Output("Reading language documents", ex); } } LanguageDocuments[idlow] = null; return(null); }
static void ListenLoop() { while (true) { ConsoleKeyInfo pressed = Console.ReadKey(true); if (pressed.Key == ConsoleKey.Enter || pressed.KeyChar == '\n' || pressed.KeyChar == '\r') { lock (holder) { CommandInput.Add(read); RecCommandInput.Add(read); if (RecCommandInput.Count > RecCommandInputMax) { RecCommandInput.RemoveAt(0); } CIPos = RecCommandInput.Count; } SysConsole.WriteLine(">" + read, "^r^7"); read = ""; pos = 0; } else if (pressed.Key == ConsoleKey.Backspace) { if (pos > 0) { read = read.Substring(0, pos - 1) + read.Substring(pos); pos--; } } else if (pressed.Key == ConsoleKey.Delete) { if (pos < read.Length) { read = read.Substring(0, pos) + read.Substring(pos + 1); } } else if (pressed.Key == ConsoleKey.LeftArrow) { if (pos > 0) { pos--; } } else if (pressed.Key == ConsoleKey.RightArrow) { if (pos < read.Length) { pos++; } } else if (pressed.Key == ConsoleKey.UpArrow) { if (CIPos > 0) { CIPos--; read = RecCommandInput.Count > CIPos ? RecCommandInput[CIPos] : ""; pos = read.Length; } } else if (pressed.Key == ConsoleKey.DownArrow) { if (CIPos < RecCommandInput.Count) { CIPos++; read = RecCommandInput.Count > CIPos ? RecCommandInput[CIPos] : ""; pos = read.Length; } } else if (pressed.Key == ConsoleKey.Home) { pos = 0; } else if (pressed.Key == ConsoleKey.End) { pos = read.Length; } else if ((pressed.Key >= ConsoleKey.F1 && pressed.Key <= ConsoleKey.F24) || pressed.Key == ConsoleKey.Escape) { // Do nothing } // TODO: Other special keys else { read = read.Substring(0, pos) + pressed.KeyChar + read.Substring(pos); pos++; } Update(); } }
public static void Populate(FileHandler files) { List <string> fileList = files.ListFiles("info/blocks/"); List <MaterialInfo> allmats = new List <MaterialInfo>((int)Material.NUM_DEFAULT); foreach (string file in fileList) { string f = file.ToLowerFast().After("/blocks/").Before(".blk"); if (TryGetFromNameOrNumber(allmats, f, out Material mat)) { continue; } mat = (Material)Enum.Parse(typeof(Material), f.ToUpperInvariant()); string data = files.ReadText("info/blocks/" + f + ".blk"); string[] split = data.Replace("\r", "").Split('\n'); MaterialInfo inf = new MaterialInfo((int)mat); for (int i = 0; i < split.Length; i++) { if (split[i].StartsWith("//") || !split[i].Contains("=")) { continue; } string[] opt = split[i].SplitFast('=', 1); switch (opt[0].ToLowerFast()) { case "name": inf.SetName(opt[1]); break; case "plant": inf.Plant = opt[1]; break; case "plantscale": inf.PlantScale = float.Parse(opt[1]); break; case "plantmultiplier": inf.PlantMultiplier = float.Parse(opt[1]); inf.InversePlantMultiplier = 1.0f / inf.PlantMultiplier; break; case "sound": inf.Sound = (MaterialSound)Enum.Parse(typeof(MaterialSound), opt[1].ToUpperInvariant()); break; case "solidity": inf.Solidity = (MaterialSolidity)Enum.Parse(typeof(MaterialSolidity), opt[1].ToUpperInvariant()); break; case "speedmod": inf.SpeedMod = double.Parse(opt[1]); break; case "frictionmod": inf.FrictionMod = double.Parse(opt[1]); break; case "lightdamage": inf.LightDamage = double.Parse(opt[1]); break; case "lightemitrange": inf.LightEmitRange = double.Parse(opt[1]); break; case "lightemit": inf.LightEmit = Location.FromString(opt[1]); break; case "fogalpha": inf.FogAlpha = double.Parse(opt[1]); break; case "opaque": inf.Opaque = opt[1].ToLowerFast() == "true"; break; case "spreads": inf.Spreads = opt[1].ToLowerFast() == "true"; break; case "rendersatall": inf.RendersAtAll = opt[1].ToLowerFast() == "true"; break; case "breaksfromothertools": inf.BreaksFromOtherTools = opt[1].ToLowerFast() == "true"; break; case "fogcolor": inf.FogColor = Location.FromString(opt[1]); break; case "canrenderagainstself": inf.CanRenderAgainstSelf = opt[1].ToLowerFast() == "true"; break; case "anyopaque": inf.AnyOpaque = opt[1].ToLowerFast() == "true"; break; case "spawntype": inf.SpawnType = (MaterialSpawnType)Enum.Parse(typeof(MaterialSpawnType), opt[1].ToUpperInvariant()); break; case "hardness": inf.Hardness = double.Parse(opt[1]); break; case "breaktime": inf.BreakTime = opt[1].ToLowerFast() == "infinity" ? double.PositiveInfinity : double.Parse(opt[1]); break; case "breaker": inf.Breaker = (MaterialBreaker)Enum.Parse(typeof(MaterialBreaker), opt[1].ToUpperInvariant()); break; case "breaksinto": inf.BreaksInto = (Material)Enum.Parse(typeof(Material), opt[1].ToUpperInvariant()); break; case "solidifiesinto": inf.SolidifiesInto = (Material)Enum.Parse(typeof(Material), opt[1].ToUpperInvariant()); break; case "bigspreadsas": inf.BigSpreadsAs = (Material)Enum.Parse(typeof(Material), opt[1].ToUpperInvariant()); break; case "texturebasic": for (int t = 0; t < (int)MaterialSide.COUNT; t++) { if (inf.Texture[t] == null) { inf.Texture[t] = new List <string>() { opt[1].ToLowerFast() }; } } break; case "texture_top": inf.Texture[(int)MaterialSide.TOP] = new List <string>() { opt[1].ToLowerFast() }; break; case "texture_bottom": inf.Texture[(int)MaterialSide.BOTTOM] = new List <string>() { opt[1].ToLowerFast() }; break; case "texture_xp": inf.Texture[(int)MaterialSide.XP] = new List <string>() { opt[1].ToLowerFast() }; break; case "texture_xm": inf.Texture[(int)MaterialSide.XM] = new List <string>() { opt[1].ToLowerFast() }; break; case "texture_yp": inf.Texture[(int)MaterialSide.YP] = new List <string>() { opt[1].ToLowerFast() }; break; case "texture_ym": inf.Texture[(int)MaterialSide.YM] = new List <string>() { opt[1].ToLowerFast() }; break; case "texturebasic_add": for (int t = 0; t < (int)MaterialSide.COUNT; t++) { inf.Texture[t].Add(opt[1].ToLowerFast()); } break; case "texture_top_add": inf.Texture[(int)MaterialSide.TOP].Add(opt[1].ToLowerFast()); break; case "texture_bottom_add": inf.Texture[(int)MaterialSide.BOTTOM].Add(opt[1].ToLowerFast()); break; case "texture_xp_add": inf.Texture[(int)MaterialSide.XP].Add(opt[1].ToLowerFast()); break; case "texture_xm_add": inf.Texture[(int)MaterialSide.XM].Add(opt[1].ToLowerFast()); break; case "texture_yp_add": inf.Texture[(int)MaterialSide.YP].Add(opt[1].ToLowerFast()); break; case "texture_ym_add": inf.Texture[(int)MaterialSide.YM].Add(opt[1].ToLowerFast()); break; default: SysConsole.Output(OutputType.WARNING, "Invalid material option: " + opt[0]); break; } } while (allmats.Count <= (int)mat) { MaterialInfo place = new MaterialInfo(allmats.Count); place.SetName("errno_" + allmats.Count); for (int t = 0; t < (int)MaterialSide.COUNT; t++) { place.Texture[t] = null; } allmats.Add(place); } allmats[(int)mat] = inf; } int c = 0; Dictionary <string, int> TexturesToIDs = new Dictionary <string, int>(); for (int i = 0; i < allmats.Count; i++) { for (int t = 0; t < (int)MaterialSide.COUNT; t++) { if (allmats[i].Texture[t] == null) { allmats[i].Texture[t] = new List <string>() { "white" }; SysConsole.Output(OutputType.WARNING, "Texture unset for " + ((Material)i) + " side " + ((MaterialSide)t)); } List <string> tex = allmats[i].Texture[t]; allmats[i].TID[t] = new int[tex.Count]; for (int x = 0; x < tex.Count; x++) { int res; if (TexturesToIDs.ContainsKey(tex[x])) { res = TexturesToIDs[tex[x]]; } else { TexturesToIDs[tex[x]] = c; res = c; c++; } (allmats[i].TID[t])[x] = res; } } } Textures = new string[c]; foreach (KeyValuePair <string, int> val in TexturesToIDs) { Textures[val.Value] = val.Key; } lock (ALL_MATS) { SysConsole.Output(OutputType.INIT, "Loaded: " + allmats.Count + " materials!"); ALL_MATS = allmats; } }
private void Subdivide() { // TODO: Save TCs and work with them properly. Shape p = new Shape(); Dictionary <Location, Point> ps = new Dictionary <Location, Point>(); for (int i = 0; i < BSSD.Verts[0].Count; i++) { Location t = new Location(BSSD.Verts[0][i]); if (!ps.ContainsKey(t)) { ps.Add(t, new Point(BSSD.Verts[0][i])); } } for (int i = 0; i < BSSD.Verts[0].Count; i += 3) { Point a = ps[new Location(BSSD.Verts[0][i])]; Point b = ps[new Location(BSSD.Verts[0][i + 1])]; Point c = ps[new Location(BSSD.Verts[0][i + 2])]; if (i + 3 < BSSD.Verts[0].Count) { Point a2 = ps[new Location(BSSD.Verts[0][i + 3])]; Point b2 = ps[new Location(BSSD.Verts[0][i + 4])]; Point c2 = ps[new Location(BSSD.Verts[0][i + 5])]; bool ac = a2 == a || a2 == b || a2 == c; bool bc = b2 == a || b2 == b || b2 == c; bool cc = c2 == a || c2 == b || c2 == c; if (ac && bc && cc) { SysConsole.Output(OutputType.WARNING, this + " has weird setup: " + a + ", " + b + ", " + c); p.AddFace(SubdivisionUtilities.CreateFaceF(p.AllEdges, a, b, c)); } else if (ac && cc) { p.AddFace(SubdivisionUtilities.CreateFaceF(p.AllEdges, a, b, b2, c)); i += 3; } else if (ac && bc) { p.AddFace(SubdivisionUtilities.CreateFaceF(p.AllEdges, a, b, c, c2)); i += 3; } else if (bc && cc) { p.AddFace(SubdivisionUtilities.CreateFaceF(p.AllEdges, a, b, c, a2)); i += 3; } else { p.AddFace(SubdivisionUtilities.CreateFaceF(p.AllEdges, a, b, c)); } } else { p.AddFace(SubdivisionUtilities.CreateFaceF(p.AllEdges, a, b, c)); } } CatmullClarkSubdivider cmcs = new CatmullClarkSubdivider(); Shape res = cmcs.Subdivide(p); List <Vector3> vecs = new List <Vector3>(); List <Vector3> norms = new List <Vector3>(); List <Vector3> Tcs = new List <Vector3>(); foreach (Face face in res.Faces) { for (int i = 0; i < 3; i++) { vecs.Add(face.AllPoints[i].Position); norms.Add(face.Normal); Tcs.Add(new Vector3(0, 0, BSSD.TCrds[0][0].Z)); } } BSSD = new BlockShapeSubDetails(); Vector3[] tcrds = Tcs.ToArray(); for (int i = 0; i < BSSD.Verts.Length; i++) { BSSD.Verts[i] = vecs; BSSD.Norms[i] = norms; BSSD.TCrds[i] = tcrds; } }
SingleAnimation LoadAnimation(string name, FileHandler Files) { if (Files.Exists("animations/" + name + ".anim")) { SingleAnimation created = new SingleAnimation() { Name = name }; string[] data = Files.ReadText("animations/" + name + ".anim").SplitFast('\n'); int entr = 0; for (int i = 0; i < data.Length; i++) { if (data[i].StartsWith("//")) { continue; } string type = data[i]; if (data.Length <= i + 1 || data[i + 1] != "{") { break; } List <KeyValuePair <string, string> > entries = new List <KeyValuePair <string, string> >(); for (i += 2; i < data.Length; i++) { if (data[i].Trim().StartsWith("//")) { continue; } if (data[i] == "}") { break; } string[] dat = data[i].SplitFast(':'); if (dat.Length <= 1) { SysConsole.Output(OutputType.WARNING, "Invalid key dat: " + dat[0]); } else { string key = dat[0].Trim(); string value = dat[1].Substring(0, dat[1].Length - 1).Trim(); entries.Add(new KeyValuePair <string, string>(key, value)); } } bool isgeneral = type == "general" && entr == 0; SingleAnimationNode node = null; if (!isgeneral) { node = new SingleAnimationNode() { Name = type.ToLowerFast() }; } foreach (KeyValuePair <string, string> entry in entries) { if (isgeneral) { if (entry.Key == "length") { created.Length = Utilities.StringToDouble(entry.Value); } else { SysConsole.Output(OutputType.WARNING, "Unknown GENERAL key: " + entry.Key); } } else { if (entry.Key == "positions") { string[] poses = entry.Value.SplitFast(' '); for (int x = 0; x < poses.Length; x++) { if (poses[x].Length > 0) { string[] posdata = poses[x].SplitFast('='); node.PosTimes.Add(Utilities.StringToDouble(posdata[0])); node.Positions.Add(new Location(Utilities.StringToFloat(posdata[1]), Utilities.StringToFloat(posdata[2]), Utilities.StringToFloat(posdata[3]))); } } } else if (entry.Key == "rotations") { string[] rots = entry.Value.SplitFast(' '); for (int x = 0; x < rots.Length; x++) { if (rots[x].Length > 0) { string[] posdata = rots[x].SplitFast('='); node.RotTimes.Add(Utilities.StringToDouble(posdata[0])); node.Rotations.Add(new Quaternion(Utilities.StringToFloat(posdata[1]), Utilities.StringToFloat(posdata[2]), Utilities.StringToFloat(posdata[3]), Utilities.StringToFloat(posdata[4]))); } } } else if (entry.Key == "parent") { node.ParentName = entry.Value.ToLowerFast(); } else if (entry.Key == "offset") { string[] posdata = entry.Value.SplitFast('='); node.Offset = new Location(Utilities.StringToFloat(posdata[0]), Utilities.StringToFloat(posdata[1]), Utilities.StringToFloat(posdata[2])); } else { SysConsole.Output(OutputType.WARNING, "Unknown NODE key: " + entry.Key); } } } if (!isgeneral) { created.Nodes.Add(node); created.node_map.Add(node.Name, node); } entr++; } foreach (SingleAnimationNode node in created.Nodes) { for (int i = 0; i < created.Nodes.Count; i++) { if (created.Nodes[i].Name == node.ParentName) { node.Parent = created.Nodes[i]; break; } } } created.Engine = this; return(created); } else { throw new Exception("Invalid animation file - file not found: animations/" + name + ".anim"); } }