public UI MakeUI(ComplexLS ui_script) { var sprite = Context.Content.MakeSprite(ui_script.Read <ComplexLS>("SPRITE")); float left = (float)ui_script.ReadToken <double>("LEFT"); float right = (float)ui_script.ReadToken <double>("RIGHT"); float top = (float)ui_script.ReadToken <double>("TOP"); float bottom = (float)ui_script.ReadToken <double>("BOTTOM"); var id = ui_script.Read <TokenLS <string> >("ID"); var ui = new UI(sprite, left, bottom, right, top); ui.Visible = ui_script.Read("HIDDEN") == null; List <IRender> uis = new List <IRender>(); foreach (var suic in ui_script.Read <ComplexLS>("CHILDREN").SubRunes) { if (suic.Word == "ELEMENT") { uis.Add(MakeUI(suic as ComplexLS)); } else if (suic.Word == "TEXT") { uis.Add(MakeText(suic as ComplexLS, right - left, 0.7f)); } } ui.Children = uis.ToArray(); if (id != null) { AssignUI(ui, id); } return(ui); }
public Level MakeLevel(ComplexLS level_script) { var bounds = level_script.Read <ComplexLS>("BOUNDS"); Vector2 min, max; min.X = (float)bounds.Read <TokenLS <double> >("LEFT"); min.Y = (float)bounds.Read <TokenLS <double> >("BOTTOM"); max.X = (float)bounds.Read <TokenLS <double> >("RIGHT"); max.Y = (float)bounds.Read <TokenLS <double> >("TOP"); var boundsbody = GameContext.PhysicsContext.CreateBody(new BodyDef() { FixedRotation = true }); var def = new PolygonDef(); float hrangey = (max.Y - min.Y) / 2; float hrangex = (max.X - min.X) / 2; def.SetAsBox(1, hrangey, new Vec2(min.X - 1, hrangey), 0); boundsbody.CreateShape(def); def.SetAsBox(1, hrangey, new Vec2(max.X + 1, hrangey), 0); boundsbody.CreateShape(def); def.SetAsBox(hrangex, 1, new Vec2(hrangex, min.Y - 1), 0); boundsbody.CreateShape(def); def.SetAsBox(hrangex, 1, new Vec2(hrangex, max.Y + 1), 0); boundsbody.CreateShape(def); var lvl = new Level(GameContext, null); lvl.Backdrop = MakeSprite(level_script.Read <ComplexLS>("BACKDROP")); foreach (var sprop in level_script.Read <ComplexLS>("PROPS").ReadAll <ComplexLS>("PROP")) { lvl.Props.SpawnProp(sprop); } return(lvl); }
public TextRender MakeText(ComplexLS text_script, float line_length, float font_size) { float x = (float)text_script.ReadToken <double>("X"); float y = (float)text_script.ReadToken <double>("Y"); var str = Context.Content.Text.CompileString( text_script.ReadToken <string>("LINE"), new Vector2(x, y), Context.Window.RenderWorker, line_length / font_size); str.CalcFontSize(font_size); return(str); }
public Sprite MakeSprite(ComplexLS sprite_script) { var depth = sprite_script.Read <TokenLS <Pixels> >("DEPTH"); var offset = sprite_script.Read <ComplexLS>("OFFSET"); var offset_x = offset != null?offset.Read <TokenLS <Pixels> >("X") : null; var offset_y = offset != null?offset.Read <TokenLS <Pixels> >("Y") : null; return(MakeSprite(sprite_script.Read <TokenLS <string> >("FILENAME"), depth != null ? depth.Value : 0, offset_x != null ? offset_x.Value : 0, offset_y != null ? offset_y.Value : 0)); }
public Prop SpawnProp(ComplexLS prop_script) { var template = MakePropTemplate(prop_script.Read <ComplexLS>("TEMPLATE")); float x = (float)prop_script.Read <TokenLS <double> >("X"); float y = (float)prop_script.Read <TokenLS <double> >("Y"); var z = prop_script.Read <TokenLS <double> >("Z"); bool makeplayer = prop_script.Read <LScript>("PLAYER") != null; var ontrigger = prop_script.Read <ComplexLS>("ON_TRIGGER"); var prop = SpawnProp(template, new Vec2(x, y), makeplayer, ontrigger != null); prop.OnInteract = prop_script.Read <ComplexLS>("ON_INTERACT"); prop.OnTrigger = ontrigger; prop.ZPosition = z != null ? (float)z.Value : 0.0f; return(prop); }
public Sprite MakeAnimation(ComplexLS script) { string filename = script.Read <TokenLS <string> >("FILENAME"); if (ActiveTextures.TryGetValue(filename, out Sprite texture)) { return(texture); } var seqs = new List <AnimationSequence>(); int handle, w, h; handle = Sprite.LoadHandle(filename, out w, out h); foreach (var scriptsequence in script.ReadAll <ComplexLS>("SEQUENCE")) { string name = scriptsequence.ReadToken <string>("NAME"); var dirs = AnimationDirections.None; foreach (var scriptdir in scriptsequence.Read <ComplexLS>("DIRECTIONS").SubRunes) { if (Enum.TryParse <AnimationDirections>(scriptdir.Word, true, out var fnddir)) { dirs |= fnddir; } } var locs = new List <(int X, int Y)>(); foreach (var scriptloc in scriptsequence.ReadAll <ComplexLS>("STEP")) { locs.Add((scriptloc.ReadToken <Pixels>("X"), scriptloc.ReadToken <Pixels>("Y"))); } var scriptoffset = scriptsequence.Read <ComplexLS>("OFFSET"); var offset_x = scriptoffset != null?scriptoffset.Read <TokenLS <Pixels> >("X") : null; var offset_y = scriptoffset != null?scriptoffset.Read <TokenLS <Pixels> >("Y") : null; seqs.Add(Sprite.MakeSteps(name, locs, (scriptsequence.ReadToken <Pixels>("WIDTH"), scriptsequence.ReadToken <Pixels>("HEIGHT")), (offset_x != null ?offset_x.Value : 0, offset_y != null ? offset_y.Value : 0), (w, h), dirs)); } var animation = new Animation(seqs.ToArray(), handle); return(ActiveTextures[filename] = animation); }
protected override object EvalEntry(ParseTree tree, params object[] paramlist) { string entry_name = Nodes.First(n => n.Token.Type == TokenType.WORD || n.Token.Type == TokenType.META).Token.Text; var payload = Nodes.Where(n => n.Token.Type == TokenType.Payload).FirstOrDefault(); if (payload == null) { return(new LScript(entry_name)); } LScript entry = null; var f_node = payload.Nodes.Where(n => n.Token.Type == TokenType.Token).FirstOrDefault(); if (f_node != null) { entry = f_node.Eval(tree, entry_name) as LScript; } else { f_node = payload.Nodes.First(n => n.Token.Type == TokenType.Group); var entries = f_node.Nodes.Where(n => n.Token.Type == TokenType.Entry) .Select(e => e.Eval(tree, paramlist) as LScript) .Where(e => e != null); entry = new ComplexLS(entry_name, entries.ToArray()); } var content_node = payload.Nodes.Where(n => n.Token.Type == TokenType.NEWNAME).FirstOrDefault(); if (content_node != null) { ContentReferences[content_node.Token.Text.Substring(content_node.Token.Text.IndexOf('$'))] = entry; } if (Nodes.Any(n => n.Token.Type == TokenType.META)) { var got = ApplyMeta?.Invoke(entry); return(got); } return(entry); }
public PropTemplate MakePropTemplate(ComplexLS template_script) { var sprtscript = template_script.Read <ComplexLS>("SPRITE"); Sprite sprt; if (sprtscript != null) { sprt = LevelContext.Context.Content.MakeSprite(template_script.Read <ComplexLS>("SPRITE")); } else { sprt = LevelContext.Context.Content.MakeAnimation(template_script.Read <ComplexLS>("ANIMATION")); } var name_s = template_script.Read <TokenLS <string> >("NAME"); string name = name_s != null ? name_s.Value : "UNKNOWN"; var desc_s = template_script.Read <TokenLS <string> >("DESC"); string desc = desc_s != null ? desc_s.Value : ""; float mass = (float)template_script.Read <TokenLS <double> >("MASS"); bool canmove = template_script.ReadAll <LScript>("CANMOVE").Any(); bool collides = template_script.ReadAll <LScript>("COLLIDES").Any(); float friction = 1.0f; var s_friction = template_script.Read <TokenLS <double> >("FRICTION"); if (s_friction != null) { friction = (float)s_friction.Value; } var width = template_script.Read <TokenLS <Pixels> >("WIDTH"); var height = template_script.Read <TokenLS <Pixels> >("HEIGHT"); if (width != null && height != null) { return(new PropTemplate(sprt, name, desc, mass, friction, collides, canmove, width.Value / Sprite.TileSize, height.Value / Sprite.TileSize)); } else { return(new PropTemplate(sprt, name, desc, mass, friction, collides, canmove)); } }
public void SpawnUI(ComplexLS ui_script) => Elements.Add(MakeUI(ui_script));