mirror of
https://github.com/kwsch/NHSE.git
synced 2026-09-26 20:07:11 -05:00
Add handling for revised player house and room structure (v2.0) (#547)
* Add handling for revised player house and room structure (v2.0) * Update player room load/dump file type filters
This commit is contained in:
@@ -96,7 +96,7 @@ public static bool LoadMuseum(Museum museum)
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void DumpHouse(IReadOnlyList<Player> players, IReadOnlyList<PlayerHouse> houses, int index, bool dumpAll)
|
||||
public static void DumpHouse(IReadOnlyList<Player> players, IReadOnlyList<IPlayerHouse> houses, int index, bool dumpAll)
|
||||
{
|
||||
if (dumpAll)
|
||||
DumpAllPlayerHouses(houses, players);
|
||||
@@ -104,23 +104,25 @@ public static void DumpHouse(IReadOnlyList<Player> players, IReadOnlyList<Player
|
||||
DumpPlayerHouse(players, houses, index);
|
||||
}
|
||||
|
||||
private static void DumpPlayerHouse(IReadOnlyList<Player> players, IReadOnlyList<PlayerHouse> houses, int index)
|
||||
private static void DumpPlayerHouse(IReadOnlyList<Player> players, IReadOnlyList<IPlayerHouse> houses, int index)
|
||||
{
|
||||
var house = houses[index];
|
||||
var name = PlayerHouseEditor.GetHouseSummary(players, house, index);
|
||||
using var sfd = new SaveFileDialog
|
||||
{
|
||||
Filter = "New Horizons Player House (*.nhph)|*.nhph|All files (*.*)|*.*",
|
||||
FileName = $"{name}.nhph",
|
||||
Filter = "New Horizons Player House (*.nhph)|*.nhph|" +
|
||||
"New Horizons Player House (*.nhph2)|*.nhph2|" +
|
||||
"All files (*.*)|*.*",
|
||||
FileName = $"{name}.{house.Extension}",
|
||||
};
|
||||
if (sfd.ShowDialog() != DialogResult.OK)
|
||||
return;
|
||||
|
||||
var data = house.Data;
|
||||
var data = house.Write();
|
||||
File.WriteAllBytes(sfd.FileName, data);
|
||||
}
|
||||
|
||||
private static void DumpAllPlayerHouses(IReadOnlyList<PlayerHouse> houses, IReadOnlyList<Player> players)
|
||||
private static void DumpAllPlayerHouses(IReadOnlyList<IPlayerHouse> houses, IReadOnlyList<Player> players)
|
||||
{
|
||||
using var fbd = new FolderBrowserDialog();
|
||||
if (fbd.ShowDialog() != DialogResult.OK)
|
||||
@@ -132,69 +134,90 @@ private static void DumpAllPlayerHouses(IReadOnlyList<PlayerHouse> houses, IRead
|
||||
houses.DumpPlayerHouses(players, fbd.SelectedPath);
|
||||
}
|
||||
|
||||
public static bool LoadHouse(IReadOnlyList<Player> players, PlayerHouse[] houses, int index)
|
||||
public static bool LoadHouse(MainSaveOffsets offsets, IReadOnlyList<Player> players, IPlayerHouse[] houses, int index)
|
||||
{
|
||||
var h = houses[index];
|
||||
var name = PlayerHouseEditor.GetHouseSummary(players, houses[index], index);
|
||||
using var ofd = new OpenFileDialog
|
||||
{
|
||||
Filter = "New Horizons Player House (*.nhph)|*.nhph|All files (*.*)|*.*",
|
||||
FileName = $"{name}.nhph",
|
||||
Filter = "New Horizons Player House (*.nhph)|*.nhph|" +
|
||||
"New Horizons Player House (*.nhph2)|*.nhph2|" +
|
||||
"All files (*.*)|*.*",
|
||||
FileName = $"{name}.{h.Extension}",
|
||||
};
|
||||
if (ofd.ShowDialog() != DialogResult.OK)
|
||||
return false;
|
||||
|
||||
var file = ofd.FileName;
|
||||
var fi = new FileInfo(file);
|
||||
const int expectLength = PlayerHouse.SIZE;
|
||||
if (fi.Length != expectLength)
|
||||
var path = ofd.FileName;
|
||||
var expectLength = offsets.PlayerHouseSize;
|
||||
var fi = new FileInfo(path);
|
||||
if (!VillagerHouseConverter.IsCompatible((int)fi.Length, expectLength))
|
||||
{
|
||||
WinFormsUtil.Error(MessageStrings.MsgCanceling, string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength));
|
||||
WinFormsUtil.Error(string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength), path);
|
||||
return false;
|
||||
}
|
||||
|
||||
var data = File.ReadAllBytes(file);
|
||||
var h = new PlayerHouse(data);
|
||||
var data = File.ReadAllBytes(ofd.FileName);
|
||||
data = PlayerHouseConverter.GetCompatible(data, expectLength);
|
||||
if (fi.Length != expectLength)
|
||||
{
|
||||
WinFormsUtil.Error(MessageStrings.MsgCanceling, string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength), path);
|
||||
return false;
|
||||
}
|
||||
|
||||
h = offsets.ReadPlayerHouse(data);
|
||||
var current = houses[index];
|
||||
h.NPC1 = current.NPC1;
|
||||
houses[index] = h;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void DumpRoom(PlayerRoom room, int index)
|
||||
public static void DumpRoom(IPlayerRoom room, int index)
|
||||
{
|
||||
using var sfd = new SaveFileDialog
|
||||
{
|
||||
Filter = "New Horizons Player House Room (*.nhpr)|*.nhpr|All files (*.*)|*.*",
|
||||
FileName = $"Room {index + 1}.nhpr",
|
||||
Filter = "New Horizons Player House Room (*.nhpr)|*.nhpr|" +
|
||||
"New Horizons Player House Room (*.nhpr2)|*.nhpr2|" +
|
||||
"All files (*.*)|*.*",
|
||||
FileName = $"Room {index + 1}.{room.Extension}",
|
||||
};
|
||||
if (sfd.ShowDialog() != DialogResult.OK)
|
||||
return;
|
||||
|
||||
var data = room.Data;
|
||||
var data = room.Write();
|
||||
File.WriteAllBytes(sfd.FileName, data);
|
||||
}
|
||||
|
||||
public static bool LoadRoom(PlayerRoom room, int index)
|
||||
public static bool LoadRoom(MainSaveOffsets offsets, IPlayerRoom room, int index)
|
||||
{
|
||||
using var ofd = new OpenFileDialog
|
||||
{
|
||||
Filter = "New Horizons Player House Room (*.nhpr)|*.nhpr|All files (*.*)|*.*",
|
||||
FileName = $"Room {index + 1}.nhpr",
|
||||
Filter = "New Horizons Player House Room (*.nhpr)|*.nhpr|" +
|
||||
"New Horizons Player House Room (*.nhpr2)|*.nhpr2|" +
|
||||
"All files (*.*)|*.*",
|
||||
FileName = $"Room {index + 1}.{room.Extension}",
|
||||
};
|
||||
if (ofd.ShowDialog() != DialogResult.OK)
|
||||
return false;
|
||||
|
||||
var file = ofd.FileName;
|
||||
var fi = new FileInfo(file);
|
||||
const int expectLength = PlayerRoom.SIZE;
|
||||
if (fi.Length != expectLength)
|
||||
var path = ofd.FileName;
|
||||
var expectLength = offsets.PlayerRoomSize;
|
||||
var fi = new FileInfo(path);
|
||||
if (!PlayerRoomConverter.IsCompatible((int)fi.Length, expectLength))
|
||||
{
|
||||
WinFormsUtil.Error(MessageStrings.MsgCanceling, string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength));
|
||||
WinFormsUtil.Error(string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength), path);
|
||||
return false;
|
||||
}
|
||||
|
||||
var data = File.ReadAllBytes(file);
|
||||
data.CopyTo(room.Data, 0);
|
||||
var data = File.ReadAllBytes(ofd.FileName);
|
||||
data = PlayerRoomConverter.GetCompatible(data, offsets.PlayerRoomSize);
|
||||
if (fi.Length != expectLength)
|
||||
{
|
||||
WinFormsUtil.Error(MessageStrings.MsgCanceling, string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength), path);
|
||||
return false;
|
||||
}
|
||||
|
||||
room = offsets.ReadPlayerRoom(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ namespace NHSE.WinForms
|
||||
{
|
||||
public partial class PlayerHouseEditor : Form
|
||||
{
|
||||
private readonly PlayerHouse[] Houses;
|
||||
private readonly MainSave SAV;
|
||||
private readonly IPlayerHouse[] Houses;
|
||||
private readonly IReadOnlyList<Player> Players;
|
||||
private RoomItemManager Manager;
|
||||
private const int scale = 24;
|
||||
@@ -17,10 +18,11 @@ public partial class PlayerHouseEditor : Form
|
||||
private int Index = -1;
|
||||
private int RoomIndex = -1;
|
||||
|
||||
public PlayerHouseEditor(PlayerHouse[] houses, IReadOnlyList<Player> players, int index)
|
||||
public PlayerHouseEditor(IPlayerHouse[] houses, IReadOnlyList<Player> players, MainSave sav, int index)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.TranslateInterface(GameInfo.CurrentLanguage);
|
||||
SAV = sav;
|
||||
Houses = houses;
|
||||
Players = players;
|
||||
Manager = new RoomItemManager(houses[0].GetRoom(0));
|
||||
@@ -73,7 +75,7 @@ private void PG_Item_PropertyValueChanged(object s, PropertyValueChangedEventArg
|
||||
LB_Items.Items[Index] = GetHouseSummary(Players, Houses[Index], Index);
|
||||
}
|
||||
|
||||
public static string GetHouseSummary(IReadOnlyList<Player> players, PlayerHouse house, int index)
|
||||
public static string GetHouseSummary(IReadOnlyList<Player> players, IPlayerHouse house, int index)
|
||||
{
|
||||
var houseName = index >= players.Count ? $"House {index}" : $"{players[index].Personal.PlayerName}'s House";
|
||||
return $"{houseName} (lv {house.HouseLevel})";
|
||||
@@ -86,7 +88,7 @@ private void B_DumpHouse_Click(object sender, EventArgs e)
|
||||
|
||||
private void B_LoadHouse_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!MiscDumpHelper.LoadHouse(Players, Houses, Index))
|
||||
if (!MiscDumpHelper.LoadHouse(SAV.Offsets, Players, Houses, Index))
|
||||
return;
|
||||
|
||||
RoomIndex = -1;
|
||||
@@ -141,14 +143,14 @@ private static void GetCoordinates(MouseEventArgs e, out int x, out int y)
|
||||
y = e.Y / scale;
|
||||
}
|
||||
|
||||
private void ChangeRoom(PlayerHouse house)
|
||||
private void ChangeRoom(IPlayerHouse house)
|
||||
{
|
||||
RoomIndex = (int) NUD_Room.Value - 1;
|
||||
ReloadManager(house);
|
||||
DrawLayer();
|
||||
}
|
||||
|
||||
private void ReloadManager(PlayerHouse house)
|
||||
private void ReloadManager(IPlayerHouse house)
|
||||
{
|
||||
var unsupported = Manager.GetUnsupportedTiles();
|
||||
if (unsupported.Count != 0)
|
||||
@@ -300,7 +302,7 @@ private void DeleteTile(Item tile, int x, int y)
|
||||
private void B_LoadRoom_Click(object sender, EventArgs e)
|
||||
{
|
||||
var room = Manager.Room;
|
||||
MiscDumpHelper.LoadRoom(room, RoomIndex);
|
||||
MiscDumpHelper.LoadRoom(SAV.Offsets, room, RoomIndex);
|
||||
|
||||
var house = Houses[Index];
|
||||
house.SetRoom(RoomIndex, room);
|
||||
|
||||
Reference in New Issue
Block a user