public override Entity loadConfig(ConfuseSection sect) { LightEntity ent = new LightEntity(); ent.Type = types[0]; ent.X = sect.get_int("x", 0); ent.Y = sect.get_int("y", 0); return ent; }
public override Entity loadConfig(ConfuseSection sect) { ZoneEntity ent = new ZoneEntity(); ent.Type = types[0]; ent.Width = sect.get_int("width", 20); ent.Height = sect.get_int("height", 20); ent.X = sect.get_int("x", 0); ent.Y = sect.get_int("y", 0); ent.Angle = sect.get_int("angle", 0); return ent; }
public override Entity loadConfig(ConfuseSection sect) { ObjectEntity ent = new ObjectEntity(); // find type string type = sect.get_string("type", ""); foreach (EntityType ty in this.types) { if (ty.Name == type) { ent.Type = ty; break; } } if (ent.Type == null) return null; // load other deets ent.X = sect.get_int("x", 0); ent.Y = sect.get_int("y", 0); return ent; }
public abstract Entity loadConfig(ConfuseSection sect);
private ConfuseSection dosect(List<ConfuseToken> tokens) { ConfuseSection sect = new ConfuseSection(); string ident = null; bool eq = false; bool list = false; int subcnt = 0; List<ConfuseToken> sub = null; foreach (ConfuseToken t in tokens) { // In a subsection if (sub != null) { if (t.type == ConfuseTokenType.SECTSTART) { subcnt++; } else if (t.type == ConfuseTokenType.SECTEND) { subcnt--; if (subcnt == 0) { ConfuseSection subsect = dosect(sub); if (subsect == null) return null; subsect.name = ident; sect.subsections.Add(subsect); sub = null; ident = null; continue; } } sub.Add(t); continue; } // Indetifier if (ident == null && !eq && !list && t.type == ConfuseTokenType.IDENTIFIER) { ident = t.val; // Equals } else if (ident != null && !eq && !list && t.type == ConfuseTokenType.EQUALS) { eq = true; // Regular string, float, integer } else if (ident != null && eq && !list && t.type == ConfuseTokenType.STRING) { sect.values.Add(ident, t.val); ident = null; eq = false; } else if (ident != null && eq && !list && t.type == ConfuseTokenType.NUMBER) { if (t.val.Contains(".")) { sect.values.Add(ident, float.Parse(t.val)); } else { sect.values.Add(ident, int.Parse(t.val)); } ident = null; eq = false; // List start } else if (ident != null && eq && !list && t.type == ConfuseTokenType.SECTSTART) { sect.values.Add(ident, new List<object>()); list = true; // List comma (do nothing) } else if (ident != null && eq && list && t.type == ConfuseTokenType.COMMA) { // List string, number } else if (ident != null && eq && list && t.type == ConfuseTokenType.STRING) { List<object> obj = (List<object>)sect.values[ident]; obj.Add(t.val); } else if (ident != null && eq && list && t.type == ConfuseTokenType.NUMBER) { List<object> obj = (List<object>)sect.values[ident]; if (t.val.Contains(".")) { obj.Add(float.Parse(t.val)); } else { obj.Add(int.Parse(t.val)); } // List end } else if (ident != null && eq && list && t.type == ConfuseTokenType.SECTEND) { ident = null; eq = false; list = false; // Section start } else if (ident != null && !eq && !list && t.type == ConfuseTokenType.SECTSTART) { sub = new List<ConfuseToken>(); subcnt++; // Not sure } else { throw new Exception("Unexpected token " + t.type.ToString() + " while parsing " + file + ".\n\nident=" + ident + "\neq=" + eq + "\nlist=" + list); } } return sect; }
private ConfuseSection dosect(List <ConfuseToken> tokens) { ConfuseSection sect = new ConfuseSection(); string ident = null; bool eq = false; bool list = false; int subcnt = 0; List <ConfuseToken> sub = null; foreach (ConfuseToken t in tokens) { // In a subsection if (sub != null) { if (t.type == ConfuseTokenType.SECTSTART) { subcnt++; } else if (t.type == ConfuseTokenType.SECTEND) { subcnt--; if (subcnt == 0) { ConfuseSection subsect = dosect(sub); if (subsect == null) { return(null); } subsect.name = ident; sect.subsections.Add(subsect); sub = null; ident = null; continue; } } sub.Add(t); continue; } // Indetifier if (ident == null && !eq && !list && t.type == ConfuseTokenType.IDENTIFIER) { ident = t.val; // Equals } else if (ident != null && !eq && !list && t.type == ConfuseTokenType.EQUALS) { eq = true; // Regular string, float, integer } else if (ident != null && eq && !list && t.type == ConfuseTokenType.STRING) { sect.values.Add(ident, t.val); ident = null; eq = false; } else if (ident != null && eq && !list && t.type == ConfuseTokenType.NUMBER) { if (t.val.Contains(".")) { sect.values.Add(ident, float.Parse(t.val)); } else { sect.values.Add(ident, int.Parse(t.val)); } ident = null; eq = false; // List start } else if (ident != null && eq && !list && t.type == ConfuseTokenType.SECTSTART) { sect.values.Add(ident, new List <object>()); list = true; // List comma (do nothing) } else if (ident != null && eq && list && t.type == ConfuseTokenType.COMMA) { // List string, number } else if (ident != null && eq && list && t.type == ConfuseTokenType.STRING) { List <object> obj = (List <object>)sect.values[ident]; obj.Add(t.val); } else if (ident != null && eq && list && t.type == ConfuseTokenType.NUMBER) { List <object> obj = (List <object>)sect.values[ident]; if (t.val.Contains(".")) { obj.Add(float.Parse(t.val)); } else { obj.Add(int.Parse(t.val)); } // List end } else if (ident != null && eq && list && t.type == ConfuseTokenType.SECTEND) { ident = null; eq = false; list = false; // Section start } else if (ident != null && !eq && !list && t.type == ConfuseTokenType.SECTSTART) { sub = new List <ConfuseToken>(); subcnt++; // Not sure } else { throw new Exception("Unexpected token " + t.type.ToString() + " while parsing " + file + ".\n\nident=" + ident + "\neq=" + eq + "\nlist=" + list); } } return(sect); }