Skip to content

Commit

Permalink
[HaCreator] refractoring prior mirrorFieldData commits
Browse files Browse the repository at this point in the history
  • Loading branch information
lastbattle committed Mar 13, 2022
1 parent 05245dc commit a650265
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
9 changes: 0 additions & 9 deletions HaCreator/GUI/InstanceEditor/MirrorFieldDataEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HaCreator.MapEditor;
using MapleLib.WzLib.WzStructure;
using HaCreator.MapEditor.Instance;
using HaCreator.MapEditor.UndoRedo;
using HaCreator.MapEditor.Instance.Misc;

namespace HaCreator.GUI.InstanceEditor
Expand Down
1 change: 1 addition & 0 deletions HaCreator/MapEditor/Instance/Misc/MirrorFieldData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace HaCreator.MapEditor.Instance.Misc
{
public enum MirrorFieldDataType
{
info,
mob,
user,
npc,
Expand Down
17 changes: 8 additions & 9 deletions HaCreator/Wz/MapLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -789,30 +789,29 @@ public static void LoadMisc(WzImage mapImage, Board mapBoard)
foreach (WzImageProperty prop_ in prop.WzProperties) // mob, user
{
MirrorFieldDataType targetObjectReflectionType = MirrorFieldDataType.NULL;
if (!Enum.TryParse(prop_.Name, out targetObjectReflectionType) || targetObjectReflectionType == MirrorFieldDataType.NULL)
if (!Enum.TryParse(prop_.Name, out targetObjectReflectionType))
{
string error = string.Format("New MirrorFieldData type object detected. prop name = '{0}", prop_.Name);
ErrorLogger.Log(ErrorLevel.MissingFeature, error);
}
if (targetObjectReflectionType == MirrorFieldDataType.NULL || targetObjectReflectionType == MirrorFieldDataType.info)
continue;

foreach (WzImageProperty prop_items in prop_.WzProperties)
{
WzVectorProperty lt = InfoTool.GetVector(prop_items["lt"]);
WzVectorProperty rb = InfoTool.GetVector(prop_items["rb"]);
System.Drawing.Rectangle rectBoundary = InfoTool.GetLtRbRectangle(prop_items);
WzVectorProperty offset = InfoTool.GetVector(prop_items["offset"]);
ushort gradient = (ushort)InfoTool.GetOptionalInt(prop_items["gradient"], 0);
ushort alpha = (ushort)InfoTool.GetOptionalInt(prop_items["alpha"], 0);
string objectForOverlay = InfoTool.GetOptionalString(prop_items["objectForOverlay"]);
bool reflection = InfoTool.GetOptionalBool(prop_items["reflection"]);
bool alphaTest = InfoTool.GetOptionalBool(prop_items["alphaTest"]);

int width = rb.X.Value - lt.X.Value;
int height = rb.Y.Value - lt.Y.Value;
Rectangle rectangle = new Rectangle(
lt.X.Value - offset.X.Value,
lt.Y.Value - offset.Y.Value,
width,
height);
rectBoundary.X - offset.X.Value,
rectBoundary.Y - offset.Y.Value,
rectBoundary.Width,
rectBoundary.Height);

ReflectionDrawableBoundary reflectionInfo = new ReflectionDrawableBoundary(gradient, alpha, objectForOverlay, reflection, alphaTest);

Expand Down
9 changes: 6 additions & 3 deletions HaCreator/Wz/MapSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,9 @@ public void SaveMirrorFieldData()
int i = 0;
foreach (MirrorFieldDataType dataType in Enum.GetValues(typeof(MirrorFieldDataType))) // initial holder data, only run once
{
if (dataType == MirrorFieldDataType.NULL)
if (dataType == MirrorFieldDataType.NULL || dataType == MirrorFieldDataType.info)
continue;

WzSubProperty holderProp = new WzSubProperty(); // <imgdir name="MirrorFieldData"><imgdir name="0">
holderProp.Name = i.ToString(); // "0"

Expand Down Expand Up @@ -898,8 +899,10 @@ public void SaveMirrorFieldData()
width,
height);*/

itemProp["lt"] = InfoTool.SetVector(rect.X, rect.Y);
itemProp["rb"] = InfoTool.SetVector(rect.X + rect.Width, rect.Y + rect.Height);
InfoTool.SetLtRbRectangle(itemProp,
new System.Drawing.Rectangle(rect.X, rect.Y, rect.Width, rect.Height) // convert Microsoft.Xna.Framework.Rectangle to System.Drawing.Rectangle
);

itemProp["offset"] = InfoTool.SetVector(mirrorFieldData.Offset.X, mirrorFieldData.Offset.Y);
itemProp["gradient"] = InfoTool.SetInt(mirrorFieldData.ReflectionInfo.Gradient);
itemProp["alpha"] = InfoTool.SetInt(mirrorFieldData.ReflectionInfo.Alpha);
Expand Down

0 comments on commit a650265

Please sign in to comment.