Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow Saving With Invalid Platform Triggers #13

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gtk-sharp/MapWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,7 @@ bool SaveAs() {
d.CurrentName = Level.Name + ".sceA";
d.DoOverwriteConfirmation = true;
try {
Level.Validate();
if (d.Run() == (int) ResponseType.Accept) {
mapfile = new MapFile();
Level.AssurePlayerStart();
Expand Down Expand Up @@ -1014,6 +1015,7 @@ bool Save() {
} else {
bool success = false;
try {
Level.Validate();
Level.AssurePlayerStart();
Redraw();
mapfile.Directory[0] = Level.Save();
Expand Down
23 changes: 23 additions & 0 deletions level/Level.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,29 @@ public void AssurePlayerStart() {
}
}

void ValidatePlatformTriggers() {
for (int i = 0; i < Polygons.Count; ++i) {
Polygon polygon = Polygons[i];
if (polygon.Type == PolygonType.PlatformOnTrigger || polygon.Type == PolygonType.PlatformOffTrigger) {
bool found = false;
foreach (Platform platform in Platforms) {
if (platform.PolygonIndex == polygon.Permutation) {
found = true;
break;
}
}
if (!found) {
string message = "Invalid map: Platform trigger at polygon " + i + " does not have a valid platform assigned.";
throw new Wadfile.BadMapException(message);
}
}
}
}

public void Validate() {
ValidatePlatformTriggers();
}

public Wadfile.DirectoryEntry Save() {
Wadfile.DirectoryEntry wad = new Wadfile.DirectoryEntry();
wad.Chunks = Chunks;
Expand Down