Merge pull request #6 from nkrapivin/master
Implement Physics, makerSettings, and got rid of all TODOs
This commit is contained in:
commit
a107b80c1d
1 changed files with 68 additions and 12 deletions
|
@ -11,8 +11,9 @@ using UndertaleModLib.Models;
|
|||
using UndertaleModLib.Util;
|
||||
using UndertaleModLib.Decompiler;
|
||||
|
||||
string GameName = Data.GeneralInfo.Name.ToString().Replace(@"""",""); //Name == "Project" -> Project
|
||||
int progress = 0;
|
||||
string projFolder = GetFolder(FilePath) + "Export_Project" + Path.DirectorySeparatorChar;
|
||||
string projFolder = GetFolder(FilePath) + GameName + ".gmx" + Path.DirectorySeparatorChar;
|
||||
TextureWorker worker = new TextureWorker();
|
||||
ThreadLocal<DecompileContext> DECOMPILE_CONTEXT = new ThreadLocal<DecompileContext>(() => new DecompileContext(Data, false));
|
||||
string gmxDeclaration = "This Document is generated by GameMaker, if you edit it by hand then you do so at your own risk!";
|
||||
|
@ -213,10 +214,36 @@ void ExportGameObject(UndertaleGameObject gameObject)
|
|||
new XElement("persistent", BoolToString(gameObject.Persistent)),
|
||||
new XElement("parentName", gameObject.ParentId is null ? "<undefined>" : gameObject.ParentId.Name.Content),
|
||||
new XElement("maskName", gameObject.TextureMaskId is null ? "<undefined>" : gameObject.TextureMaskId.Name.Content),
|
||||
new XElement("events")
|
||||
new XElement("events"),
|
||||
|
||||
//Physics
|
||||
new XElement("PhysicsObject", BoolToString(gameObject.UsesPhysics)),
|
||||
new XElement("PhysicsObjectSensor", BoolToString(gameObject.IsSensor)),
|
||||
new XElement("PhysicsObjectShape", (uint)gameObject.CollisionShape),
|
||||
new XElement("PhysicsObjectDensity", gameObject.Density),
|
||||
new XElement("PhysicsObjectRestitution", gameObject.Restitution),
|
||||
new XElement("PhysicsObjectGroup", gameObject.Group),
|
||||
new XElement("PhysicsObjectLinearDamping", gameObject.LinearDamping),
|
||||
new XElement("PhysicsObjectAngularDamping", gameObject.AngularDamping),
|
||||
new XElement("PhysicsObjectFriction", gameObject.Friction),
|
||||
new XElement("PhysicsObjectAwake", BoolToString(gameObject.Awake)),
|
||||
new XElement("PhysicsObjectKinematic", BoolToString(gameObject.Kinematic)),
|
||||
new XElement("PhysicsShapePoints")
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
|
||||
// Loop through PhysicsShapePoints List
|
||||
for (int _point = 0; _point < gameObject.PhysicsVertices.Count; _point++)
|
||||
{
|
||||
var _x = gameObject.PhysicsVertices[_point].X;
|
||||
var _y = gameObject.PhysicsVertices[_point].Y;
|
||||
|
||||
var physicsPointsNode = gmx.Element("object").Element("PhysicsShapePoints");
|
||||
physicsPointsNode.Add(new XElement("points",_x.ToString() + "," + _y.ToString()));
|
||||
}
|
||||
|
||||
// Traversing the event type list
|
||||
for (int i = 0; i < gameObject.Events.Count; i++)
|
||||
{
|
||||
|
@ -273,12 +300,11 @@ void ExportGameObject(UndertaleGameObject gameObject)
|
|||
eventNode.Add(actionNode);
|
||||
eventsNode.Add(eventNode);
|
||||
|
||||
// TODO:Physics
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File.WriteAllText(projFolder + "/objects/" + gameObject.Name.Content + ".object.gmx", gmx.ToString());
|
||||
File.WriteAllText(projFolder + "/objects/" + gameObject.Name.Content + ".object.gmx", gmx.ToString() + "\n");
|
||||
}
|
||||
|
||||
// --------------- Export Room ---------------
|
||||
|
@ -307,10 +333,25 @@ void ExportRoom(UndertaleRoom room)
|
|||
new XElement("code", room.CreationCodeId != null ? Decompiler.Decompile(room.CreationCodeId, DECOMPILE_CONTEXT.Value) : ""),
|
||||
new XElement("enableViews", BoolToString(room.Flags.HasFlag(UndertaleRoom.RoomEntryFlags.EnableViews))),
|
||||
new XElement("clearViewBackground", BoolToString(room.Flags.HasFlag(UndertaleRoom.RoomEntryFlags.ShowColor))),
|
||||
new XElement("clearDisplayBuffer", BoolToString(room.Flags.HasFlag(UndertaleRoom.RoomEntryFlags.ClearDisplayBuffer)))
|
||||
new XElement("clearDisplayBuffer", BoolToString(room.Flags.HasFlag(UndertaleRoom.RoomEntryFlags.ClearDisplayBuffer))),
|
||||
new XElement("makerSettings",
|
||||
new XElement("isSet", 0),
|
||||
new XElement("w", 0),
|
||||
new XElement("h", 0),
|
||||
new XElement("showGrid", 0),
|
||||
new XElement("showObjects", 0),
|
||||
new XElement("showTiles", 0),
|
||||
new XElement("showBackgrounds", 0),
|
||||
new XElement("showForegrounds", 0),
|
||||
new XElement("showViews", 0),
|
||||
new XElement("deleteUnderlyingObj", 0),
|
||||
new XElement("deleteUnderlyingTiles", 0),
|
||||
new XElement("page", 0),
|
||||
new XElement("xoffset", 0),
|
||||
new XElement("yoffset", 0)
|
||||
)
|
||||
)
|
||||
);
|
||||
// TODO:MakerSettings
|
||||
|
||||
// Room backgrounds
|
||||
var backgroundsNode = new XElement("backgrounds");
|
||||
|
@ -399,9 +440,20 @@ void ExportRoom(UndertaleRoom room)
|
|||
}
|
||||
gmx.Element("room").Add(tilesNode);
|
||||
|
||||
// TODO:Room physics
|
||||
//Room Physics
|
||||
|
||||
gmx.Element("room").Add(
|
||||
new XElement("PhysicsWorld", room.World),
|
||||
new XElement("PhysicsWorldTop", room.Top),
|
||||
new XElement("PhysicsWorldLeft", room.Left),
|
||||
new XElement("PhysicsWorldRight", room.Right),
|
||||
new XElement("PhysicsWorldBottom", room.Bottom),
|
||||
new XElement("PhysicsWorldGravityX", room.GravityX),
|
||||
new XElement("PhysicsWorldGravityY", room.GravityY),
|
||||
new XElement("PhysicsWorldPixToMeters", room.MetersPerPixel)
|
||||
);
|
||||
|
||||
File.WriteAllText(projFolder + "/rooms/" + room.Name.Content + ".room.gmx", gmx.ToString());
|
||||
File.WriteAllText(projFolder + "/rooms/" + room.Name.Content + ".room.gmx", gmx.ToString() + "\n");
|
||||
}
|
||||
|
||||
// --------------- Export Sound ---------------
|
||||
|
@ -422,9 +474,13 @@ void ExportSound(UndertaleSound sound)
|
|||
new XElement("extension", Path.GetExtension(sound.File.Content)),
|
||||
new XElement("origname", "sound\\audio\\" + sound.File.Content),
|
||||
new XElement("effects", sound.Effects.ToString()),
|
||||
new XElement("volume", sound.Volume.ToString()),
|
||||
new XElement("volume",
|
||||
new XElement("volume", sound.Volume.ToString())
|
||||
),
|
||||
new XElement("pan", "0"),
|
||||
new XElement("bitRates", "192"),
|
||||
new XElement("bitRates",
|
||||
new XElement("bitRate", "192")
|
||||
),
|
||||
new XElement("sampleRates",
|
||||
new XElement("sampleRate", "44100")
|
||||
),
|
||||
|
@ -443,7 +499,7 @@ void ExportSound(UndertaleSound sound)
|
|||
)
|
||||
);
|
||||
|
||||
File.WriteAllText(projFolder + "/sound/" + sound.Name.Content + ".sound.gmx", gmx.ToString());
|
||||
File.WriteAllText(projFolder + "/sound/" + sound.Name.Content + ".sound.gmx", gmx.ToString() + "\n");
|
||||
|
||||
// Save sound files
|
||||
if (sound.AudioFile != null)
|
||||
|
@ -626,7 +682,7 @@ void GenerateProjectFile()
|
|||
WriteIndexes<UndertalePath>(gmx.Element("assets"), "paths", "paths", Data.Paths, "path", "paths\\");
|
||||
WriteIndexes<UndertaleTimeline>(gmx.Element("assets"), "timelines", "timelines", Data.Timelines, "timeline", "timelines\\");
|
||||
|
||||
File.WriteAllText(projFolder + "Export_Project.project.gmx", gmx.ToString());
|
||||
File.WriteAllText(projFolder + GameName + ".project.gmx", gmx.ToString());
|
||||
}
|
||||
|
||||
void WriteIndexes<T>(XElement rootNode, string elementName, string attributeName, IList<T> dataList, string oneName, string resourcePath, string fileExtension = "")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue