改进对15*15样板的支持
This commit is contained in:
parent
8bb1a552cc
commit
56e17d0292
4
App.xaml
4
App.xaml
@ -1,7 +1,7 @@
|
|||||||
<Application x:Class="WpfApp7.App"
|
<Application x:Class="Migrator.App"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:local="clr-namespace:WpfApp7"
|
xmlns:local="clr-namespace:Migrator"
|
||||||
StartupUri="MainWindow.xaml">
|
StartupUri="MainWindow.xaml">
|
||||||
<Application.Resources>
|
<Application.Resources>
|
||||||
|
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
|
||||||
namespace WpfApp7
|
namespace Migrator
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interaction logic for App.xaml
|
/// Interaction logic for App.xaml
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class App : Application
|
public partial class App : System.Windows.Application
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<UseWPF>true</UseWPF>
|
<UseWPF>true</UseWPF>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -131,14 +131,26 @@ namespace H5MotaUpdate.ViewModels
|
|||||||
if (!CheckValid()) return;
|
if (!CheckValid()) return;
|
||||||
Version ver;
|
Version ver;
|
||||||
Version.TryParse(VersionString, out ver);
|
Version.TryParse(VersionString, out ver);
|
||||||
int width = StringUtils.ReadMapWidth(Path.Combine(SourceRootDirectory, "libs/core.js"));
|
|
||||||
|
#region
|
||||||
|
// 从libs/core.js中读取塔的默认长宽,若不为13,需要写入新样板的core.js中
|
||||||
|
int width, height;
|
||||||
|
string sourceCoreJSPath = Path.Combine(SourceRootDirectory, "libs/core.js"),
|
||||||
|
destCoreJSPath = Path.Combine(DestRootDirectory, "libs/core.js");
|
||||||
|
(width, height) = StringUtils.ReadMapWidth(sourceCoreJSPath);
|
||||||
|
|
||||||
|
if (width != 13 || height != 13)
|
||||||
|
{
|
||||||
|
StringUtils.WriteMapWidth(destCoreJSPath, width, height);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
DataJSMigrator dataJSMigrator = new(SourceProjectDirectory, DestProjectDirectroy, ver);
|
DataJSMigrator dataJSMigrator = new(SourceProjectDirectory, DestProjectDirectroy, ver);
|
||||||
EnemysJSMigrator enemysJSMigrator = new(SourceProjectDirectory, DestProjectDirectroy, ver);
|
EnemysJSMigrator enemysJSMigrator = new(SourceProjectDirectory, DestProjectDirectroy, ver);
|
||||||
IconsJSMigrator iconsJSMigrator = new(SourceProjectDirectory, DestProjectDirectroy, ver);
|
IconsJSMigrator iconsJSMigrator = new(SourceProjectDirectory, DestProjectDirectroy, ver);
|
||||||
ItemsJSMigrator itemsJSMigrator = new(SourceProjectDirectory, DestProjectDirectroy, ver);
|
ItemsJSMigrator itemsJSMigrator = new(SourceProjectDirectory, DestProjectDirectroy, ver);
|
||||||
MapsJSMigrator mapsJSMigrator = new(SourceProjectDirectory, DestProjectDirectroy, ver);
|
MapsJSMigrator mapsJSMigrator = new(SourceProjectDirectory, DestProjectDirectroy, ver);
|
||||||
FloorsMigrator floorsMigrator = new(SourceProjectDirectory, DestProjectDirectroy, ver, width);
|
FloorsMigrator floorsMigrator = new(SourceProjectDirectory, DestProjectDirectroy, ver, width, height);
|
||||||
MediaSourceMigrator mediaSourceJSMigrator = new(SourceProjectDirectory, DestProjectDirectroy, ver);
|
MediaSourceMigrator mediaSourceJSMigrator = new(SourceProjectDirectory, DestProjectDirectroy, ver);
|
||||||
|
|
||||||
dataJSMigrator.Migrate();
|
dataJSMigrator.Migrate();
|
||||||
|
@ -27,17 +27,18 @@ namespace H5MotaUpdate.ViewModels
|
|||||||
Version version;
|
Version version;
|
||||||
readonly string FILENAME = "floors";
|
readonly string FILENAME = "floors";
|
||||||
string?[] mapsIndexArray;
|
string?[] mapsIndexArray;
|
||||||
int mapWidth = 13;
|
int mapWidth, mapHeight;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 请输入新旧Project文件夹的路径
|
/// 请输入新旧Project文件夹的路径
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FloorsMigrator(string oldProjectDirectory, string newProjectDirectory, Version ver, int width)
|
public FloorsMigrator(string oldProjectDirectory, string newProjectDirectory, Version ver, int width, int height)
|
||||||
{
|
{
|
||||||
sourcePath = System.IO.Path.Combine(oldProjectDirectory, FILENAME);
|
sourcePath = System.IO.Path.Combine(oldProjectDirectory, FILENAME);
|
||||||
destPath = System.IO.Path.Combine(newProjectDirectory, FILENAME);
|
destPath = System.IO.Path.Combine(newProjectDirectory, FILENAME);
|
||||||
this.version = ver;
|
this.version = ver;
|
||||||
this.mapWidth = width;
|
this.mapWidth = width;
|
||||||
|
this.mapHeight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Migrate(string?[] mapsIndexArray)
|
public void Migrate(string?[] mapsIndexArray)
|
||||||
@ -104,10 +105,20 @@ namespace H5MotaUpdate.ViewModels
|
|||||||
jsonObject["canFlyFrom"] = jsonObject["canFlyTo"];
|
jsonObject["canFlyFrom"] = jsonObject["canFlyTo"];
|
||||||
jsonObject["ratio"] = jsonObject["item_ratio"];
|
jsonObject["ratio"] = jsonObject["item_ratio"];
|
||||||
jsonObject.Remove("item_ratio");
|
jsonObject.Remove("item_ratio");
|
||||||
jsonObject["width"] = mapWidth;
|
|
||||||
jsonObject["height"] = mapWidth;
|
|
||||||
jsonObject["autoEvent"] = new JObject();
|
jsonObject["autoEvent"] = new JObject();
|
||||||
|
|
||||||
|
// 设置每张地图的尺寸。如果自己有就用自己的,否则设为默认长宽。
|
||||||
|
JToken width = jsonObject["width"],
|
||||||
|
height = jsonObject["height"];
|
||||||
|
if (width == null)
|
||||||
|
{
|
||||||
|
jsonObject["width"] = mapWidth;
|
||||||
|
}
|
||||||
|
if (height == null)
|
||||||
|
{
|
||||||
|
jsonObject["height"] = mapHeight;
|
||||||
|
}
|
||||||
|
|
||||||
#region
|
#region
|
||||||
// 楼层贴图:老版本为一字符串或数组,字符串会被自动转为[0,0,str]
|
// 楼层贴图:老版本为一字符串或数组,字符串会被自动转为[0,0,str]
|
||||||
// 其中t[0],t[1]分别为x,y,t[2]为贴图名字 剩下的不知道干嘛的
|
// 其中t[0],t[1]分别为x,y,t[2]为贴图名字 剩下的不知道干嘛的
|
||||||
|
@ -144,31 +144,84 @@ namespace H5MotaUpdate.ViewModels
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 读取塔的地图尺寸,默认值为13
|
/// 读取塔的地图尺寸,默认值为13
|
||||||
/// <summary>
|
/// <summary>
|
||||||
public static int ReadMapWidth(string filePath)
|
public static (int, int) ReadMapWidth(string filePath)
|
||||||
{
|
{
|
||||||
int width;
|
/*
|
||||||
|
* 直到2.9为止,地图默认尺寸在libs/core.js中 this.__SIZE__ = 13
|
||||||
|
* 老版本写法如下:this.bigmap = {
|
||||||
|
* width: 13, // map width and height
|
||||||
|
* height: 13,
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
int width, height;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string fileContent = File.ReadAllText(filePath);
|
string fileContent = File.ReadAllText(filePath);
|
||||||
|
|
||||||
string widthPattern = @"this\._WIDTH_\s*=\s*(\d+);";
|
// gpt写的,我也看不懂,就当它们是对的,有错再说
|
||||||
|
string widthPattern = @"this\._WIDTH_\s*=\s*(\d+);",
|
||||||
|
heightPattern = @"this\._HEIGHT_\s*=\s*(\d+);",
|
||||||
|
sizePattern = @"this\.__SIZE__\s*=\s*(\d+);",
|
||||||
|
oldSizePattern = @"this\.bigmap\s*=\s*\{[^}]*width:\s*(\d+)[^}]*height:\s*(\d+)[^}]*\}";
|
||||||
|
|
||||||
Match widthMatch = Regex.Match(fileContent, widthPattern);
|
Match widthMatch = Regex.Match(fileContent, widthPattern),
|
||||||
|
heightMatch = Regex.Match(fileContent, heightPattern);
|
||||||
if (widthMatch.Success)
|
if (widthMatch.Success && heightMatch.Success)
|
||||||
{
|
{
|
||||||
width = int.Parse(widthMatch.Groups[1].Value);
|
width = int.Parse(widthMatch.Groups[1].Value);
|
||||||
|
height = int.Parse(heightMatch.Groups[1].Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Match sizeMatch = Regex.Match(fileContent, sizePattern);
|
||||||
|
if (sizeMatch.Success)
|
||||||
|
{
|
||||||
|
width = int.Parse(sizeMatch.Groups[1].Value);
|
||||||
|
height = width;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Match oldWidthMatch = Regex.Match(fileContent, oldSizePattern);
|
||||||
|
if (oldWidthMatch.Success)
|
||||||
|
{
|
||||||
|
width = int.Parse(oldWidthMatch.Groups[1].Value);
|
||||||
|
height = int.Parse(oldWidthMatch.Groups[2].Value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
width = 13;
|
width = 13;
|
||||||
|
height = 13;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
width = 13;
|
width = 13;
|
||||||
|
height = 13;
|
||||||
|
}
|
||||||
|
return (width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 将塔的地图尺寸写入libs/core.js
|
||||||
|
/// <summary>
|
||||||
|
public static void WriteMapWidth(string destFilePath, int width, int height)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
|
||||||
|
string tempFilePath = destFilePath + ".tmp";
|
||||||
|
string fileContent = File.ReadAllText(destFilePath);
|
||||||
|
fileContent = Regex.Replace(fileContent, @"this\._WIDTH_\s*=\s*\d+;", $"this._WIDTH_ = {width};");
|
||||||
|
fileContent = Regex.Replace(fileContent, @"this\._HEIGHT_\s*=\s*\d+;", $"this._HEIGHT_ = {height};");
|
||||||
|
File.WriteAllText(tempFilePath, fileContent);
|
||||||
|
File.Delete(destFilePath);
|
||||||
|
File.Move(tempFilePath, destFilePath);
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
|
||||||
}
|
}
|
||||||
return width;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user