From 87a626b153142852f966047d90ed0cee96b33b60 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Tue, 13 Sep 2022 09:48:31 -0400 Subject: [PATCH] cwe plugin enhancements and additional functionality --- .../ChaosWorksScene/ChaosWorksSceneEditor.cs | 173 +++++++++ .../Editors/ChaosWorksScene/LevelRenderer.cs | 103 ++++++ .../Properties/AssemblyInfo.cs | 46 +++ .../DefaultSettingsProvider.xml | 15 + ...or.Plugins.ChaosWorks.UserInterface.csproj | 81 +++++ .../ChaosWorksScene/ChaosWorksScene.uexml | 20 ++ .../ChaosWorksScene/DEFDataFormat.cs | 327 ++++++++++++++++++ .../ChaosWorks/ChaosWorksVOLDataFormat.cs | 2 +- .../FileSystemObjectModelExtensions.cs | 39 +++ .../ChaosWorksScene/ChaosWorksSceneLevel.cs | 46 +++ .../ChaosWorksSceneLevelPlane.cs | 38 ++ .../ChaosWorksScene/ChaosWorksSceneObject.cs | 41 +++ .../ChaosWorksSceneObjectModel.cs | 52 +++ .../ChaosWorksScene/ChaosWorksSceneSprite.cs | 40 +++ .../ChaosWorksScene/ChaosWorksSceneType.cs | 42 +++ .../UniversalEditor.Plugins.ChaosWorks.csproj | 13 + UniversalEditor.sln | 7 + 17 files changed, 1084 insertions(+), 1 deletion(-) create mode 100644 Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/Editors/ChaosWorksScene/ChaosWorksSceneEditor.cs create mode 100644 Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/Editors/ChaosWorksScene/LevelRenderer.cs create mode 100644 Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/Properties/AssemblyInfo.cs create mode 100644 Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/SettingsProviders/DefaultSettingsProvider.xml create mode 100644 Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface.csproj create mode 100644 Plugins/UniversalEditor.Plugins.ChaosWorks/Associations/ChaosWorksScene/ChaosWorksScene.uexml create mode 100644 Plugins/UniversalEditor.Plugins.ChaosWorks/DataFormats/ChaosWorksScene/DEFDataFormat.cs create mode 100644 Plugins/UniversalEditor.Plugins.ChaosWorks/DataFormats/FileSystem/ChaosWorks/FileSystemObjectModelExtensions.cs create mode 100644 Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneLevel.cs create mode 100644 Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneLevelPlane.cs create mode 100644 Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneObject.cs create mode 100644 Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneObjectModel.cs create mode 100644 Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneSprite.cs create mode 100644 Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneType.cs diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/Editors/ChaosWorksScene/ChaosWorksSceneEditor.cs b/Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/Editors/ChaosWorksScene/ChaosWorksSceneEditor.cs new file mode 100644 index 00000000..88d5da80 --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/Editors/ChaosWorksScene/ChaosWorksSceneEditor.cs @@ -0,0 +1,173 @@ +// +// ChaosWorksSceneEditor.cs - +// +// Author: +// Michael Becker +// +// Copyright (c) 2022 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using MBS.Framework.UserInterface; +using MBS.Framework.UserInterface.Layouts; +using UniversalEditor.Accessors; +using UniversalEditor.DataFormats.FileSystem.ChaosWorks; +using UniversalEditor.ObjectModels.FileSystem; +using UniversalEditor.ObjectModels.Multimedia.Picture.Collection; +using UniversalEditor.Plugins.ChaosWorks.DataFormats.Multimedia.PictureCollection; +using UniversalEditor.Plugins.ChaosWorks.ObjectModels.ChaosWorksScene; +using UniversalEditor.UserInterface; + +namespace UniversalEditor.Plugins.ChaosWorks.UserInterface.Editors.ChaosWorksScene +{ + public class ChaosWorksSceneEditor : Editor + { + private LevelRenderer levelRenderer = null; + public ChaosWorksSceneEditor() + { + Layout = new BoxLayout(Orientation.Vertical); + levelRenderer = new LevelRenderer(this); + Controls.Add(levelRenderer, new BoxLayout.Constraints(true, true)); + } + + private static ChaosWorksVOLDataFormat voldf = new ChaosWorksVOLDataFormat(); + private System.Collections.Generic.Dictionary _sprites = new System.Collections.Generic.Dictionary(); + private void InitializeSprites() + { + _sprites.Clear(); + + FileSystemObjectModel fsom = new FileSystemObjectModel(); + string path = MBS.Framework.Application.Instance.GetSetting(new Guid("{25e4e8be-bee2-47ed-bc4c-5d3bb3d5aeae}")); + string[] volfiles = System.IO.Directory.GetFiles(path, "*.vol"); + foreach (string volfile in volfiles) + { + FileSystemObjectModel fsom1 = new FileSystemObjectModel(); + Document.Load(fsom1, voldf, new FileAccessor(volfile)); + + fsom1.CopyTo(fsom); + // ff84f01a-3269-4038-88d8-f9680c8b1b98 + } + + ChaosWorksSceneObjectModel scene = (ObjectModel as ChaosWorksSceneObjectModel); + string groupName = "BROWN"; + for (int i = 0; i < scene.Sprites.Count; i++) + { + File f = fsom.GetFileByLabel(String.Format("{0}/{1}/HIRES", groupName.ToUpper(), scene.Sprites[i].SpriteName.ToUpper())); + if (f != null) + { + PictureCollectionObjectModel coll = new PictureCollectionObjectModel(); + Document.Load(coll, spldf, new EmbeddedFileAccessor(f)); + _sprites[scene.Sprites[i].SpriteName] = coll; + } + } + } + + private static CWESpriteDataFormat spldf = new CWESpriteDataFormat(); + public PictureCollectionObjectModel LoadFFSprite(string name) + { + if (_sprites.ContainsKey(name)) + { + return _sprites[name]; + } + return null; + } + private string GetDefaultProjectPath() + { + return MBS.Framework.Application.Instance.GetSetting(new Guid("{25e4e8be-bee2-47ed-bc4c-5d3bb3d5aeae}")); + } + + public override void UpdateSelections() + { + } + + protected override Selection CreateSelectionInternal(object content) + { + return null; + } + + EditorReference _er = null; + public override EditorReference MakeReference() + { + if (_er == null) + { + _er = new EditorReference(GetType()); + _er.SupportedObjectModels.Add(typeof(ChaosWorksSceneObjectModel)); + } + return _er; + } + + protected override void OnCreated(EventArgs e) + { + base.OnCreated(e); + + string searchPath = GetDefaultProjectPath(); + if (searchPath == null) + { + MBS.Framework.UserInterface.Dialogs.MessageDialog.ShowDialog("Please specify default project path in settings", "Error", MBS.Framework.UserInterface.Dialogs.MessageDialogButtons.OK, MBS.Framework.UserInterface.Dialogs.MessageDialogIcon.Error); + } + } + + protected override void OnObjectModelChanged(EventArgs e) + { + base.OnObjectModelChanged(e); + + ChaosWorksSceneObjectModel scene = (ObjectModel as ChaosWorksSceneObjectModel); + if (scene == null) + return; + + InitializeSprites(); + + EditorDocumentExplorerNode nodeTypes = new EditorDocumentExplorerNode("Types"); + for (int i = 0; i < scene.Types.Count; i++) + { + EditorDocumentExplorerNode node = new EditorDocumentExplorerNode(String.Format("{0} : {1} {2} {3}", scene.Types[i].Name, scene.Types[i].Flags1, scene.Types[i].Flags2, scene.Types[i].Flags3)); + node.SetExtraData("type", scene.Types[i]); + nodeTypes.Nodes.Add(node); + } + DocumentExplorer.Nodes.Add(nodeTypes); + + EditorDocumentExplorerNode nodeSprites = new EditorDocumentExplorerNode("Sprites"); + for (int i = 0; i < scene.Sprites.Count; i++) + { + EditorDocumentExplorerNode node = new EditorDocumentExplorerNode(String.Format("{0} : {1}", scene.Sprites[i].SpriteName, scene.Sprites[i].TypeName)); + node.SetExtraData("sprite", scene.Sprites[i]); + nodeSprites.Nodes.Add(node); + } + DocumentExplorer.Nodes.Add(nodeSprites); + + EditorDocumentExplorerNode nodeLevels = new EditorDocumentExplorerNode("Levels"); + for (int i = 0; i < scene.Levels.Count; i++) + { + EditorDocumentExplorerNode node = new EditorDocumentExplorerNode(String.Format("Level {0}", i + 1)); + node.SetExtraData("level", scene.Levels[i]); + nodeLevels.Nodes.Add(node); + } + DocumentExplorer.Nodes.Add(nodeLevels); + } + + protected override void OnDocumentExplorerSelectionChanged(EditorDocumentExplorerSelectionChangedEventArgs e) + { + base.OnDocumentExplorerSelectionChanged(e); + + if (e.Node != null) + { + ChaosWorksSceneLevel level = e.Node.GetExtraData("level"); + if (level != null) + { + levelRenderer.Level = level; + } + } + } + } +} diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/Editors/ChaosWorksScene/LevelRenderer.cs b/Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/Editors/ChaosWorksScene/LevelRenderer.cs new file mode 100644 index 00000000..87acc1af --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/Editors/ChaosWorksScene/LevelRenderer.cs @@ -0,0 +1,103 @@ +// +// LevelRenderer.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2022 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using MBS.Framework.UserInterface; +using MBS.Framework.UserInterface.Drawing; +using UniversalEditor.ObjectModels.Multimedia.Picture; +using UniversalEditor.ObjectModels.Multimedia.Picture.Collection; +using UniversalEditor.Plugins.ChaosWorks.ObjectModels.ChaosWorksScene; +using UniversalEditor.Plugins.Multimedia.UserInterface; + +namespace UniversalEditor.Plugins.ChaosWorks.UserInterface.Editors.ChaosWorksScene +{ + public class LevelRenderer : MBS.Framework.UserInterface.CustomControl + { + private ChaosWorksSceneLevel _Level = null; + public ChaosWorksSceneLevel Level { get { return _Level; } set { _Level = value; InitPicx(); Refresh(); } } + + public ChaosWorksSceneEditor ParentEditor { get; private set; } = null; + public LevelRenderer(ChaosWorksSceneEditor parentEditor) + { + ParentEditor = parentEditor; + } + + private System.Collections.Generic.Dictionary _picx = new System.Collections.Generic.Dictionary(); + private void InitPicx() + { + _picx.Clear(); + + double minScrollX = 0, minScrollY = 0, maxScrollX = 0, maxScrollY = 0; + + if (Level != null) + { + for (int i = 0; i < Level.Planes.Count; i++) + { + for (int j = 0; j < Level.Planes[i].Objects.Count; j++) + { + if (Level.Planes[i].Objects[j].Position.X < minScrollX) + { + minScrollX = Level.Planes[i].Objects[j].Position.X; + } + if (Level.Planes[i].Objects[j].Position.Y < minScrollY) + { + minScrollY = Level.Planes[i].Objects[j].Position.Y; + } + if (Level.Planes[i].Objects[j].Position.X > maxScrollX) + { + maxScrollX = Level.Planes[i].Objects[j].Position.X; + } + if (Level.Planes[i].Objects[j].Position.Y > maxScrollY) + { + maxScrollY = Level.Planes[i].Objects[j].Position.Y; + } + + PictureCollectionObjectModel piccoll = ParentEditor.LoadFFSprite(Level.Planes[i].Objects[j].SpriteName); + PictureObjectModel pic = piccoll.Pictures[Level.Planes[i].Objects[j].Phase]; + _picx[j] = pic.ToImage(); + } + } + + ScrollBounds = new MBS.Framework.Drawing.Dimension2D(maxScrollX, maxScrollY); + } + } + + protected override void OnPaint(PaintEventArgs e) + { + base.OnPaint(e); + + if (Level != null) + { + for (int i = 0; i < Level.Planes.Count; i++) + { + for (int j = 0; j < Level.Planes[i].Objects.Count; j++) + { + e.Graphics.DrawImage(_picx[j], Level.Planes[i].Position.X * (Level.Planes[i].Objects[j].Position.X - Level.CenterPosition.X - HorizontalAdjustment.Value), Level.Planes[i].Position.Y * (Level.Planes[i].Objects[j].Position.Y - Level.CenterPosition.Y - VerticalAdjustment.Value)); + } + } + } + } + + protected override void OnScrolled(ScrolledEventArgs e) + { + base.OnScrolled(e); + Invalidate(); + } + } +} diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/Properties/AssemblyInfo.cs b/Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..48f5092e --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/Properties/AssemblyInfo.cs @@ -0,0 +1,46 @@ +// +// AssemblyInfo.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2022 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("UniversalEditor.Plugins.ChaosWorks.UserInterface")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Mike Becker's Software")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Mike Becker's Software")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/SettingsProviders/DefaultSettingsProvider.xml b/Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/SettingsProviders/DefaultSettingsProvider.xml new file mode 100644 index 00000000..b2b4d5be --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/SettingsProviders/DefaultSettingsProvider.xml @@ -0,0 +1,15 @@ + + + + + + Editors + Chaos Works + + + + + + + + diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface.csproj b/Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface.csproj new file mode 100644 index 00000000..be0510fd --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface/UniversalEditor.Plugins.ChaosWorks.UserInterface.csproj @@ -0,0 +1,81 @@ + + + + Debug + AnyCPU + {17A0F754-C902-49EB-A21D-93A4EE75059B} + Library + UniversalEditor.Plugins.ChaosWorks.UserInterface + UniversalEditor.Plugins.ChaosWorks.UserInterface + v4.7 + 4.0.2019.12 + + + true + full + false + ..\..\Output\Debug\Plugins + DEBUG; + prompt + 4 + false + + + true + ..\..\Output\Release\Plugins + prompt + 4 + false + + + + + + + + + + + + + + + + + {2D4737E6-6D95-408A-90DB-8DFF38147E85} + UniversalEditor.Core + + + {30467E5C-05BC-4856-AADC-13906EF4CADD} + UniversalEditor.Essential + + + {30A2F772-8EC1-425A-8D5D-36A0BE4D6B66} + UniversalEditor.Plugins.ChaosWorks + + + {8622EBC4-8E20-476E-B284-33D472081F5C} + UniversalEditor.UserInterface + + + {00266B21-35C9-4A7F-A6BA-D54D7FDCC25C} + MBS.Framework + + + {29E1C1BB-3EA5-4062-B62F-85EEC703FE07} + MBS.Framework.UserInterface + + + {BE4D0BA3-0888-42A5-9C09-FC308A4509D2} + UniversalEditor.Plugins.Multimedia + + + {D9D5AC3B-9AC0-4D4E-B295-2134FDCF166C} + UniversalEditor.Plugins.Multimedia.UserInterface + + + + + + + diff --git a/Plugins/UniversalEditor.Plugins.ChaosWorks/Associations/ChaosWorksScene/ChaosWorksScene.uexml b/Plugins/UniversalEditor.Plugins.ChaosWorks/Associations/ChaosWorksScene/ChaosWorksScene.uexml new file mode 100644 index 00000000..8e55e6ec --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.ChaosWorks/Associations/ChaosWorksScene/ChaosWorksScene.uexml @@ -0,0 +1,20 @@ + + + + + + + + *.def + + + + + + + + + + + + diff --git a/Plugins/UniversalEditor.Plugins.ChaosWorks/DataFormats/ChaosWorksScene/DEFDataFormat.cs b/Plugins/UniversalEditor.Plugins.ChaosWorks/DataFormats/ChaosWorksScene/DEFDataFormat.cs new file mode 100644 index 00000000..277b7926 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.ChaosWorks/DataFormats/ChaosWorksScene/DEFDataFormat.cs @@ -0,0 +1,327 @@ +// +// DEFDataFormat.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2022 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using UniversalEditor.IO; +using UniversalEditor.Plugins.ChaosWorks.ObjectModels.ChaosWorksScene; + +namespace UniversalEditor.Plugins.ChaosWorks.DataFormats.ChaosWorksScene +{ + public class DEFDataFormat : DataFormat + { + protected override void LoadInternal(ref ObjectModel objectModel) + { + ChaosWorksSceneObjectModel scene = (objectModel as ChaosWorksSceneObjectModel); + if (scene == null) + throw new ObjectModelNotSupportedException(); + + IO.Reader reader = Accessor.Reader; + string groupName = null; + int levelIndex = -1; + int planeIndex = -1; + int currentLevelIndex = -1; + int currentPlaneIndex = 0; + string previousGroupName = null; + + while (!reader.EndOfStream) + { + string line = reader.ReadLine(); + line = StripComment(line); + line = line.Trim(); + + if (String.IsNullOrEmpty(line)) + continue; + + if (line.EndsWith(":")) + { + // group start + groupName = line.Substring(0, line.Length - 1); + } + else if (line.Contains("=")) + { + // property set + } + else + { + string[] parms = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + if (groupName == "types") + { + previousGroupName = groupName; + if (parms.Length >= 4) + { + ChaosWorksSceneType type = new ChaosWorksSceneType(); + type.Flags1 = Int16.Parse(parms[0]); + type.Flags2 = Int16.Parse(parms[1]); + type.Flags3 = Int16.Parse(parms[2]); + type.Name = parms[3]; + scene.Types.Add(type); + } + } + else if (groupName == "sprites") + { + previousGroupName = groupName; + if (parms.Length >= 2) + { + ChaosWorksSceneSprite sprite = new ChaosWorksSceneSprite(); + if (parms[0] == "*") + { + // idk + sprite.SpriteName = parms[1]; + sprite.TypeName = parms[2]; + } + else + { + sprite.SpriteName = parms[0]; + sprite.TypeName = parms[1]; + } + scene.Sprites.Add(sprite); + } + } + else + { + if (groupName != previousGroupName) + { + levelIndex = -1; + planeIndex = -1; + previousGroupName = groupName; + } + + if (levelIndex == -1 && planeIndex == -1) + { + if (groupName.StartsWith("level")) + { + if (groupName.Contains("_plane")) + { + int indexOfPlane = groupName.IndexOf("_plane"); + int levelLength = indexOfPlane - "level".Length; + + string szLevelIndex = groupName.Substring("level".Length, levelLength); + string szPlaneIndex = groupName.Substring("_plane".Length + indexOfPlane); + levelIndex = Int32.Parse(szLevelIndex); + planeIndex = Int32.Parse(szPlaneIndex); + } + else + { + levelIndex = Int32.Parse(groupName.Substring("level".Length)); + if (levelIndex != currentLevelIndex) + { + currentLevelIndex = levelIndex; + currentPlaneIndex = 0; + if (parms.Length == 3) + { + ChaosWorksSceneLevel currentLevel = new ChaosWorksSceneLevel(); + currentLevel.ActivePlaneIndex = Int32.Parse(parms[0]); + currentLevel.CenterPosition = new PositionVector2(Double.Parse(parms[1]), Double.Parse(parms[2])); + scene.Levels.Add(currentLevel); + continue; + } + } + } + } + } + else if (planeIndex == -1) + { + // reading level information + ChaosWorksSceneLevelPlane plane = new ChaosWorksSceneLevelPlane(); + plane.Position = new PositionVector2(Double.Parse(parms[0]), Double.Parse(parms[1])); + plane.u1 = Int32.Parse(parms[2]); + plane.u2 = Int32.Parse(parms[3]); + plane.u3 = Int32.Parse(parms[4]); + scene.Levels[levelIndex - 1].Planes.Add(plane); + currentPlaneIndex++; + } + else + { + // reading plane information + if (parms.Length >= 9) + { + ChaosWorksSceneObject obj = new ChaosWorksSceneObject(); + obj.SpriteName = parms[0]; + obj.Phase = Int32.Parse(parms[1]); + obj.Mirror = Int32.Parse(parms[2]); + obj.Position = new PositionVector2(Double.Parse(parms[3]), Double.Parse(parms[4])); + obj.Link = Int32.Parse(parms[5]); + obj.LPos = Int32.Parse(parms[6]); + obj.S = Int32.Parse(parms[7]); + obj.TypeName = parms[8]; + scene.Levels[levelIndex - 1].Planes[planeIndex - 1].Objects.Add(obj); + } + } + } + } + } + } + + private string StripComment(string line) + { + int index = line.IndexOf(';'); + if (index == -1) + return line; + + return line.Substring(0, index); + } + + protected override void SaveInternal(ObjectModel objectModel) + { + ChaosWorksSceneObjectModel scene = (objectModel as ChaosWorksSceneObjectModel); + if (scene == null) + throw new ObjectModelNotSupportedException(); + + int availableLevels = 9, availableTypes = 1024, availableSprites = 1024, availableObjects = 65534; + int usedLevels = scene.Levels.Count, usedTypes = scene.Types.Count, usedSprites = scene.Sprites.Count, usedObjects = 0; + System.Collections.Generic.Dictionary usage = new System.Collections.Generic.Dictionary(); + + for (int h = 0; h < scene.Levels.Count; h++) + { + for (int i = 0; i < scene.Levels[h].Planes.Count; i++) + { + for (int j = 0; j < scene.Levels[h].Planes[i].Objects.Count; j++) + { + usedObjects++; + if (usage.ContainsKey(scene.Levels[h].Planes[i].Objects[j].TypeName)) + { + usage[scene.Levels[h].Planes[i].Objects[j].TypeName] = usage[scene.Levels[h].Planes[i].Objects[j].TypeName] + 1; + } + else + { + usage[scene.Levels[h].Planes[i].Objects[j].TypeName] = 1; + } + } + } + } + + IO.Writer writer = Accessor.Writer; + writer.WriteLine(";"); + writer.WriteLine("; used avail free"); + writer.WriteLine("; ------------------------------------"); + + PrintComment(writer, "levels", usedLevels, availableLevels); + PrintComment(writer, "types", usedTypes, availableTypes); + PrintComment(writer, "sprites", usedSprites, availableSprites); + PrintComment(writer, "objects", usedObjects, availableObjects); + writer.WriteLine(); + writer.WriteLine("; --- type definitions ------------------------------------------------------"); + writer.WriteLine(); + writer.WriteLine("types:"); + writer.WriteLine(); + for (int i = 0; i < scene.Types.Count; i++) + { + writer.Write(String.Format(" {0} {1} {2} {3}", scene.Types[i].Flags1.ToString().PadLeft(4, '0'), scene.Types[i].Flags2.ToString().PadLeft(4, '0'), scene.Types[i].Flags3.ToString().PadLeft(4, '0'), scene.Types[i].Name.PadRight(25, ' '))); + + int nUsageTimes = 0; + if (usage.ContainsKey(scene.Types[i].Name)) + { + nUsageTimes = usage[scene.Types[i].Name]; + } + string usageTimes = null; + if (nUsageTimes == 0) + { + usageTimes = "*** NOT USED ***"; + } + else if (nUsageTimes == 1) + { + usageTimes = "used once"; + } + else + { + usageTimes = String.Format("used {0} times", nUsageTimes); + } + writer.WriteLine(String.Format("; {0}", usageTimes)); + } + + writer.WriteLine(); + writer.WriteLine("; --- sprites and default types ---------------------------------------------"); + writer.WriteLine(); + writer.WriteLine("sprites: ; TOT L1 L2 L3 L4 L5 L6 L7 L8 L9 (kB)"); + writer.WriteLine(" ; ------------------------------------"); + writer.WriteLine(); + for (int i = 0; i < scene.Sprites.Count; i++) + { + writer.Write(String.Format(" {0} {1}", scene.Sprites[i].SpriteName, scene.Sprites[i].TypeName).PadRight(54, ' ')); + writer.WriteLine("; 10 3 1 0 2 2 2 0 0 0 4"); + } + + writer.WriteLine(); + + writer.WriteLine("; ---available levels------------------------------------------------------"); + writer.WriteLine(); + writer.WriteLine(String.Format("main_level = {0}", scene.Levels.IndexOf(scene.MainLevel))); + writer.WriteLine(); + + for (int i = 0; i < scene.Levels.Count; i++) + { + ChaosWorksSceneLevel level = scene.Levels[i]; + WriteLevel(writer, i, level); + } + for (int i = 0; i < scene.Levels.Count; i++) + { + ChaosWorksSceneLevel level = scene.Levels[i]; + WriteLevelData(writer, i, level); + } + } + + private void WriteLevelData(Writer writer, int index, ChaosWorksSceneLevel level) + { + for (int i = 0; i < level.Planes.Count; i++) + { + if (level.Planes[i].Objects.Count == 0) + continue; + + writer.WriteLine(String.Format("level{0}_plane{1}: ;-------------------------------------------------------------", index + 1, i + 1)); + writer.WriteLine(); + writer.WriteLine("; sprite phas mirr x y link lpos s type"); + writer.WriteLine(); + for (int j = 0; j < level.Planes[i].Objects.Count; j++) + { + writer.WriteLine(String.Format(" {0} {1} {2} {3} {4} {5} {6} {7} {8}", + level.Planes[i].Objects[j].SpriteName.PadRight(24, ' '), + level.Planes[i].Objects[j].Phase.ToString().PadLeft(3, '0'), + level.Planes[i].Objects[j].Mirror.ToString(), + level.Planes[i].Objects[j].Position.X.ToString().PadLeft(5, ' '), + level.Planes[i].Objects[j].Position.Y.ToString().PadRight(8, ' '), + level.Planes[i].Objects[j].Link.ToString(), + level.Planes[i].Objects[j].LPos.ToString().PadRight(4, ' '), + level.Planes[i].Objects[j].S.ToString(), + level.Planes[i].Objects[j].TypeName)); + } + writer.WriteLine(); + } + } + private void WriteLevel(Writer writer, int index, ChaosWorksSceneLevel level) + { + writer.WriteLine(String.Format("level{0}:", index + 1)); + writer.WriteLine(); + writer.Write(String.Format(" {0} {1} {2}", level.ActivePlaneIndex, level.CenterPosition.X.ToString(), level.CenterPosition.Y.ToString()).PadRight(23, ' ')); + writer.WriteLine("; active plane and center position"); + for (int i = 0; i < level.Planes.Count; i++) + { + int planeSize = 0; + writer.Write(String.Format(" {0} {1} {2} {3} {4}", level.Planes[i].Position.X.ToString("F3"), level.Planes[i].Position.Y.ToString("F3"), level.Planes[i].u1, level.Planes[i].u2, level.Planes[i].u3).PadRight(25, ' ')); + writer.WriteLine(String.Format("; plane #{0}, size {1}", (i + 1), planeSize)); + } + writer.WriteLine(); + } + + private void PrintComment(Writer writer, string title, int nUsed, int nAvailable) + { + writer.WriteLine(String.Format("; {3}{0}{1}{2}", nUsed.ToString().PadRight(8, ' '), nAvailable.ToString().PadRight(8, ' '), (nAvailable - nUsed).ToString().PadRight(8, ' '), title.PadRight(13, ' '))); + } + } +} diff --git a/Plugins/UniversalEditor.Plugins.ChaosWorks/DataFormats/FileSystem/ChaosWorks/ChaosWorksVOLDataFormat.cs b/Plugins/UniversalEditor.Plugins.ChaosWorks/DataFormats/FileSystem/ChaosWorks/ChaosWorksVOLDataFormat.cs index aa8d316f..05ccc2ac 100644 --- a/Plugins/UniversalEditor.Plugins.ChaosWorks/DataFormats/FileSystem/ChaosWorks/ChaosWorksVOLDataFormat.cs +++ b/Plugins/UniversalEditor.Plugins.ChaosWorks/DataFormats/FileSystem/ChaosWorks/ChaosWorksVOLDataFormat.cs @@ -151,7 +151,7 @@ namespace UniversalEditor.DataFormats.FileSystem.ChaosWorks } short CHUNKSIZE = br.ReadInt16(); - Console.WriteLine("cwe-vol: reading chunk size {0}", CHUNKSIZE); + // Console.WriteLine("cwe-vol: reading chunk size {0}", CHUNKSIZE); byte[] compressed = br.ReadBytes(CHUNKSIZE); byte[] decompressed = lzrw1.Decompress(compressed); diff --git a/Plugins/UniversalEditor.Plugins.ChaosWorks/DataFormats/FileSystem/ChaosWorks/FileSystemObjectModelExtensions.cs b/Plugins/UniversalEditor.Plugins.ChaosWorks/DataFormats/FileSystem/ChaosWorks/FileSystemObjectModelExtensions.cs new file mode 100644 index 00000000..6097dd71 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.ChaosWorks/DataFormats/FileSystem/ChaosWorks/FileSystemObjectModelExtensions.cs @@ -0,0 +1,39 @@ +// +// FileSystemObjectModelExtensions.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2022 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using UniversalEditor.ObjectModels.FileSystem; + +namespace UniversalEditor.DataFormats.FileSystem.ChaosWorks +{ + public static class FileSystemObjectModelExtensions + { + public static File GetFileByLabel(this FileSystemObjectModel fsom, string label) + { + File[] files = fsom.GetAllFiles(); + for (int i = 0; i < files.Length; i++) + { + if ((label?.Equals(files[i].GetAdditionalDetail("ChaosWorks.VOL.Label"))).GetValueOrDefault(false)) + return files[i]; + } + return null; + } + } +} diff --git a/Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneLevel.cs b/Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneLevel.cs new file mode 100644 index 00000000..af433eaa --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneLevel.cs @@ -0,0 +1,46 @@ +// +// ChaosWorksSceneLevel.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2022 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +namespace UniversalEditor.Plugins.ChaosWorks.ObjectModels.ChaosWorksScene +{ + public class ChaosWorksSceneLevel + { + public class ChaosWorksSceneLevelCollection + : System.Collections.ObjectModel.Collection + { + + } + + /// + /// Gets or sets the index of the active plane (usually 5). + /// + /// The index of the active plane. + public int ActivePlaneIndex { get; set; } = 0; + + /// + /// Gets or sets the center position. + /// + /// The center position. + public PositionVector2 CenterPosition { get; set; } = PositionVector2.Empty; + + public ChaosWorksSceneLevelPlane.ChaosWorksSceneLevelPlaneCollection Planes { get; } = new ChaosWorksSceneLevelPlane.ChaosWorksSceneLevelPlaneCollection(); + } +} diff --git a/Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneLevelPlane.cs b/Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneLevelPlane.cs new file mode 100644 index 00000000..3cc33b5e --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneLevelPlane.cs @@ -0,0 +1,38 @@ +// +// ChaosWorksSceneLevelPlane.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2022 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +namespace UniversalEditor.Plugins.ChaosWorks.ObjectModels.ChaosWorksScene +{ + public class ChaosWorksSceneLevelPlane + { + public class ChaosWorksSceneLevelPlaneCollection + : System.Collections.ObjectModel.Collection + { + } + + public PositionVector2 Position { get; set; } = PositionVector2.Empty; + public int u1 { get; set; } = 0; + public int u2 { get; set; } = 0; + public int u3 { get; set; } = 0; + + public ChaosWorksSceneObject.ChaosWorksSceneObjectCollection Objects { get; } = new ChaosWorksSceneObject.ChaosWorksSceneObjectCollection(); + } +} diff --git a/Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneObject.cs b/Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneObject.cs new file mode 100644 index 00000000..743bab6c --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneObject.cs @@ -0,0 +1,41 @@ +// +// ChaosWorksSceneObject.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2022 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +namespace UniversalEditor.Plugins.ChaosWorks.ObjectModels.ChaosWorksScene +{ + public class ChaosWorksSceneObject + { + public class ChaosWorksSceneObjectCollection + : System.Collections.ObjectModel.Collection + { + + } + + public string SpriteName { get; set; } + public int Phase { get; set; } + public int Mirror { get; set; } + public PositionVector2 Position { get; set; } + public int Link { get; set; } + public int LPos { get; set; } + public int S { get; set; } + public string TypeName { get; set; } + } +} diff --git a/Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneObjectModel.cs b/Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneObjectModel.cs new file mode 100644 index 00000000..99b8dbab --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneObjectModel.cs @@ -0,0 +1,52 @@ +// +// ChaosWorkSceneObjectModel.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2022 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +namespace UniversalEditor.Plugins.ChaosWorks.ObjectModels.ChaosWorksScene +{ + public class ChaosWorksSceneObjectModel : ObjectModel + { + public override void Clear() + { + } + + public override void CopyTo(ObjectModel where) + { + } + + private static ObjectModelReference _omr = null; + protected override ObjectModelReference MakeReferenceInternal() + { + if (_omr == null) + { + _omr = base.MakeReferenceInternal(); + _omr.Path = new string[] { "Game Development", "Chaos Works", "Chaos Works Scene" }; + } + return _omr; + } + + public ChaosWorksSceneType.ChaosWorksSceneTypeCollection Types { get; } = new ChaosWorksSceneType.ChaosWorksSceneTypeCollection(); + public ChaosWorksSceneSprite.ChaosWorksSceneSpriteCollection Sprites { get; } = new ChaosWorksSceneSprite.ChaosWorksSceneSpriteCollection(); + public ChaosWorksSceneLevel.ChaosWorksSceneLevelCollection Levels { get; } = new ChaosWorksSceneLevel.ChaosWorksSceneLevelCollection(); + + public ChaosWorksSceneLevel MainLevel { get; set; } = null; + + } +} diff --git a/Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneSprite.cs b/Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneSprite.cs new file mode 100644 index 00000000..654e4ef3 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneSprite.cs @@ -0,0 +1,40 @@ +// +// ChaosWorksSceneSprite.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2022 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +namespace UniversalEditor.Plugins.ChaosWorks.ObjectModels.ChaosWorksScene +{ + public class ChaosWorksSceneSprite + { + public class ChaosWorksSceneSpriteCollection + : System.Collections.ObjectModel.Collection + { + + } + + public string SpriteName { get; set; } = null; + public string TypeName { get; set; } = null; + + public override string ToString() + { + return String.Format("{0} {1}", SpriteName, TypeName); + } + } +} diff --git a/Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneType.cs b/Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneType.cs new file mode 100644 index 00000000..b29ed96c --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.ChaosWorks/ObjectModels/ChaosWorksScene/ChaosWorksSceneType.cs @@ -0,0 +1,42 @@ +// +// ChaosWorksSceneType.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2022 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +namespace UniversalEditor.Plugins.ChaosWorks.ObjectModels.ChaosWorksScene +{ + public class ChaosWorksSceneType + { + public class ChaosWorksSceneTypeCollection + : System.Collections.ObjectModel.Collection + { + + } + + public short Flags1 { get; set; } = 0; + public short Flags2 { get; set; } = 0; + public short Flags3 { get; set; } = 0; + public string Name { get; set; } = String.Empty; + + public override string ToString() + { + return String.Format("{0}: {1} {2} {3}", Name, Flags1, Flags2, Flags3); + } + } +} diff --git a/Plugins/UniversalEditor.Plugins.ChaosWorks/UniversalEditor.Plugins.ChaosWorks.csproj b/Plugins/UniversalEditor.Plugins.ChaosWorks/UniversalEditor.Plugins.ChaosWorks.csproj index 009c6edd..a79e539f 100644 --- a/Plugins/UniversalEditor.Plugins.ChaosWorks/UniversalEditor.Plugins.ChaosWorks.csproj +++ b/Plugins/UniversalEditor.Plugins.ChaosWorks/UniversalEditor.Plugins.ChaosWorks.csproj @@ -43,6 +43,14 @@ + + + + + + + + @@ -72,11 +80,16 @@ + + + + +