Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ HMM使用基于CSV变种的HMM格式文件,便于阅读,以行为单位,

## 对比/补丁文件

作为专业的地图数据维护工具,HMM支持对地图文件进行对比,查看数据中更改过的地方,选择性的合并数据,并能将变更内容到处为.hmp补丁文件。
作为专业的地图数据维护工具,HMM支持对地图文件进行对比,查看数据中更改过的地方,选择性的合并数据,并能将变更内容导出为.hmp补丁文件。

![地图对比](doc/images/diff.png)

Expand Down
6 changes: 6 additions & 0 deletions code/HellMapManager/Assets/translate.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@
<x:String x:Key="StringManagedFileChooserOverwritePromptFileAlreadyExistsText">{0}个文件已经存在,您是否想替换它?</x:String>
<x:String x:Key="StringManagedFileChooserOverwritePromptConfirmText">是</x:String>
<x:String x:Key="StringManagedFileChooserOverwritePromptCancelText">否</x:String>
<x:String x:Key="ModelFilterTooltip">使用英文逗号分隔多个关键字。
可以使用 类型=来进行精确匹配,例如 name=入口 表示只匹配名称完全等于“入口”的项目。
类型为空可以进行全类型精确匹配。
前置英文感叹号表示排除。
支持的类型为:key|name|desc|tag|group|to|command|message|misc。
支持用\进行转义。</x:String>
</ResourceDictionary>
28 changes: 21 additions & 7 deletions code/HellMapManager/Cores/MapDatabase.API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -741,13 +741,15 @@ public void APIRemoveVariables(List<string> keys)
_lock.ExitWriteLock();
}
}
public QueryResult? APIQueryPathAny(List<string> from, List<string> target, Context context, MapperOptions options)
public QueryResult? APIQueryPathAny(List<string> from, List<string> target, Context? context, MapperOptions? options)
{
_lock.EnterReadLock();
try
{
if (Current != null)
{
context ??= new Context();
options ??= new MapperOptions();
return new Walking(new Mapper(Current, context, options)).QueryPathAny(from, target, 0).SuccessOrNull();
}
}
Expand All @@ -758,13 +760,15 @@ public void APIRemoveVariables(List<string> keys)
return null;
}

public QueryResult? APIQueryPathAll(string start, List<string> target, Context context, MapperOptions options)
public QueryResult? APIQueryPathAll(string start, List<string> target, Context? context, MapperOptions? options)
{
_lock.EnterReadLock();
try
{
if (Current != null)
{
context ??= new Context();
options ??= new MapperOptions();
return new Walking(new Mapper(Current, context, options)).QueryPathAll(start, target).SuccessOrNull();
}
}
Expand All @@ -774,13 +778,15 @@ public void APIRemoveVariables(List<string> keys)
}
return null;
}
public QueryResult? APIQueryPathOrdered(string start, List<string> target, Context context, MapperOptions options)
public QueryResult? APIQueryPathOrdered(string start, List<string> target, Context? context, MapperOptions? options)
{
_lock.EnterReadLock();
try
{
if (Current != null)
{
context ??= new Context();
options ??= new MapperOptions();
return new Walking(new Mapper(Current, context, options)).QueryPathOrdered(start, target).SuccessOrNull();
}
}
Expand Down Expand Up @@ -848,13 +854,15 @@ public List<string> APIQueryRegionRooms(string key)
return [];
}

public List<string> APIDilate(List<string> src, int iterations, Context context, MapperOptions options)
public List<string> APIDilate(List<string> src, int iterations, Context? context, MapperOptions? options)
{
_lock.EnterReadLock();
try
{
if (Current != null)
{
context ??= new Context();
options ??= new MapperOptions();
return new Walking(new Mapper(Current, context, options)).Dilate(src, iterations);
}
}
Expand All @@ -864,13 +872,15 @@ public List<string> APIDilate(List<string> src, int iterations, Context context,
}
return [];
}
public string APITrackExit(string start, string command, Context context, MapperOptions options)
public string APITrackExit(string start, string command, Context? context, MapperOptions? options)
{
_lock.EnterReadLock();
try
{
if (Current != null)
{
context ??= new Context();
options ??= new MapperOptions();
var mapper = new Mapper(Current, context, options);
var room = mapper.GetRoom(start);
if (room is not null)
Expand Down Expand Up @@ -911,13 +921,15 @@ public string APIGetVariable(string key)
}
return "";
}
public Room? APIGetRoom(string key, Context context, MapperOptions options)
public Room? APIGetRoom(string key, Context? context, MapperOptions? options)
{
_lock.EnterReadLock();
try
{
if (Current != null)
{
context ??= new Context();
options ??= new MapperOptions();
return new Mapper(Current, context, options).GetRoom(key);
}
}
Expand Down Expand Up @@ -1147,13 +1159,15 @@ public void APIGroupRoom(string key, string group)
_lock.ExitWriteLock();
}
}
public List<Exit> APIGetRoomExits(string key, Context context, MapperOptions options)
public List<Exit> APIGetRoomExits(string key, Context? context, MapperOptions? options)
{
_lock.EnterReadLock();
try
{
if (Current != null)
{
context ??= new Context();
options ??= new MapperOptions();
var mapper = new Mapper(Current, context, options);
var room = mapper.GetRoom(key);
if (room is not null)
Expand Down
2 changes: 1 addition & 1 deletion code/HellMapManager/Cores/MapDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace HellMapManager.Cores;
public partial class MapDatabase()
{
public ReaderWriterLockSlim _lock = new();
public const int Version = 1003;
public const int Version = 1004;
public MapFile? Current;
public Settings Settings = new();

Expand Down
75 changes: 75 additions & 0 deletions code/HellMapManager/Helpers/FilterHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

using System;
using System.Collections.Generic;
using System.Linq;
using HellMapManager.Models;
using HellMapManager.Utils.ControlCode;

namespace HellMapManager.Helpers;

public class FilterHelper
{
const string TypeKey = "key";
const string TypeName = "name";
const string TypeTo = "to";
const string TypeTag = "tag";
const string TypeCommand = "command";
const string TypeGroup = "group";
const string TypeType = "type";
const string TypeValue = "value";
const string TypeDesc = "desc";
const string TypeMisc = "misc";

const string TypeMessage = "message";
static readonly ControlCode escaper = new ControlCode().
WithCommand(new Command("\\", "0", "\\\\")).
WithCommand(new Command("\n", "1", "\\n")).
WithCommand(new Command(",", "2", "\\,")).
WithCommand(new Command("=", "3", "\\=")).
WithCommand(new Command(" ", "4", "\\ ")).
WithCommand(new Command("!", "5", "\\!"));

public static FilterKeyword ParseKeyword(string unpacked)
{
var keyword = new FilterKeyword();
if (unpacked.StartsWith("!"))
{
keyword.Not = true;
unpacked = unpacked[1..];
}
var data = unpacked.Split(['='], 2);
if (data.Length > 1)
{
keyword.Type = escaper.Decode(data[0].Trim()) switch
{
"" => FilterKeywordType.Any,
TypeKey => FilterKeywordType.Key,
TypeName => FilterKeywordType.Name,
TypeTo => FilterKeywordType.To,
TypeTag => FilterKeywordType.Tag,
TypeCommand => FilterKeywordType.Command,
TypeGroup => FilterKeywordType.Group,
TypeMisc => FilterKeywordType.Misc,
TypeType => FilterKeywordType.Type,
TypeDesc => FilterKeywordType.Desc,
TypeValue => FilterKeywordType.Value,
TypeMessage => FilterKeywordType.Message,
_ => FilterKeywordType.Wrong,
};
keyword.Value = escaper.Decode(data[1]);
keyword.PartialMatch = false;
}
else
{
keyword.Value = escaper.Decode(data[0]);
keyword.PartialMatch = true;
}
return keyword;
}
public static List<FilterKeyword> ParseKeywords(string filter)
{
return escaper.Unpack(filter).Split(",", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).ToList().ConvertAll(r => ParseKeyword(r));
}

}

2 changes: 1 addition & 1 deletion code/HellMapManager/Misc/AppVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace HellMapManager.Misc;

public class AppVersion(int major, int minor, int patch)
{
public static AppVersion Current { get; } = new(0, 20260101, 0);
public static AppVersion Current { get; } = new(0, 20260116, 0);
public int Major { get; } = major;
public int Minor { get; } = minor;
public int Patch { get; } = patch;
Expand Down
2 changes: 1 addition & 1 deletion code/HellMapManager/Misc/Links.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public class Links
public const string ScriptInro = "https://github.com/hellclient-scripts/hellmapmanager/blob/main/doc/script/index.md";
public const string API = "https://github.com/hellclient-scripts/hellmapmanager/blob/main/doc/api/index.md";
public const string BestPractices = "https://github.com/hellclient-scripts/hellmapmanager/blob/main/doc/bestpractices/index.md";

public const string Forum = "https://forum.hellclient.com/";
}
23 changes: 13 additions & 10 deletions code/HellMapManager/Models/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,21 @@ public bool IsBlocked(string from, string to)
{
return BlockedLinks.ContainsKey(from) && BlockedLinks[from].ContainsKey(to);
}
public static Context FromEnvironment(Environment env)
public static Context FromEnvironment(Environment? env)
{
var context = new Context();
context.WithTags(env.Tags);
context.WithRoomConditions(env.RoomConditions);
context.WithRooms(env.Rooms);
context.WithWhitelist(env.Whitelist);
context.WithBlacklist(env.Blacklist);
context.WithShortcuts(env.Shortcuts);
context.WithPaths(env.Paths);
context.WithBlockedLinks(env.BlockedLinks);
context.WithCommandCosts(env.CommandCosts);
if (env != null)
{
context.WithTags(env.Tags);
context.WithRoomConditions(env.RoomConditions);
context.WithRooms(env.Rooms);
context.WithWhitelist(env.Whitelist);
context.WithBlacklist(env.Blacklist);
context.WithShortcuts(env.Shortcuts);
context.WithPaths(env.Paths);
context.WithBlockedLinks(env.BlockedLinks);
context.WithCommandCosts(env.CommandCosts);
}
return context;
}
public Environment ToEnvironment()
Expand Down
37 changes: 37 additions & 0 deletions code/HellMapManager/Models/FilterKeyword.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Text.RegularExpressions;

namespace HellMapManager.Models;

public enum FilterKeywordType
{
Any,
Wrong,
Misc,
Message,
Key,
Name,
To,
Tag,
Command,
Group,
Type,

Desc,
Value,
}
public class FilterKeyword
{
public FilterKeywordType Type = FilterKeywordType.Any;
public bool Not = false;
public bool PartialMatch = true;
public string Value = "";
public bool Match(string target, FilterKeywordType type)
{
if (Type != FilterKeywordType.Any && Type != type)
{
return false;
}
return Not != (PartialMatch ? target.Contains(Value) : target == Value);
}
}
4 changes: 2 additions & 2 deletions code/HellMapManager/Models/Landmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public static void Sort(List<Landmark> list)

public partial class Landmark
{
public bool Filter(string filter)
public bool Filter(FilterKeyword keyword)
{
if (Key.Contains(filter) || Type.Contains(filter) || Value.Contains(filter) || Group.Contains(filter) || Desc.Contains(filter))
if (keyword.Match(Key, FilterKeywordType.Key) || keyword.Match(Type, FilterKeywordType.Type) || keyword.Match(Value, FilterKeywordType.Value) || keyword.Match(Group, FilterKeywordType.Group) || keyword.Match(Desc, FilterKeywordType.Desc))
{
return true;
}
Expand Down
12 changes: 6 additions & 6 deletions code/HellMapManager/Models/Marker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ public static void Sort(List<Marker> list)
}
public partial class Marker
{
public bool Filter(string val)
public bool Filter(FilterKeyword keyword)
{
if (Key.Contains(val) ||
Value.Contains(val) ||
Desc.Contains(val) ||
Group.Contains(val) ||
Message.Contains(val)
if (keyword.Match(Key, FilterKeywordType.Key) ||
keyword.Match(Value, FilterKeywordType.Value) ||
keyword.Match(Desc, FilterKeywordType.Desc) ||
keyword.Match(Group, FilterKeywordType.Group) ||
keyword.Match(Message, FilterKeywordType.Message)
)
{
return true;
Expand Down
13 changes: 7 additions & 6 deletions code/HellMapManager/Models/Region.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,19 @@ public static void Sort(List<Region> list)

public partial class Region
{
public bool Filter(string val)
public bool Filter(FilterKeyword keyword)
{
if (Key.Contains(val) ||
Desc.Contains(val) ||
Group.Contains(val) ||
Message.Contains(val))

if (keyword.Match(Key, FilterKeywordType.Key) ||
keyword.Match(Desc, FilterKeywordType.Desc) ||
keyword.Match(Group, FilterKeywordType.Group) ||
keyword.Match(Message, FilterKeywordType.Message))
{
return true;
}
foreach (var item in Items)
{
if (item.Value.Contains(val))
if (keyword.Match(item.Value, FilterKeywordType.To))
{
return true;
}
Expand Down
Loading