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

Add puzzle items #13

Merged
merged 7 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
22 changes: 21 additions & 1 deletion src/SerialLoops.Lib/Items/BackgroundItem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using HaruhiChokuretsuLib.Archive;
using HaruhiChokuretsuLib.Archive.Data;
using HaruhiChokuretsuLib.Archive.Event;
using HaruhiChokuretsuLib.Archive.Graphics;
using SkiaSharp;
using System.Linq;
Expand All @@ -8,18 +9,27 @@ namespace SerialLoops.Lib.Items
{
public class BackgroundItem : Item
{
public int Id { get; set; }
public GraphicsFile Graphic1 { get; set; }
public GraphicsFile Graphic2 { get; set; }
public BgType BackgroundType { get; set; }
public (string ScriptName, ScriptCommandInvocation command)[] ScriptUses { get; set; }

public BackgroundItem(string name) : base(name, ItemType.Background)
{
}
public BackgroundItem(string name, BgTableEntry entry, ArchiveFile<GraphicsFile> grp) : base(name, ItemType.Background)
public BackgroundItem(string name, int id, BgTableEntry entry, ArchiveFile<EventFile> evt, ArchiveFile<GraphicsFile> grp) : base(name, ItemType.Background)
{
Id = id;
BackgroundType = entry.Type;
Graphic1 = grp.Files.First(g => g.Index == entry.BgIndex1);
Graphic2 = grp.Files.FirstOrDefault(g => g.Index == entry.BgIndex2); // can be null if type is SINGLE_TEX
PopulateScriptUses(evt);
}

public override void Refresh(Project project)
{
PopulateScriptUses(project.Evt);
}

public SKBitmap GetBackground()
Expand Down Expand Up @@ -71,5 +81,15 @@ public SKBitmap GetBackground()
return bitmap;
}
}

public void PopulateScriptUses(ArchiveFile<EventFile> evt)
{
string[] bgCommands = new string[] { "KBG_DISP", "BG_DISP", "BG_DISP2", "BG_DISPTEMP", "BG_FADE" };

ScriptUses = evt.Files.SelectMany(e =>
e.ScriptSections.SelectMany(sec =>
sec.Objects.Where(c => bgCommands.Contains(c.Command.Mnemonic)).Select(c => (e.Name[0..^1], c))))
.Where(t => t.c.Parameters[0] == Id || t.c.Command.Mnemonic == "BG_FADE" && t.c.Parameters[1] == Id).ToArray();
}
}
}
13 changes: 3 additions & 10 deletions src/SerialLoops.Lib/Items/Item.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using SerialLoops.Lib.Items;

namespace SerialLoops.Lib.Items
namespace SerialLoops.Lib.Items
{
public abstract class Item : ItemDescription
{

public Item(string name, ItemDescription.ItemType type) : base(name, type)
public Item(string name, ItemType type) : base(name, type)
{
}

public abstract void Refresh(Project project);
}

}
14 changes: 1 addition & 13 deletions src/SerialLoops.Lib/Items/ItemDescription.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SerialLoops.Lib.Items
namespace SerialLoops.Lib.Items
{
public class ItemDescription
{
Expand All @@ -18,12 +12,6 @@ public ItemDescription(string name, ItemType type)
Type = type;
}

// Load an item from an ItemDescription
public virtual Item Load()
{
throw new NotImplementedException();
}

// Enum with values for each type of item
public enum ItemType
{
Expand Down
9 changes: 8 additions & 1 deletion src/SerialLoops.Lib/Items/MapItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using HaruhiChokuretsuLib.Archive.Data;
using HaruhiChokuretsuLib.Archive;
using HaruhiChokuretsuLib.Archive.Data;
using HaruhiChokuretsuLib.Archive.Event;
using HaruhiChokuretsuLib.Archive.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -18,5 +21,9 @@ public MapItem(MapFile map) : base(map.Name[0..^1], ItemType.Map)
Map = map;
}

public override void Refresh(Project project)
{
throw new NotImplementedException();
}
}
}
39 changes: 35 additions & 4 deletions src/SerialLoops.Lib/Items/PuzzleItem.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
using System;
using HaruhiChokuretsuLib.Archive.Data;
using HaruhiChokuretsuLib.Archive.Graphics;
using SkiaSharp;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SerialLoops.Lib.Items
{
internal class PuzzleItem
public class PuzzleItem : Item
{
public PuzzleFile Puzzle { get; set; }
public SKBitmap SingularityImage { get; set; }

public PuzzleItem(PuzzleFile puzzleFile, Project project) : base(puzzleFile.Name[0..^1], ItemType.Puzzle)
{
Puzzle = puzzleFile;
Refresh(project);
}

public override void Refresh(Project project)
{
GraphicsFile singularityLayout = project.Grp.Files.First(f => f.Index == Puzzle.Settings.SingularityLayout);
GraphicsFile singularityTexture = project.Grp.Files.First(f => f.Index == Puzzle.Settings.SingularityTexture);
SingularityImage = singularityLayout.GetLayout(
new List<GraphicsFile>() { singularityTexture },
0,
singularityLayout.LayoutEntries.Count,
false,
true).bitmap;
}

public static readonly List<string> Characters = new()
{
"UNKNOWN (0)",
"KYON",
"HARUHI",
"MIKURU",
"NAGATO",
"KOIZUMI",
"ANY",
};
}
}
9 changes: 8 additions & 1 deletion src/SerialLoops.Lib/Items/ScriptItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using HaruhiChokuretsuLib.Archive.Event;
using HaruhiChokuretsuLib.Archive;
using HaruhiChokuretsuLib.Archive.Data;
using HaruhiChokuretsuLib.Archive.Event;
using HaruhiChokuretsuLib.Archive.Graphics;

namespace SerialLoops.Lib.Items
{
Expand All @@ -13,5 +16,9 @@ public ScriptItem(EventFile evt) : base(evt.Name[0..^1], ItemType.Script)
Event = evt;
}

public override void Refresh(Project project)
{
throw new System.NotImplementedException();
}
}
}
38 changes: 21 additions & 17 deletions src/SerialLoops.Lib/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public class Project
public List<ItemDescription> Items { get; set; } = new();

[JsonIgnore]
private ArchiveFile<DataFile> _dat;
public ArchiveFile<DataFile> Dat;
[JsonIgnore]
private ArchiveFile<GraphicsFile> _grp;
public ArchiveFile<GraphicsFile> Grp;
[JsonIgnore]
private ArchiveFile<EventFile> _evt;
public ArchiveFile<EventFile> Evt;

public Project()
{
Expand All @@ -60,32 +60,36 @@ public Project(string name, string langCode, Config config, ILogger log)

public void LoadArchives(ILogger log)
{
_dat = ArchiveFile<DataFile>.FromFile(Path.Combine(IterativeDirectory, "original", "archives", "dat.bin"), log);
_grp = ArchiveFile<GraphicsFile>.FromFile(Path.Combine(IterativeDirectory, "original", "archives", "grp.bin"), log);
_evt = ArchiveFile<EventFile>.FromFile(Path.Combine(IterativeDirectory, "original", "archives", "evt.bin"), log);
Dat = ArchiveFile<DataFile>.FromFile(Path.Combine(IterativeDirectory, "original", "archives", "dat.bin"), log);
Grp = ArchiveFile<GraphicsFile>.FromFile(Path.Combine(IterativeDirectory, "original", "archives", "grp.bin"), log);
Evt = ArchiveFile<EventFile>.FromFile(Path.Combine(IterativeDirectory, "original", "archives", "evt.bin"), log);

Items.AddRange(_evt.Files
.Where(e => !new string[] { "CHESSS", "EVTTBLS", "TOPICS", "SCENARIOS", "TUTORIALS", "VOICEMAPS" }.Contains(e.Name))
.Select(e => new ScriptItem(e)));
QMapFile qmap = _dat.Files.First(f => f.Name == "QMAPS").CastTo<QMapFile>();
Items.AddRange(_dat.Files
.Where(d => qmap.QMaps.Select(q => q.Name.Replace(".", "")).Contains(d.Name))
.Select(m => new MapItem(m.CastTo<MapFile>())));
BgTableFile bgTable = _dat.Files.First(f => f.Name == "BGTBLS").CastTo<BgTableFile>();
foreach (BgTableEntry entry in bgTable.BgTableEntries)
BgTableFile bgTable = Dat.Files.First(f => f.Name == "BGTBLS").CastTo<BgTableFile>();
for (int i = 0; i < bgTable.BgTableEntries.Count; i++)
{
BgTableEntry entry = bgTable.BgTableEntries[i];
if (entry.BgIndex1 > 0)
{
GraphicsFile nameGraphic = _grp.Files.First(g => g.Index == entry.BgIndex1);
GraphicsFile nameGraphic = Grp.Files.First(g => g.Index == entry.BgIndex1);
string name = $"BG_{nameGraphic.Name[0..(nameGraphic.Name.LastIndexOf('_'))]}";
string bgNameBackup = name;
for (int j = 1; Items.Select(i => i.Name).Contains(name); j++)
{
name = $"{bgNameBackup}{j:D2}";
}
Items.Add(new BackgroundItem(name, entry, _grp));
Items.Add(new BackgroundItem(name, i, entry, Evt, Grp));
}
}
Items.AddRange(Evt.Files
.Where(e => !new string[] { "CHESSS", "EVTTBLS", "TOPICS", "SCENARIOS", "TUTORIALS", "VOICEMAPS" }.Contains(e.Name))
.Select(e => new ScriptItem(e)));
QMapFile qmap = Dat.Files.First(f => f.Name == "QMAPS").CastTo<QMapFile>();
Items.AddRange(Dat.Files
.Where(d => qmap.QMaps.Select(q => q.Name.Replace(".", "")).Contains(d.Name))
.Select(m => new MapItem(m.CastTo<MapFile>())));
Items.AddRange(Dat.Files
.Where(d => d.Name.StartsWith("SLG"))
.Select(d => new PuzzleItem(d.CastTo<PuzzleFile>(), this)));
}

public ItemDescription FindItem(string name)
Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops.Lib/SerialLoops.Lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HaruhiChokuretsuLib" Version="0.11.0" />
<PackageReference Include="HaruhiChokuretsuLib" Version="0.12.0" />
<PackageReference Include="NitroPacker.Core" Version="2.0.1" />
</ItemGroup>

Expand Down
2 changes: 2 additions & 0 deletions src/SerialLoops/Controls/EditorTabsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ internal static DocumentPage CreateTab(ItemDescription item, Project project, IL
return new BackgroundEditor((BackgroundItem)project.Items.First(i => i.Name == item.Name), log);
case ItemDescription.ItemType.Map:
return new MapEditor((MapItem)project.Items.First(i => i.Name == item.Name), log);
case ItemDescription.ItemType.Puzzle:
return new PuzzleEditor((PuzzleItem)project.Items.First(i => i.Name == item.Name), log);
case ItemDescription.ItemType.Script:
return new ScriptEditor((ScriptItem)project.Items.First(i => i.Name == item.Name), log);
default:
Expand Down
2 changes: 2 additions & 0 deletions src/SerialLoops/Editors/BackgroundEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using HaruhiChokuretsuLib.Util;
using SerialLoops.Utility;
using SerialLoops.Lib.Items;
using System.Linq;

namespace SerialLoops.Editors
{
Expand All @@ -22,6 +23,7 @@ public override Panel GetEditorPanel()
Items =
{
new ImageView() { Image = new SKGuiImage(_bg.GetBackground()) },
$"Used in the following scripts: {string.Join(", ", _bg.ScriptUses.Select(s => s.ScriptName))}",
}
};
}
Expand Down
103 changes: 103 additions & 0 deletions src/SerialLoops/Editors/PuzzleEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using Eto.Forms;
using HaruhiChokuretsuLib.Archive.Data;
using HaruhiChokuretsuLib.Util;
using SerialLoops.Lib.Items;
using SerialLoops.Utility;
using System.Linq;

namespace SerialLoops.Editors
{
public class PuzzleEditor : Editor
{
private PuzzleItem _puzzle;

public PuzzleEditor(PuzzleItem item, ILogger log) : base(item, log)
{
}

public override Panel GetEditorPanel()
{
_puzzle = (PuzzleItem)Description;
StackLayout mainLayout = new()
{
Orientation = Orientation.Horizontal,
Spacing = 20,
};

StackLayout panel1 = new()
{
Orientation = Orientation.Vertical,
Spacing = 10,
};

GroupBox topicsBox = new() { Text = "Associated Main Topics", Padding = 5 };
StackLayout topics = new() { Orientation = Orientation.Horizontal, Spacing = 5 };
foreach (var (topic, _) in _puzzle.Puzzle.AssociatedTopics.Take(_puzzle.Puzzle.AssociatedTopics.Count - 1))
{
topics.Items.Add(new LinkButton { Text = topic.ToString() });
}
topicsBox.Content = topics;
panel1.Items.Add(topicsBox);

GroupBox haruhiRoutesBox = new() { Text = "Haruhi Routes", Padding = 5 };
StackLayout haruhiRoutes = new() { Orientation = Orientation.Vertical, Spacing = 8 };
foreach (PuzzleHaruhiRoute haruhiRoute in _puzzle.Puzzle.HaruhiRoutes)
{
haruhiRoutes.Items.Add(haruhiRoute.ToString());
}
haruhiRoutesBox.Content = haruhiRoutes;
panel1.Items.Add(haruhiRoutesBox);

mainLayout.Items.Add(panel1);

DropDown accompanyingCharacterDropdown = new();
accompanyingCharacterDropdown.Items.AddRange(PuzzleItem.Characters.Select(c => new ListItem() { Text = c, Key = c }));
accompanyingCharacterDropdown.SelectedIndex = PuzzleItem.Characters.IndexOf(_puzzle.Puzzle.Settings.AccompanyingCharacter);
DropDown powerCharacter1Dropdown = new();
powerCharacter1Dropdown.Items.AddRange(PuzzleItem.Characters.Select(c => new ListItem() { Text = c, Key = c }));
powerCharacter1Dropdown.SelectedIndex = PuzzleItem.Characters.IndexOf(_puzzle.Puzzle.Settings.PowerCharacter1);
DropDown powerCharacter2Dropdown = new();
powerCharacter2Dropdown.Items.AddRange(PuzzleItem.Characters.Select(c => new ListItem() { Text = c, Key = c }));
powerCharacter2Dropdown.SelectedIndex = PuzzleItem.Characters.IndexOf(_puzzle.Puzzle.Settings.PowerCharacter2);

mainLayout.Items.Add(new StackLayout()
{
Spacing = 10,
HorizontalContentAlignment = HorizontalAlignment.Stretch,
Items =
{
new GroupBox
{
Text = "Settings",
Padding = 5,
Content = new StackLayout
{
Spacing = 10,
VerticalContentAlignment = VerticalAlignment.Center,
HorizontalContentAlignment = HorizontalAlignment.Stretch,
Items =
{
ControlGenerator.GetControlWithLabel("Map ID", new TextBox { Text = _puzzle.Puzzle.Settings.MapId.ToString() }),
ControlGenerator.GetControlWithLabel("Base Time", new TextBox { Text = _puzzle.Puzzle.Settings.BaseTime.ToString() }),
ControlGenerator.GetControlWithLabel("Number of Singularities", new TextBox { Text = _puzzle.Puzzle.Settings.NumSingularities.ToString() }),
ControlGenerator.GetControlWithLabel("Unknown 04", new TextBox { Text = _puzzle.Puzzle.Settings.Unknown04.ToString() }),
ControlGenerator.GetControlWithLabel("Target Number", new TextBox { Text = _puzzle.Puzzle.Settings.TargetNumber.ToString() }),
ControlGenerator.GetControlWithLabel("Continue on Failure", new CheckBox { Checked = _puzzle.Puzzle.Settings.ContinueOnFailure }),
ControlGenerator.GetControlWithLabel("Accompanying Character", accompanyingCharacterDropdown),
ControlGenerator.GetControlWithLabel("Power Character 1", powerCharacter1Dropdown),
ControlGenerator.GetControlWithLabel("Power Character 2", powerCharacter2Dropdown),
ControlGenerator.GetControlWithLabel("Singularity", new SKGuiImage(_puzzle.SingularityImage)),
ControlGenerator.GetControlWithLabel("Topic Set", new TextBox { Text = _puzzle.Puzzle.Settings.TopicSet.ToString() }),
ControlGenerator.GetControlWithLabel("Unknown 15", new TextBox { Text = _puzzle.Puzzle.Settings.Unknown15.ToString() }),
ControlGenerator.GetControlWithLabel("Unknown 16", new TextBox { Text = _puzzle.Puzzle.Settings.Unknown16.ToString() }),
ControlGenerator.GetControlWithLabel("Unknown 17", new TextBox { Text = _puzzle.Puzzle.Settings.Unknown17.ToString() }),
},
},
},
},
});

return mainLayout;
}
}
}
Loading