Skip to content

Commit adbfc26

Browse files
Implement levels dropdown
1 parent 4754674 commit adbfc26

7 files changed

Lines changed: 250 additions & 1 deletion

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
4+
public static class LevelLists
5+
{
6+
public static Dictionary<int, string>? GetLevelNames(string gameFile, string levelListsFolder)
7+
{
8+
string path = Path.Join(levelListsFolder, $"{gameFile}.txt");
9+
10+
if (!File.Exists(path))
11+
return null;
12+
13+
var names = new Dictionary<int, string>();
14+
15+
foreach (var line in File.ReadAllLines(path))
16+
{
17+
var parts = line.Split('=', 2);
18+
if (parts.Length == 2 && int.TryParse(parts[0].Trim(), out int id))
19+
names[id] = parts[1].Trim();
20+
}
21+
22+
return names;
23+
}
24+
25+
private static readonly Dictionary<string, string> GAME_IDS = new() {
26+
{ "NPEA00385", "RC1" },
27+
{ "NPUA80643", "RC1" },
28+
{ "NPEA00386", "RC2" },
29+
{ "NPUA80644", "RC2" },
30+
{ "NPEA00387", "RC3" },
31+
{ "NPUA80645", "RC3" },
32+
{ "NPEA00423", "RC4" },
33+
{ "NPUA80646", "RC4" },
34+
};
35+
public static string? DetectGameFile(string path)
36+
{
37+
foreach (var entry in GAME_IDS)
38+
if (path.Contains(entry.Key))
39+
return entry.Value;
40+
return null;
41+
}
42+
}

Replanetizer/LevelLists/RC1.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
0=Veldin
2+
1=Novalis
3+
2=Aridia
4+
3=Kerwan
5+
4=Eudora
6+
5=Rilgar
7+
6=Blarg
8+
7=Umbris
9+
8=Batalia
10+
9=Gaspar
11+
10=Orxon
12+
11=Pokitaru
13+
12=Hoven
14+
13=Gemlik Base
15+
14=Oltanis
16+
15=Quartu
17+
16=Kalebo III
18+
17=Drek's Fleet
19+
18=Veldin 2

Replanetizer/LevelLists/RC2.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
0=Aranos
2+
1=Oozla
3+
2=Maktar Nebula
4+
3=Endako
5+
4=Barlow
6+
5=Feltzin
7+
6=Notak
8+
7=Siberius
9+
8=Tabora
10+
9=Dobbo
11+
10=Hrugis Cloud
12+
11=Joba
13+
12=Todano
14+
13=Boldan
15+
14=Aranos 2
16+
15=Gorn
17+
16=Snivelak
18+
17=Smolg
19+
18=Damosel
20+
19=Grelbin
21+
20=Yeedil
22+
21=Insomniac Museum
23+
22=Dobbo Orbit
24+
23=Damosel Orbit
25+
24=Ship Shack
26+
25=Wupash Nebula
27+
26=Jamming Array

Replanetizer/LevelLists/RC3.txt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
1=Veldin
2+
2=Florana
3+
3=Starship Phoenix
4+
4=Marcadia
5+
5=Daxx
6+
6=Phoenix Rescue
7+
7=Annihilation Nation
8+
8=Aquatos
9+
9=Tyhrranosis
10+
10=Zeldrin Starport
11+
11=Obani Gemini
12+
12=Blackwater City
13+
13=Holostar Studios
14+
14=Koros
15+
16=Metropolis
16+
17=Crash Site
17+
18=Aridia
18+
19=Qwark's Hideout
19+
20=Launch Site
20+
21=Obani Draco
21+
22=Command Center
22+
23=Holostar Studios (Clank)
23+
24=Insomniac Museum
24+
26=Metropolis Rangers
25+
27=Aquatos Clank
26+
28=Aquatos Sewers
27+
29=Tyhrranosis Rangers
28+
30=Vid Comic 6
29+
31=Vid Comic 1
30+
32=Vid Comic 4
31+
33=Vid Comic 2
32+
34=Vid Comic 3
33+
35=Vid Comic 5
34+
36=Vid Comic 1 Special Edition
35+
36+
40=Bakisi Isles MP
37+
41=Hoven Gorge MP
38+
42=Outpost X12 MP
39+
43=Korgon Outpost MP
40+
44=Metropolis MP
41+
45=Blackwater City MP
42+
46=Command Center MP
43+
47=Blackwater Docks MP
44+
48=Aquatos Sewers MP
45+
49=Marcadia Palace MP
46+
50=Bakisi Isles MP (Split)
47+
51=Hoven Gorge MP (Split)
48+
52=Outpost X12 MP (Split)
49+
53=Korgon Outpost MP (Split)
50+
54=Metropolis MP (Split)
51+
55=Blackwater City MP (Split)

Replanetizer/LevelLists/RC4.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
1=Dreadzone Station
2+
2=Catacrom Four
3+
4=Sarathos
4+
5=Kronos
5+
6=Shaar
6+
7=Valix Belt
7+
8=Orxon
8+
10=Torval
9+
11=Stygia
10+
13=Maraxus
11+
14=Ghost Station
12+
15=Control Level
13+
21=Dreadzone Station (Co-Op)
14+
22=Catacrom Four (Co-Op)
15+
24=Sarathos (Co-Op)
16+
25=Kronos (Co-Op)
17+
26=Shaar (Co-Op)
18+
27=Valix Belt (Co-Op)
19+
28=Orxon (Co-Op)
20+
30=Torval (Co-Op)
21+
31=Stygia (Co-Op)
22+
33=Maraxus (Co-Op)
23+
34=Ghost Station (Co-Op)
24+
35=Control Level (Co-Op)
25+
26+
41=Battledome Tower MP
27+
42=Catacrom Graveyard MP
28+
44=Sarathos Swamp MP
29+
45=Dark Cathedral MP
30+
46=Temple of Shaar MP
31+
47=Valix Lighthouse MP
32+
48=Mining Facility MP
33+
50=Torval Ruins MP
34+
51=Tempus Station MP
35+
53=Maraxus Prison MP
36+
54=Ghost Station MP
37+
61=Battledome Tower MP (Split)
38+
62=Catacrom Graveyard MP (Split)
39+
64=Sarathos Swamp MP (Split)
40+
65=Dark Cathedral MP (Split)
41+
66=Temple of Shaar MP (Split)
42+
67=Valix Lighthouse MP (Split)
43+
68=Mining Facility MP (Split)
44+
70=Torval Ruins MP (Split)
45+
71=Tempus Station MP (Split)
46+
73=Maraxus Prison MP (Split)
47+
74=Ghost Station MP (Split)

Replanetizer/Replanetizer.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@
5959
<None Update="Icons\Replanetizer.png">
6060
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6161
</None>
62+
<None Update="LevelLists\RC4.txt">
63+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
64+
</None>
65+
<None Update="LevelLists\RC3.txt">
66+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
67+
</None>
68+
<None Update="LevelLists\RC2.txt">
69+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
70+
</None>
6271
<None Update="ModelLists\MobyModelsRC4.txt">
6372
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6473
</None>
@@ -74,6 +83,9 @@
7483
<None Update="ModelLists\TieModelsRC3.txt">
7584
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7685
</None>
86+
<None Update="LevelLists\RC1.txt">
87+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
88+
</None>
7789
<None Update="Resources\blue_noise.png">
7890
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7991
</None>

Replanetizer/Window.cs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ private static bool FrameIsLevel(Frame frame)
140140
{
141141
return frame.GetType() == typeof(LevelFrame);
142142
}
143-
144143
private void RenderMenuBar()
145144
{
146145
if (ImGui.BeginMainMenuBar())
@@ -161,6 +160,11 @@ private void RenderMenuBar()
161160
AddFrame(lf);
162161
}
163162
}
163+
if (ImGui.MenuItem("Open ps3data folder"))
164+
{
165+
var res = CrossFileDialog.OpenFolder();
166+
if (res.Length > 0) TryOpenFolder(res);
167+
}
164168

165169
if (ImGui.MenuItem("Quit"))
166170
{
@@ -169,6 +173,40 @@ private void RenderMenuBar()
169173
ImGui.EndMenu();
170174
}
171175

176+
// Put levels dropdown if it can find the game id in the path.
177+
// This is probably stupid.
178+
// Could probably be better to open the first engine.ps3 files it finds, and then from there maybe work out
179+
// what game it is, since there is a way to detect gametype in the engine parser?
180+
// Ahhhh.... I don't know.
181+
if (activeGameId != null && rootFolder != null)
182+
{
183+
var names = LevelLists.GetLevelNames(activeGameId, levelListsFolder);
184+
if (names != null && ImGui.BeginMenu("Levels"))
185+
{
186+
foreach (var (id, name) in names.OrderBy(x => x.Key))
187+
{
188+
string levelPath = Path.Join(rootFolder, $"level{id}", "engine.ps3");
189+
bool exists = File.Exists(levelPath);
190+
191+
if (!exists)
192+
ImGui.BeginDisabled();
193+
194+
if (ImGui.MenuItem(name))
195+
{
196+
foreach (var frame in openFrames.Where(FrameIsLevel))
197+
frame.Dispose();
198+
199+
openFrames.RemoveAll(FrameIsLevel);
200+
openFrames.Add(new LevelFrame(this, levelPath));
201+
}
202+
203+
if (!exists)
204+
ImGui.EndDisabled();
205+
}
206+
ImGui.EndMenu();
207+
}
208+
}
209+
172210
if (ImGui.BeginMenu("About"))
173211
{
174212
if (ImGui.MenuItem("About Replanetizer"))
@@ -186,6 +224,19 @@ private void RenderMenuBar()
186224
}
187225
}
188226

227+
private string? rootFolder = null;
228+
private string? activeGameId = null;
229+
private string levelListsFolder = Path.Join(AppContext.BaseDirectory, "LevelLists");
230+
private void TryOpenFolder(string folder)
231+
{
232+
string? gameId = LevelLists.DetectGameFile(folder);
233+
if (gameId == null)
234+
return;
235+
236+
rootFolder = folder;
237+
activeGameId = gameId;
238+
}
239+
189240
private void RenderUI(float deltaTime)
190241
{
191242
RenderMenuBar();

0 commit comments

Comments
 (0)