改进对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:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:WpfApp7"
|
||||
xmlns:local="clr-namespace:Migrator"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
|
@ -2,12 +2,12 @@
|
||||
using System.Data;
|
||||
using System.Windows;
|
||||
|
||||
namespace WpfApp7
|
||||
namespace Migrator
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
public partial class App : System.Windows.Application
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWPF>true</UseWPF>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -131,14 +131,26 @@ namespace H5MotaUpdate.ViewModels
|
||||
if (!CheckValid()) return;
|
||||
Version 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);
|
||||
EnemysJSMigrator enemysJSMigrator = new(SourceProjectDirectory, DestProjectDirectroy, ver);
|
||||
IconsJSMigrator iconsJSMigrator = new(SourceProjectDirectory, DestProjectDirectroy, ver);
|
||||
ItemsJSMigrator itemsJSMigrator = 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);
|
||||
|
||||
dataJSMigrator.Migrate();
|
||||
|
@ -27,17 +27,18 @@ namespace H5MotaUpdate.ViewModels
|
||||
Version version;
|
||||
readonly string FILENAME = "floors";
|
||||
string?[] mapsIndexArray;
|
||||
int mapWidth = 13;
|
||||
int mapWidth, mapHeight;
|
||||
|
||||
/// <summary>
|
||||
/// 请输入新旧Project文件夹的路径
|
||||
/// </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);
|
||||
destPath = System.IO.Path.Combine(newProjectDirectory, FILENAME);
|
||||
this.version = ver;
|
||||
this.mapWidth = width;
|
||||
this.mapHeight = height;
|
||||
}
|
||||
|
||||
public void Migrate(string?[] mapsIndexArray)
|
||||
@ -104,10 +105,20 @@ namespace H5MotaUpdate.ViewModels
|
||||
jsonObject["canFlyFrom"] = jsonObject["canFlyTo"];
|
||||
jsonObject["ratio"] = jsonObject["item_ratio"];
|
||||
jsonObject.Remove("item_ratio");
|
||||
jsonObject["width"] = mapWidth;
|
||||
jsonObject["height"] = mapWidth;
|
||||
jsonObject["autoEvent"] = new JObject();
|
||||
|
||||
// 设置每张地图的尺寸。如果自己有就用自己的,否则设为默认长宽。
|
||||
JToken width = jsonObject["width"],
|
||||
height = jsonObject["height"];
|
||||
if (width == null)
|
||||
{
|
||||
jsonObject["width"] = mapWidth;
|
||||
}
|
||||
if (height == null)
|
||||
{
|
||||
jsonObject["height"] = mapHeight;
|
||||
}
|
||||
|
||||
#region
|
||||
// 楼层贴图:老版本为一字符串或数组,字符串会被自动转为[0,0,str]
|
||||
// 其中t[0],t[1]分别为x,y,t[2]为贴图名字 剩下的不知道干嘛的
|
||||
|
@ -144,31 +144,84 @@ namespace H5MotaUpdate.ViewModels
|
||||
/// <summary>
|
||||
/// 读取塔的地图尺寸,默认值为13
|
||||
/// <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
|
||||
{
|
||||
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);
|
||||
|
||||
if (widthMatch.Success)
|
||||
Match widthMatch = Regex.Match(fileContent, widthPattern),
|
||||
heightMatch = Regex.Match(fileContent, heightPattern);
|
||||
if (widthMatch.Success && heightMatch.Success)
|
||||
{
|
||||
width = int.Parse(widthMatch.Groups[1].Value);
|
||||
height = int.Parse(heightMatch.Groups[1].Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
width = 13;
|
||||
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
|
||||
{
|
||||
width = 13;
|
||||
height = 13;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
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