From d05d9232baabbbe677af0fdfc7d7375f7d92ded3 Mon Sep 17 00:00:00 2001 From: Zhenwei Wu Date: Mon, 14 Jan 2019 15:48:40 +0800 Subject: [PATCH] Add new components. Fix se loading. Improve frame alignment. --- Editor/EditorForm.cs | 10 +++++-- Pat/Effects/ActorVariables.cs | 27 +++++++++++++++++++ Pat/Effects/BulletEffect.cs | 4 +-- Pat/Effects/CommonValue.cs | 49 +++++++++++++++++++++++++++++++++++ SoundEffect/Sound.cs | 4 +-- 5 files changed, 88 insertions(+), 6 deletions(-) diff --git a/Editor/EditorForm.cs b/Editor/EditorForm.cs index 625822d..9fa3e09 100644 --- a/Editor/EditorForm.cs +++ b/Editor/EditorForm.cs @@ -1022,10 +1022,16 @@ private void alignAllFramesToolStripMenuItem_Click(object sender, EventArgs e) { var seg = _Editor.CurrentSegment; var frame = _Editor.CurrentFrame; + var imageFrame = _Editor.Project.ImageList.GetImage(frame.ImageID); + var x = -frame.OriginX + imageFrame.Width * frame.ScaleX / 200; + var y = -frame.OriginY + imageFrame.Height * frame.ScaleY / 100; foreach (var f in seg.Frames) { - f.OriginX = frame.OriginX; - f.OriginY = frame.OriginY; + var image2 = _Editor.Project.ImageList.GetImage(f.ImageID); + var x2 = -f.OriginX + image2.Width * f.ScaleX / 200; + var y2 = -f.OriginY + image2.Height * f.ScaleY / 100; + f.OriginX -= x - x2; + f.OriginY -= y - y2; } } } diff --git a/Pat/Effects/ActorVariables.cs b/Pat/Effects/ActorVariables.cs index 4fe8294..f54c2bd 100644 --- a/Pat/Effects/ActorVariables.cs +++ b/Pat/Effects/ActorVariables.cs @@ -22,6 +22,7 @@ public override float Get(Simulation.Actor actor) { } + if (!actor.Variables.ContainsKey(Name)) return 0; var val = actor.Variables[Name]; if (val.Type == Simulation.ActorVariableType.Float) { @@ -36,6 +37,32 @@ public override Expression Generate(GenerationEnvironment env) } } + [Serializable] + public class ActorParentFloatVariableValue : Value + { + [XmlAttribute] + public string Name { get; set; } + + public override float Get(Simulation.Actor actor) + { + var parent = actor.Owner; + if (!parent.Variables.ContainsKey(Name)) return 0; + var val = parent.Variables[Name]; + if (val.Type == Simulation.ActorVariableType.Float) + { + return (float)val.Value; + } + return 0; + } + + public override Expression Generate(GenerationEnvironment env) + { + return ActorVariableHelper.GenerateGet( + ActorVariableHelper.GenerateGet("SYS_parent").MakeIndex("wr"), + Name); + } + } + [Serializable] public class ActorSetFloatVariableEffect : Effect { diff --git a/Pat/Effects/BulletEffect.cs b/Pat/Effects/BulletEffect.cs index 2df7e95..1b6e340 100644 --- a/Pat/Effects/BulletEffect.cs +++ b/Pat/Effects/BulletEffect.cs @@ -367,7 +367,7 @@ public override ILineObject Generate(GenerationEnvironment env) } if (cond != null) { - cond = new BiOpExpr(new CustomCodeExpr("ownerActor != null"), cond, BiOpExpr.Op.And); + cond = new BiOpExpr(new CustomCodeExpr("(!ownerActor)"), cond, BiOpExpr.Op.Or); ret.Add(new ControlBlock(ControlBlockType.If, cond, new ILineObject[] { BulletEffectHelper.GenerateEnd(ReleaseIfCheckFailed, SegmentCheckFailed), @@ -390,7 +390,7 @@ public override ILineObject Generate(GenerationEnvironment env) var setRotation = ThisExpr.Instance.MakeIndex("rz").Assign(ownerActor.MakeIndex("rz")).Statement(); ret.AddRange(new ILineObject[] { - new ControlBlock(ControlBlockType.If, "ownerActor != null", new ILineObject[] { + new ControlBlock(ControlBlockType.If, "(ownerActor)", new ILineObject[] { ThisExpr.Instance.MakeIndex("x").Assign(x).Statement(), ThisExpr.Instance.MakeIndex("y").Assign(y).Statement(), ThisExpr.Instance.MakeIndex("direction").Assign(dir).Statement(), diff --git a/Pat/Effects/CommonValue.cs b/Pat/Effects/CommonValue.cs index dbe740e..5bd5083 100644 --- a/Pat/Effects/CommonValue.cs +++ b/Pat/Effects/CommonValue.cs @@ -3,6 +3,7 @@ using GS_PatEditor.Editor.Exporters.CodeFormat; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -122,4 +123,52 @@ public override Expression Generate(GenerationEnvironment env) BiOpExpr.Op.Add); } } + + public enum UnaryFunctionValueType + { + Sin, + Cos, + } + + [Serializable] + public class UnaryFunctionValue : Value + { + [XmlElement] + [EditorChildNode("UnaryFunctionValue_Operand")] + public Value Operand; + + [XmlAttribute] + public UnaryFunctionValueType Function { get; set; } + + public UnaryFunctionValue() + { + } + + public override float Get(Simulation.Actor actor) + { + var v = Operand.Get(actor); + switch (Function) + { + case UnaryFunctionValueType.Sin: + return (float)Math.Sin(v); + case UnaryFunctionValueType.Cos: + return (float)Math.Cos(v); + default: + return 0; + } + } + + public override Expression Generate(GenerationEnvironment env) + { + var v = Operand.Generate(env); + string name; + switch (Function) + { + case UnaryFunctionValueType.Sin: name = "sin"; break; + case UnaryFunctionValueType.Cos: name = "cos"; break; + default: return new ConstNumberExpr(0); + } + return ThisExpr.Instance.MakeIndex(name).Call(v); + } + } } diff --git a/SoundEffect/Sound.cs b/SoundEffect/Sound.cs index d193363..6f33e0e 100644 --- a/SoundEffect/Sound.cs +++ b/SoundEffect/Sound.cs @@ -53,7 +53,7 @@ public Sound(SoundEngine engine, string filename) var align = br.ReadInt16(); if (align != 2) { - throw new IOException("invalid cv3 file"); + //throw new IOException("invalid cv3 file"); } var bits = br.ReadInt16(); if (bytesPerSecond != rate * bits / 8 * channels) @@ -63,7 +63,7 @@ public Sound(SoundEngine engine, string filename) var zero = br.ReadInt16(); if (zero != 0) { - throw new IOException("invalid cv3 file"); + //throw new IOException("invalid cv3 file"); } var len = br.ReadInt32();