From 2e64f5774901cd2cc55f81a053b3bc982aa3c0d2 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Wed, 15 May 2024 21:52:07 +0800 Subject: [PATCH] =?UTF-8?q?Support=20for=20saving=20node=20data=20to=20jso?= =?UTF-8?q?n=20files.=20=E6=94=AF=E6=8C=81=E5=B0=86=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=BD=AC=E5=AD=98=E4=B8=BAjson=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BA=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ColdMint.Traveler.csproj | 3 - locals/UI.csv | 5 +- locals/UI.en.translation | Bin 1514 -> 1590 bytes locals/UI.jp.translation | Bin 1845 -> 1949 bytes locals/UI.zh.translation | Bin 1573 -> 1649 bytes scenes/LevelGraphEditor.tscn | 80 +++++++- scripts/Config.cs | 99 +++++++++- scripts/levelGraphEditor/ConnectionData.cs | 4 +- scripts/levelGraphEditor/IRoomNodeData.cs | 4 +- .../LevelGraphEditorSaveData.cs | 4 +- scripts/levelGraphEditor/RoomNodeData.cs | 1 + .../loader/uiLoader/LevelGraphEditorLoader.cs | 185 +++++++++++++----- scripts/serialization/JsonSerialization.cs | 10 +- scripts/utils/ExplorerUtils.cs | 80 ++++++++ scripts/utils/GuidUtils.cs | 16 ++ 15 files changed, 420 insertions(+), 71 deletions(-) create mode 100644 scripts/utils/ExplorerUtils.cs create mode 100644 scripts/utils/GuidUtils.cs diff --git a/ColdMint.Traveler.csproj b/ColdMint.Traveler.csproj index 49b333a..dafdfc5 100644 --- a/ColdMint.Traveler.csproj +++ b/ColdMint.Traveler.csproj @@ -7,7 +7,4 @@ ColdMint enable - - - \ No newline at end of file diff --git a/locals/UI.csv b/locals/UI.csv index 27e8618..0f22d2d 100644 --- a/locals/UI.csv +++ b/locals/UI.csv @@ -22,4 +22,7 @@ default_room_name,房间{0},Room{0},部屋{0}です room_template_collection_prompt,房间模板集(每一行被认为是一条房间模板地址。),Room template set (Each row is considered to be one room template address.),お部屋テンプレートセット(各行がお部屋テンプレートアドレスとされています。) error_specifying_room_template_line,位于{0}错误,文件不存在。,"Located at {0} error, file does not exist.",{0}エラーに位置し、ファイルは存在しません。 line_errors_must_start_with_res,位于{0}错误,必须以res://开头。,"Located at {0} error, must start with res://.",{0}エラーに位置し、res://で始めなければなりません。 -display_current_page_data,显示当前页面数据,Displays the current page data,現在のページデータを表示します \ No newline at end of file +open_the_export_directory,打开导出目录,Open the export directory,エクスポートディレクトリを開きます +save,保存,Save,保留 +filename,文件名,File name,ファイル名 +cancel,取消,Cancel,キャンセル \ No newline at end of file diff --git a/locals/UI.en.translation b/locals/UI.en.translation index 63f638f462ec0ee2e6b5405b08d5497491f4b292..7add42571b9fa7eedd19a19e7ec041cdc58beb3a 100644 GIT binary patch delta 406 zcmaFGy^UvsG$X5lNoumiWCcdENFfFWhW|hy1EoQ15KuzmYe3n0K-vV#wgS=)P_`SC zhUkQlK9kooiiZXPWg>t$4v15LI1h-CRh2;bRY1A{h}(d;2Z)i?Oak&*fmi{EX87- z)%Bv!xdUkqAm*HG&YY|YGvkd!*7``G5=Ed4$j{&JJXkji$Y%$#*(a}OR_496`r+pu zpa{ratdoy3H#08W?9EcgXzG8VUzq8ajh1qwqKpVn@IQv&#IjU|e{LVRIazZ4F*qmY TC8y>9HG$0n8o&?~9OMiDfcJ_! delta 322 zcmdnS^NM?eG$X57aZy_CWCcdENInJzhW|hy0;NH05RgLRD?r(5Kw1aNHUiQXP_`YE zhUkQl9+THIiVOMyWkP^B3WyVcI1MDKn*(GO0dWNo*8wrIz7`;#6^IppxC@AxCrdM# zi!uUPAiO{~>61T@W&z>J?M$mxnV>T2deP_Hfou*S<^KGMWRBbwg_Y2ERQw*qO`MFe`t$4v15LI1h-CRh2;bRY1A{h}(d;2Z)i?Oak&*fmi{EX8_Ax8--dg?e^Ch4NJ5ZK=@-^mW z#-E#`SQav6J#Jd@xM}_4rk#(Q=RR)U^SHU=adZ3Qrp1q&*MP)9+*Oa8CcT{2{kXCB zapS(njWZdZ?4SF5>P&{m%~KyYEqvUx3pb*d|uyr7( J2L%T?0{|~tyYT=3 delta 347 zcmbQszm;!;G$X4;NmixFWCcdoNInJzhW|hy0;NH05RgLRD?r(5Kw1aNHUiQXP_`YE zhUkQl9+USmiVOMyWkP^B3WyVcI1MDKn*(GO0dWNo*8wrIz7`;#6^IppxC@AxCu=d8 zi!uUPAiO{~=~E|=<^ti#)0kGPGC^h3^`g&J0@(sk9JjsY|2&|i9+0m$IgB|OZpIsl zto5Nl8Bd^$=j40L%9ABoDj3gfp2V_{$?AFkzNd3mJZ@a~xOvv&<~@&_c06uw2Q&6R iZkqIB;fm)=c0F#K{_8(x&I$?+as~hmIE2gq diff --git a/locals/UI.zh.translation b/locals/UI.zh.translation index e18f24e76a0613ee318696e36deaa2312737dc01..b5dd9cecbff35029605207d47557c54d07497a03 100644 GIT binary patch delta 409 zcmZ3=^O0wRG$U(XSx!;zWCcdoNFfFWhW|hy1EoQ15KuzmYe3n0K-vV#wgS=)P_`SC zhUkQlK9lz`iiZXPWg>t$4v15LI1h-CRh2;bRY1A{h}(d;2Z)i?Oak&*fmi{EX8gmocpt1*rmI zb-n0wo={cnliiq;Rbghlk;qzK0aT(5lm+4McOI-e4&;N)oV<@&nfKP}ho85>MXoV7 zGoITV#j>2yqI2@oJq=IS?|It3>-p?;Pxnq`c(Q-))3q}go=t0ivU}Up3B3$Y`=>qI O)&aE`7 delta 325 zcmey!vy^9pG$X5NX;yy0WCcdoNInJzhW|hy0;NH05RgLRD?r(5Kw1aNHUiQXP_`YE zhUkQl9+USmiVOMyWkP^B3WyVcI1MDKn*(GO0dWNo*8wrIz7`;#6^IppxC@AxCu=d8 zi!uUPAiO{~=~DoZW(VQP)0kGPGC^h3^`g&t!eoGS-1e6Li-B4sfo#diVa&;JGu}vK zt*-#eXai-mC*NaMo-D~y!MJDhB$nljDl_&yU$X1z-pNlpdtWZx`f~1~XHz#k>s<%7 L5afWM;2>uJ+0%7z diff --git a/scenes/LevelGraphEditor.tscn b/scenes/LevelGraphEditor.tscn index 544e7cb..70a343e 100644 --- a/scenes/LevelGraphEditor.tscn +++ b/scenes/LevelGraphEditor.tscn @@ -152,9 +152,13 @@ offset_right = -15.0 offset_bottom = 47.0 grow_horizontal = 0 -[node name="DisplayCurrentPageData" type="Button" parent="HBoxContainer"] +[node name="OpenExportFolderButton" type="Button" parent="HBoxContainer"] layout_mode = 2 -text = "display_current_page_data" +text = "open_the_export_directory" + +[node name="SaveButton" type="Button" parent="HBoxContainer"] +layout_mode = 2 +text = "save" [node name="ShowCreateRoomPanelButton" type="Button" parent="HBoxContainer"] layout_mode = 2 @@ -163,3 +167,75 @@ text = "create_room" [node name="ReturnButton" type="Button" parent="HBoxContainer"] layout_mode = 2 text = "close" + +[node name="SaveOrloadPanel" type="Panel" parent="."] +visible = false +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = 232.0 +offset_top = 202.0 +offset_right = -121.0 +offset_bottom = -155.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="Label" type="Label" parent="SaveOrloadPanel"] +layout_mode = 1 +anchors_preset = 5 +anchor_left = 0.5 +anchor_right = 0.5 +offset_left = -18.5 +offset_top = 15.0 +offset_right = 21.5 +offset_bottom = 40.0 +grow_horizontal = 2 +text = "save" + +[node name="LineEdit" type="LineEdit" parent="SaveOrloadPanel"] +layout_mode = 1 +anchors_preset = 14 +anchor_top = 0.5 +anchor_right = 1.0 +anchor_bottom = 0.5 +offset_left = 18.0 +offset_top = -5.0 +offset_right = -18.0 +offset_bottom = 28.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="Label2" type="Label" parent="SaveOrloadPanel"] +layout_mode = 1 +anchors_preset = 4 +anchor_top = 0.5 +anchor_bottom = 0.5 +offset_left = 20.0 +offset_top = -38.0 +offset_right = 80.0 +offset_bottom = -13.0 +grow_vertical = 2 +text = "filename" + +[node name="HBoxContainer" type="HBoxContainer" parent="SaveOrloadPanel"] +layout_mode = 1 +anchors_preset = 3 +anchor_left = 1.0 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -117.0 +offset_top = -50.0 +offset_right = -19.0 +offset_bottom = -10.0 +grow_horizontal = 0 +grow_vertical = 0 + +[node name="CancelButton" type="Button" parent="SaveOrloadPanel/HBoxContainer"] +layout_mode = 2 +text = "cancel" + +[node name="ActionButton" type="Button" parent="SaveOrloadPanel/HBoxContainer"] +layout_mode = 2 +text = "save" diff --git a/scripts/Config.cs b/scripts/Config.cs index c5d343e..81fac7f 100644 --- a/scripts/Config.cs +++ b/scripts/Config.cs @@ -79,13 +79,13 @@ public static class Config /// 单个物品栏最大堆叠的物品数量 /// public const int MaxStackQuantity = 99; - + /// /// Operation prompts, function key text color /// 操作提示内,功能键文本颜色 /// public const string OperationTipActionColor = "#2b8a3e"; - + /// /// Company/Creator name @@ -133,6 +133,85 @@ public static class Config return OS.HasFeature("debug"); } + public enum OsEnum + { + //unknown + //未知 + Unknown, + + //Runs on Android (non-web browser) + //在 Android 上运行(非 Web 浏览器) + Android, + + //Runs on Linux (non-web browser) + //在 Linux 上运行(非 Web 浏览器) + Linux, + + //Runs on macOS (non-Web browser) + //在 macOS 上运行(非 Web 浏览器) + Macos, + + //Runs on iOS (non-Web browser) + //在 iOS 上运行(非 Web 浏览器) + Ios, + + //Runs on Windows + //在 Windows 上运行 + Windows, + + //The host operating system is a web browser + //宿主操作系统是网页浏览器 + Web, + + //Editor + //编辑器 + // Editor + } + + /// + /// Get what platform is currently running on + /// 获取当前在什么平台上运行 + /// + /// + public static OsEnum GetOs() + { + // if (OS.HasFeature("editor")) + // { + // return OsEnum.Editor; + // } + + if (OS.HasFeature("windows")) + { + return OsEnum.Windows; + } + + if (OS.HasFeature("android")) + { + return OsEnum.Android; + } + + if (OS.HasFeature("linux")) + { + return OsEnum.Linux; + } + + if (OS.HasFeature("web")) + { + return OsEnum.Web; + } + + if (OS.HasFeature("macos")) + { + return OsEnum.Macos; + } + + if (OS.HasFeature("ios")) + { + return OsEnum.Ios; + } + return OsEnum.Unknown; + } + public static string GetVersion() { var stringBuilder = new StringBuilder(); @@ -162,6 +241,17 @@ public static class Config } } + + /// + /// Get the export directory for the level graph + /// 获取关卡图的导出目录 + /// + /// + public static string GetLevelGraphExportDirectory() + { + return Path.Join(GetGameDataDirectory(), "LevelGraphs"); + } + /// /// The initial year of creating this game /// 创建此游戏的初始年份 @@ -215,11 +305,6 @@ public static class Config /// public const int HorizontalSpeedOfDamageNumbers = 3; - /// - /// The file name of the packet's manifest - /// 数据包的清单文件名 - /// - public const string DataPackManifestName = "DataPackManifest.json"; /// /// VerticalVelocityOfDamageNumbers diff --git a/scripts/levelGraphEditor/ConnectionData.cs b/scripts/levelGraphEditor/ConnectionData.cs index b256880..7d56c11 100644 --- a/scripts/levelGraphEditor/ConnectionData.cs +++ b/scripts/levelGraphEditor/ConnectionData.cs @@ -2,8 +2,8 @@ public class ConnectionData { - public IRoomNodeData? From { get; set; } - public IRoomNodeData? To { get; set; } + public string? FromId { get; set; } + public string? ToId { get; set; } public int FromPort { get; set; } public int ToPort { get; set; } } \ No newline at end of file diff --git a/scripts/levelGraphEditor/IRoomNodeData.cs b/scripts/levelGraphEditor/IRoomNodeData.cs index e20acff..495f822 100644 --- a/scripts/levelGraphEditor/IRoomNodeData.cs +++ b/scripts/levelGraphEditor/IRoomNodeData.cs @@ -2,12 +2,14 @@ public interface IRoomNodeData { + string Id { get; set; } + /// /// Title /// 标题 /// string Title { get; set; } - + /// /// 描述 /// Description diff --git a/scripts/levelGraphEditor/LevelGraphEditorSaveData.cs b/scripts/levelGraphEditor/LevelGraphEditorSaveData.cs index 74c98cc..566ae3c 100644 --- a/scripts/levelGraphEditor/LevelGraphEditorSaveData.cs +++ b/scripts/levelGraphEditor/LevelGraphEditorSaveData.cs @@ -8,5 +8,7 @@ namespace ColdMint.scripts.levelGraphEditor; /// public class LevelGraphEditorSaveData { - public List? ConnectionData { get; set; } + public List? ConnectionDataList { get; set; } + + public List? RoomNodeDataList { get; set; } } \ No newline at end of file diff --git a/scripts/levelGraphEditor/RoomNodeData.cs b/scripts/levelGraphEditor/RoomNodeData.cs index 80ff294..ef29d74 100644 --- a/scripts/levelGraphEditor/RoomNodeData.cs +++ b/scripts/levelGraphEditor/RoomNodeData.cs @@ -2,6 +2,7 @@ public class RoomNodeData : IRoomNodeData { + public string Id { get; set; } public string Title { get; set; } public string Description { get; set; } } \ No newline at end of file diff --git a/scripts/loader/uiLoader/LevelGraphEditorLoader.cs b/scripts/loader/uiLoader/LevelGraphEditorLoader.cs index e09b8c4..cb9f015 100644 --- a/scripts/loader/uiLoader/LevelGraphEditorLoader.cs +++ b/scripts/loader/uiLoader/LevelGraphEditorLoader.cs @@ -1,11 +1,12 @@ using System.Collections.Generic; -using System.Text.Json; -using ColdMint.scripts.debug; +using System.Diagnostics; +using System.IO; using ColdMint.scripts.levelGraphEditor; using ColdMint.scripts.serialization; using ColdMint.scripts.utils; using Godot; using Godot.Collections; +using FileAccess = Godot.FileAccess; namespace ColdMint.scripts.loader.uiLoader; @@ -34,13 +35,20 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate private int _roomIndex = 1; private TextEdit? _roomTemplateCollectionTextEdit; private Label? _roomTemplateTipsLabel; - private Button? _displayCurrentPageData; + private Button? _saveButton; + private Button? _openExportFolderButton; + private HBoxContainer? _hBoxContainer; public override void InitializeData() { base.InitializeData(); _roomNodeScene = (PackedScene)GD.Load("res://prefab/ui/RoomNode.tscn"); _defaultRoomName = TranslationServer.Translate("default_room_name"); + var folder = Config.GetLevelGraphExportDirectory(); + if (!Directory.Exists(folder)) + { + Directory.CreateDirectory(folder); + } } @@ -53,7 +61,16 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate _roomTemplateTipsLabel.Text = string.Empty; } - _displayCurrentPageData = GetNode