Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Commit

Permalink
0.1.0.2 - Alpha release!
Browse files Browse the repository at this point in the history
Cordon compile support
Updated tool icon set
Check FGD file exists before loading it, fixes #2
Allow for nulls when no textures are loaded, fixes #1
Lots of bug fixes in the VM tool
  • Loading branch information
LogicAndTrick committed Jul 27, 2013
1 parent 72b71d3 commit 9978c62
Show file tree
Hide file tree
Showing 24 changed files with 127 additions and 42 deletions.
11 changes: 11 additions & 0 deletions Sledge.DataStructures/MapObjects/EntityData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,16 @@ public string GetPropertyValue(string key)
var prop = Properties.FirstOrDefault(x => String.Equals(key, x.Key, StringComparison.InvariantCultureIgnoreCase));
return prop == null ? null : prop.Value;
}

public void SetPropertyValue(string key, string value)
{
var prop = Properties.FirstOrDefault(x => String.Equals(key, x.Key, StringComparison.InvariantCultureIgnoreCase));
if (prop == null)
{
prop = new Property { Key = key};
Properties.Add(prop);
}
prop.Value = value;
}
}
}
7 changes: 5 additions & 2 deletions Sledge.Editor/Compiling/Batch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,26 @@ public class Batch
public string BeforeExecuteStep { get; set; }
public string AfterExecuteStep { get; set; }
public string TargetFile { get; set; }
public string OriginalFile { get; set; }

public Batch(Game game, string targetFile)
public Batch(Game game, Build build, string targetFile, string originalFile)
{
// TODO: this properly
var build = game.Build;
BeforeExecute = "";
AfterExecute = "";
BeforeExecuteStep = "";
AfterExecuteStep = "";
TargetFile = targetFile;
var fileFlag = '"' + targetFile + '"';
var bspFile = '"' + Path.ChangeExtension(targetFile, "bsp") + '"';
var copyBsp = '"' + Path.ChangeExtension(originalFile, "bsp") + '"';
Steps = new List<BatchCompileStep>
{
new BatchCompileStep { Operation = Path.Combine(build.Path, build.Csg), Flags = fileFlag },
new BatchCompileStep { Operation = Path.Combine(build.Path, build.Bsp), Flags = fileFlag },
new BatchCompileStep { Operation = Path.Combine(build.Path, build.Vis), Flags = fileFlag },
new BatchCompileStep { Operation = Path.Combine(build.Path, build.Rad), Flags = fileFlag },
new BatchCompileStep { Operation = "move", SystemCommand = true, Flags = bspFile + " " + copyBsp }
//new BatchCompileStep { Operation = "copy"}
};
}
Expand Down
1 change: 1 addition & 0 deletions Sledge.Editor/Compiling/BatchCompileStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Sledge.Editor.Compiling
public class BatchCompileStep
{
public string Operation { get; set; }
public bool SystemCommand { get; set; }
public string Flags { get; set; }
public string BeforeExecute { get; set; }
public string AfterExecute { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion Sledge.Editor/Compiling/BatchCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public static void Compile(Batch batch)
{
script.AppendLine(batch.BeforeExecuteStep);
script.AppendLine(step.BeforeExecute);
script.Append('"').Append(step.Operation).Append('"').Append(' ').AppendLine(step.Flags);
var cq = step.SystemCommand ? "" : "\"";
script.Append(cq).Append(step.Operation).Append(cq).Append(' ').AppendLine(step.Flags);
script.AppendLine(step.AfterExecute);
script.AppendLine(batch.AfterExecuteStep);
}
Expand Down
63 changes: 50 additions & 13 deletions Sledge.Editor/Documents/DocumentSubscriptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,23 +238,60 @@ public void FileSaveAs()
public void FileCompile()
{
FileSave();
var currentFile = _document.MapFile;
if (currentFile == null) return;
if (!currentFile.EndsWith("map"))
if (_document.MapFile == null) return;

var tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(tempDir);

_document.Map.WorldSpawn.EntityData.Properties.Add(new Property
{
_document.Map.WorldSpawn.EntityData.Properties.Add(new Property
{
Key = "wad",
Value = string.Join(";", _document.Game.Wads.Select(x => x.Path))
});
var map = Path.ChangeExtension(_document.MapFile, "map");
MapProvider.SaveMapToFile(map, _document.Map);
currentFile = map;
}
var batch = new Batch(_document.Game, currentFile);
Key = "wad",
Value = string.Join(";", _document.Game.Wads.Select(x => x.Path))
});
var map = Path.Combine(tempDir, Path.GetFileNameWithoutExtension(_document.MapFile) + ".map");
SaveWithCordon(map);

var build = SettingsManager.Builds.FirstOrDefault(x => x.ID == _document.Game.BuildID);
var batch = new Batch(_document.Game, build, map, _document.MapFile);
BatchCompiler.Compile(batch);
}

private void SaveWithCordon(string file)
{
var map = _document.Map;
if (_document.Map.Cordon)
{
map = new Map();
map.WorldSpawn.EntityData = _document.Map.WorldSpawn.EntityData.Clone();
var entities = _document.Map.WorldSpawn.GetAllNodesContainedWithin(_document.Map.CordonBounds);
foreach (var mo in entities)
{
var clone = mo.Clone();
clone.SetParent(map.WorldSpawn);
}
var outside = new Box(map.WorldSpawn.Children.Select(x => x.BoundingBox).Union(new[] {_document.Map.CordonBounds}));
outside = new Box(outside.Start - Coordinate.One, outside.End + Coordinate.One);
var inside = _document.Map.CordonBounds;

var brush = new Brushes.BlockBrush();

var cordon = (Solid) brush.Create(map.IDGenerator, outside, null).First();
var carver = (Solid) brush.Create(map.IDGenerator, inside, null).First();
cordon.Faces.ForEach(x => x.Texture.Name = "BLACK");

// Do a carve (TODO: move carve into helper method?)
foreach (var plane in carver.Faces.Select(x => x.Plane))
{
Solid back, front;
if (!cordon.Split(plane, out back, out front, map.IDGenerator)) continue;
front.SetParent(map.WorldSpawn);
cordon = back;
}

}
MapProvider.SaveMapToFile(file, map);
}

public void OperationsCopy()
{
if (!_document.Selection.IsEmpty() && !_document.Selection.InFaceSelection)
Expand Down
3 changes: 2 additions & 1 deletion Sledge.Editor/Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public static void ShowException(Exception ex, string message = "")
{
var info = new ExceptionInfo(ex, message);
var window = new ExceptionWindow(info);
window.Show(Editor.Instance);
if (Editor.Instance == null || Editor.Instance.IsDisposed) window.Show();
else window.Show(Editor.Instance);
}
}

Expand Down
7 changes: 4 additions & 3 deletions Sledge.Editor/Milestones.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
Priorities
Bugs
Windows 7 recent file jump list not opening files
Clip tool is laggy
Recent files menu -> open files
Enhancements
(Empty)
Features
Cordon compile
Recent files menu -> open files
(Post-alpha)

Post-Alpha Priorities
TDI
Advanced compiling
Advanced/proper compiling
Texture loader refactor
Models
Autosaving
Expand Down
4 changes: 2 additions & 2 deletions Sledge.Editor/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.0.1")]
[assembly: AssemblyFileVersion("0.1.0.1")]
[assembly: AssemblyVersion("0.1.0.2")]
[assembly: AssemblyFileVersion("0.1.0.2")]
Binary file modified Sledge.Editor/Resources/Tool_Brush.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Sledge.Editor/Resources/Tool_Clip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Sledge.Editor/Resources/Tool_Decal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Sledge.Editor/Resources/Tool_Entity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Sledge.Editor/Resources/Tool_Select.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Sledge.Editor/Resources/Tool_Texture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Sledge.Editor/Resources/Tool_VM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions Sledge.Editor/Settings/SettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,7 @@ private void AddGameClicked(object sender, EventArgs e)
DefaultLightmapScale = 1,
DefaultTextureScale = 1,
Fgds = new List<Fgd>(),
Wads = new List<Wad>(),
Build = _builds.FirstOrDefault()
Wads = new List<Wad>()
});
ReIndex();
UpdateGameTree();
Expand Down Expand Up @@ -479,7 +478,7 @@ private void SelectedGameUpdateFgds()
{
SelectedGameFgdList.Items.Add(fgd.Path);
}
var gd = GameDataProvider.GetGameDataFromFiles(_selectedGame.Fgds.Select(x => x.Path));
var gd = GameDataProvider.GetGameDataFromFiles(_selectedGame.Fgds.Select(x => x.Path).Where(File.Exists));

SelectedGameDefaultPointEnt.Items.Clear();
SelectedGameDefaultPointEnt.Items.AddRange(gd.Classes.Where(x => x.ClassType == ClassType.Point).Select(x => x.Name).ToArray());
Expand Down
9 changes: 8 additions & 1 deletion Sledge.Editor/Tools/DecalTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Sledge.Editor.History;
using Sledge.Editor.Properties;
using Sledge.Graphics.Helpers;
using Sledge.Providers.Texture;
using Sledge.Settings;
using Sledge.UI;

Expand Down Expand Up @@ -65,6 +66,12 @@ private void CreateDecal(Coordinate origin)
var gd = Document.GameData.Classes.First(x => x.Name == "infodecal");
var selected = Editor.Instance.GetSelectedTexture();
var textureName = selected == null ? "{TARGET" : selected.Name;

if (TexturePackage.GetItem(textureName) == null)
{
return;
}

var decal = new Entity(Document.Map.IDGenerator.GetNextObjectID())
{
EntityData = new EntityData(gd),
Expand All @@ -73,7 +80,7 @@ private void CreateDecal(Coordinate origin)
Decal = TextureHelper.Get(textureName),
Origin = origin
};
decal.EntityData.Properties.Add(new Property { Key = "texture", Value = textureName });
decal.EntityData.SetPropertyValue("texture", textureName);

Document.PerformAction("Apply decal", new Create(decal));
}
Expand Down
5 changes: 5 additions & 0 deletions Sledge.Editor/Tools/TextureApplicationForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ private void UpdateRecentTextureList()

public void SelectTexture(TextureItem item)
{
if (item == null)
{
SelectedTexturesList.SetSelectedTextures(new TextureItem[0]);
return;
}
// Add the texture to the recent texture list
if (!_recentTextures.Contains(item))
{
Expand Down
19 changes: 12 additions & 7 deletions Sledge.Editor/Tools/VMTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,11 @@ private void RefreshMidpoints(bool recreate = true)
{
foreach (var group in copy.Faces.SelectMany(x => x.GetLines()).GroupBy(x => new { x.Start, x.End }))
{
var coord = (group.Key.Start + group.Key.End) / 2;
var mpStart = _points.First(x => !x.IsMidPoint && x.Coordinate == group.Key.Start);
var mpEnd = _points.First(x => !x.IsMidPoint && x.Coordinate == group.Key.End);
var s = group.Key.Start;
var e = group.Key.End;
var coord = (s + e) / 2;
var mpStart = _points.First(x => !x.IsMidPoint && x.Coordinate == s);
var mpEnd = _points.First(x => !x.IsMidPoint && x.Coordinate == e);
if (recreate)
{
_points.Add(new VMPoint
Expand All @@ -221,7 +223,10 @@ private void RefreshMidpoints(bool recreate = true)
}
else
{
_points.First(x => x.IsMidPoint && x.MidpointStart == mpStart && x.MidpointEnd == mpEnd).Coordinate = coord;
foreach (var point in _points.Where(x => x.IsMidPoint && x.MidpointStart.Coordinate == s && x.MidpointEnd.Coordinate == e))
{
point.Coordinate = coord;
}
}
}
}
Expand Down Expand Up @@ -275,7 +280,7 @@ public override void MouseDown(ViewportBase vp, MouseEventArgs e)
}
vtxs.ForEach(x => x.IsSelected = true);
_clickedPoints = vtxs; // This is unset if the mouse is moved, see MouseUp logic.
_snapPointOffset = SnapIfNeeded(viewport.Expand(viewport.ScreenToWorld(e.X, viewport.Height - e.Y))) - viewport.Flatten(vtx.Coordinate);
_snapPointOffset = SnapIfNeeded(viewport.Expand(viewport.ScreenToWorld(e.X, viewport.Height - e.Y))) - viewport.ZeroUnusedCoordinate(vtx.Coordinate);
_movingPoint = vtx;
}

Expand Down Expand Up @@ -347,7 +352,7 @@ public override void MouseMove(ViewportBase vp, MouseEventArgs e)
// If shift is down, retain the offset the point was at before (relative to the grid)
point += _snapPointOffset;
}
var moveDistance = point - viewport.Flatten(_movingPoint.Coordinate);
var moveDistance = point - viewport.ZeroUnusedCoordinate(_movingPoint.Coordinate);
// Move each selected point by the delta value
foreach (var p in _points.Where(x => !x.IsMidPoint && x.IsSelected))
{
Expand Down Expand Up @@ -440,7 +445,7 @@ protected override void Render3D(Viewport3D vp)
foreach (var point in _points)
{
var c = vp.WorldToScreen(point.Coordinate);
if (c.Z > 1) continue;
if (c == null || c.Z > 1) continue;
c -= half;

GL.Color3(Color.Black);
Expand Down
4 changes: 3 additions & 1 deletion Sledge.Editor/UI/EntityEditor.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Sledge.Editor/Visgroups/VisgroupPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ private void AddNode(TreeNode parent, Visgroup visgroup, Func<Visgroup, string>
public void Update(Document document)
{
Clear();
if (document == null) return;
var states = document.Map.WorldSpawn
.FindAll()
.SelectMany(x => x.Visgroups.Select(y => new {ID = y, Hidden = x.IsVisgroupHidden}))
Expand Down
14 changes: 9 additions & 5 deletions Sledge.Providers/GameData/GameDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,20 @@ protected virtual bool IsValidForString(string contents)

protected virtual DataStructures.GameData.GameData GetFromFile(string filename)
{
Stream strm = new FileStream(filename, FileMode.Open, FileAccess.Read);
return GetFromStream(strm);
using (var strm = new FileStream(filename, FileMode.Open, FileAccess.Read))
{
return GetFromStream(strm);
}
}

protected virtual DataStructures.GameData.GameData GetFromString(string contents)
{
var length = Encoding.UTF8.GetByteCount(contents);
Stream strm = new MemoryStream(length);
strm.Write(Encoding.UTF8.GetBytes(contents), 0, length);
return GetFromStream(strm);
using (var strm = new MemoryStream(length))
{
strm.Write(Encoding.UTF8.GetBytes(contents), 0, length);
return GetFromStream(strm);
}
}

protected abstract DataStructures.GameData.GameData GetFromStream(Stream stream);
Expand Down
12 changes: 10 additions & 2 deletions Sledge.Providers/Map/MapFormatProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ private void WriteEntity(StreamWriter sw, Entity ent)
sw.WriteLine("{");
WriteProperty(sw, "classname", ent.EntityData.Name);
WriteProperty(sw, "spawnflags", ent.EntityData.Flags.ToString());
ent.EntityData.Properties.ForEach(x => WriteProperty(sw, x.Key, x.Value));
foreach (var prop in ent.EntityData.Properties)
{
if (prop.Key == "classname" || prop.Key == "spawnflags") continue;
WriteProperty(sw, prop.Key, prop.Value);
}

if (solids.Any()) solids.ForEach(x => WriteSolid(sw, x)); // Brush entity
else WriteProperty(sw, "origin", FormatCoordinate(ent.Origin)); // Point entity
Expand All @@ -214,7 +218,11 @@ private void WriteWorld(StreamWriter sw, World world)
WriteProperty(sw, "classname", world.EntityData.Name);
WriteProperty(sw, "spawnflags", world.EntityData.Flags.ToString());
WriteProperty(sw, "mapversion", "220");
world.EntityData.Properties.ForEach(x => WriteProperty(sw, x.Key, x.Value));
foreach (var prop in world.EntityData.Properties)
{
if (prop.Key == "classname" || prop.Key == "spawnflags" || prop.Key == "mapversion") continue;
WriteProperty(sw, prop.Key, prop.Value);
}
solids.ForEach(x => WriteSolid(sw, x));

sw.WriteLine("}");
Expand Down
1 change: 0 additions & 1 deletion Sledge.Settings/Models/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class Game

public List<Fgd> Fgds { get; set; }
public List<Wad> Wads { get; set; }
public Build Build { get; set; }

public Game()
{
Expand Down

0 comments on commit 9978c62

Please sign in to comment.