From b0da4b049e99fbc391d9bd530b0d7031af39c840 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Sun, 26 May 2024 11:10:21 +0800 Subject: [PATCH] =?UTF-8?q?Improve=20the=20log=20of=20map=20generator.=20?= =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=9C=B0=E5=9B=BE=E7=94=9F=E6=88=90=E5=99=A8?= =?UTF-8?q?=E7=9A=84=E6=97=A5=E5=BF=97=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locals/Error.csv | 10 ---------- locals/Error.csv.import | 17 ----------------- locals/Error.en.translation | Bin 850 -> 0 bytes locals/Error.jp.translation | Bin 1197 -> 0 bytes locals/Error.zh.translation | Bin 941 -> 0 bytes locals/Log.csv | 19 ++++++++++++++++++- locals/Log.en.translation | Bin 338 -> 1258 bytes locals/Log.jp.translation | Bin 338 -> 1797 bytes locals/Log.zh.translation | Bin 338 -> 1417 bytes locals/UI.csv | 3 ++- locals/UI.en.translation | Bin 1710 -> 1730 bytes locals/UI.jp.translation | Bin 2161 -> 2189 bytes locals/UI.zh.translation | Bin 1813 -> 1833 bytes project.godot | 3 +-- scenes/LevelGraphEditor.tscn | 19 +++++++++++++++---- scripts/debug/LogCat.cs | 13 ++++++++++++- scripts/map/MapGenerator.cs | 25 +++++++++++++++++++++++++ scripts/map/room/RoomFactory.cs | 3 ++- scripts/utils/ResUtils.cs | 18 ++++++++++++++++++ 19 files changed, 93 insertions(+), 37 deletions(-) delete mode 100644 locals/Error.csv delete mode 100644 locals/Error.csv.import delete mode 100644 locals/Error.en.translation delete mode 100644 locals/Error.jp.translation delete mode 100644 locals/Error.zh.translation create mode 100644 scripts/utils/ResUtils.cs diff --git a/locals/Error.csv b/locals/Error.csv deleted file mode 100644 index 5fb7974..0000000 --- a/locals/Error.csv +++ /dev/null @@ -1,10 +0,0 @@ -id,zh,en,jp -Object reference not set to an instance of an object.,尝试在空对象上调用虚拟方法。,Object reference not set to an instance of an object.,空のオブジェクト上で仮想メソッドを呼び出してみます。 -missing_parameters,缺少参数。,Missing parameters.,パラメータが不足しています。 -room_root_node_must_be_node2d,房间根节点必须是 Node2D。,Room root node must be Node2D.,ルートノードはNode2Dでなければなりません。 -width_or_height_of_room_slot_must_be_1,房间槽的宽度或高度必须为1。,The width or height of the room slot must be 1.,部屋の溝の幅または高さは1でなければなりません。 -connected_room_timeout,连接房间超时。,Connecting the room timed out.,接続部屋はタイムアウトです。 -projectiles_is_empty,未设置抛射体。,The projectile is not set.,射出体は設置されていません。 -map_generator_missing_parameters,地图生成器缺少参数。,Map generator missing parameters.,マップジェネレータが不足しています。 -map_generator_attempts_to_parse_empty_layout_diagrams,地图生成器尝试解析空的布局图。,Map generator attempts to parse empty layout diagrams.,マップジェネレータは空のレイアウト図を解析しようとしています。 -map_generator_has_no_starting_room_data,地图生成器没有起点房间数据。,Map generator has no starting room data.,マップ生成器に起点部屋データはありません。 \ No newline at end of file diff --git a/locals/Error.csv.import b/locals/Error.csv.import deleted file mode 100644 index 0745731..0000000 --- a/locals/Error.csv.import +++ /dev/null @@ -1,17 +0,0 @@ -[remap] - -importer="csv_translation" -type="Translation" -uid="uid://nmtkvo0t7p7n" - -[deps] - -files=["res://locals/Error.zh.translation", "res://locals/Error.en.translation", "res://locals/Error.jp.translation"] - -source_file="res://locals/Error.csv" -dest_files=["res://locals/Error.zh.translation", "res://locals/Error.en.translation", "res://locals/Error.jp.translation"] - -[params] - -compress=true -delimiter=0 diff --git a/locals/Error.en.translation b/locals/Error.en.translation deleted file mode 100644 index 64b0440c2ae67ffbe863d8b6fef705129f42cf8d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 850 zcmWFv4svFI0u~_61jMXBEDFT_1tpoenN_JNAw`LK#W{&3nfZA@VF+LbQeXDp;ZIFc z2!@FfLvsKXNdR$CYH@yPQF3a0PJVJ?PJBszd~tGWUMd40vRqzbZYl#OP$W0CxHvIA zwU~h&$N}p}W#9%fGZKq4;!6^fa#9(1f!w6hD!V$cMs1p=G_0tz({Rsdp<8~y_UkYZp1VgV>0BnARv zNPGn#TMdYHfEX0w3P5ZG#31`Xcp_`*r%oU(4#Y}842l_$c>NQD^ZGzq3W()_xa;-q zi^rgRO&|@^ulM78w<3@a3Q!RshUvev=}mbmkS`3xApJ5Lb;lL}X^>mYff%M=AS=fS z$YlVTVTL3=L$XJ+0>~ExVreAtTMx75cmnw{Kx_cSApe8Re*nb){Gk1gvz zqmc_x#^bZZ;|&5F)MTHeK&cWGZb87@1OOOx(og^Z diff --git a/locals/Error.jp.translation b/locals/Error.jp.translation deleted file mode 100644 index 1192517ed1ce09179c6609771fbb874f48669d32..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1197 zcma)6OGs2<6uv#|K@@HZgCHS@q)3w<5EW5Dy99IHa2+o?HqOZ0D}jsZ|9{KZC{9*t zmiE-qDaRV}ZSC4h+h`MK?mVbft5(%_X6}U{to-4d^Z3u>JLldz)t9T!YtGpSxgID2 zb^=w+maoazYSh()^nmHtEnhGIcm8aEICZ8(^(o7Btx0Y{R0$9=%wS8%Yk2%YukQC) zL67M*0*1Du@GhV?8QNBOnhev_>kU)e3?r9eXxpGR=w^e*(rf*OwjE||i}$KwIS%e* zS|MMcKA&cKL%!xb*>$+u2jnW9EH7VeQqM8p(Td|*8OP%Mbs@YhUWO|hn>Ai!DZrF| z;Xr7cfMUmHAD>+Xb}97zz#)K3l>(Ijw`W9(TE5pnIRTx)4~qRak`*hhkf$AVeO>&R z#l>0J431$O{;|?s1$oecoB#REw`)HO{Cf^u|Im$uEATPg{NhIcIhY#PV7UIl-QhCc zkz3dGfBMq+a29bF9q{~nfig5sPb`p_A~{LwKFK+f<0RvxI+Al;B*v4AQz?}o^@QXy zDMhN2V~J-jNuhn^GecAvM7XYKbH+!pXUw%uK=!Z7U3oaggdD z)tgf~NyIM&>x{|^=uBdgM1*9R#5C&?bkJm&WIy-Gs;K?C8_ZJ+kML{H-^yK&qC_?} zNa7xpBmXax>V1)(dEgd{Gh_Lj)MJuQNsci$W|EuCo^Hd)$>n}j&O~3Om#4T3^TP)6 zW4Yu=jpUX!;4D=2kb1e6h5REe?mQ?I0z;RcJ)FP;$&5csjr8$~B?#Xp5nXlNPWANN n(NssDJ%pfG=Iv}+&O7s~c9&zEg#2^kcwhK~=Xa_ae^kE#DHrXy diff --git a/locals/Error.zh.translation b/locals/Error.zh.translation deleted file mode 100644 index b15f408dc06f2640754b42db187e0a9d6504fc7d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 941 zcma)*O=uHQ5P+XQ^#@VvK~WG42x6$TT6)rps8eJzC)}_VG{hsfC^gakW253}|#x#XW zp{OE5sPQf$hbh7GVXEtLH`U2rFzOkU9Drj`)`OBEcZMiA2xezYxkC-t zflty6O^tLrX}Y4Ry#_c5*#Vpa>Xk0EwQV=4q;$mkI*1=*LH@ZA+!ijw)BQn$i}V55 z(r*w@WDn5n+UP?$+F<+Od>S|lU@0Ha4&dXFv8LG170@SL@I|5jo^@{HB4`{3Nq%4Z zh!-tzM!fviUmGK6V-JXz|7H0{-+i#L7v#j5yB{_|x4L-w%{`&Z;QFg>`uIctEcm^A zFaGn_p3H6V`(1E;?7am7m^mv7DVE9Euga`Y5=&XDm=xxqJ)RR&(|lx}Pn7sd>f1n^ z*ze2C9Ai)7JY}NI6V=+}8~&^$l5sm;V%6bVc8#YCzU$F0+J3bmWT9eD53ziOm0$A2 zMD2AN4oM);Nt*2)eMSk6`tGwzgb51B!*`d~OtG#72sPY-s>WY*UOcXL;s4|pa_38#{81i5>mNMsGyp&9 EAFvWfv;Y7A diff --git a/locals/Log.csv b/locals/Log.csv index 1c60c93..2c63795 100644 --- a/locals/Log.csv +++ b/locals/Log.csv @@ -1 +1,18 @@ -id,zh,en,jp \ No newline at end of file +id,zh,en,jp +map_generator_is_running,地图生成器正在运行中,请稍后重试。,"Map Generator is running, please try again later.",マップ生成器が動作中ですので、後ほどリトライしてください。 +missing_parameters,缺少参数。,Missing parameters.,パラメータが不足しています。 +room_root_node_must_be_node2d,房间根节点必须是 Node2D。,Room root node must be Node2D.,ルートノードはNode2Dでなければなりません。 +width_or_height_of_room_slot_must_be_1,房间槽的宽度或高度必须为1。,The width or height of the room slot must be 1.,部屋の溝の幅または高さは1でなければなりません。 +connected_room_timeout,连接房间超时。,Connecting the room timed out.,接続部屋はタイムアウトです。 +projectiles_is_empty,未设置抛射体。,The projectile is not set.,射出体は設置されていません。 +map_generator_missing_parameters,地图生成器缺少参数。,Map generator missing parameters.,マップジェネレータが不足しています。 +map_generator_attempts_to_parse_empty_layout_diagrams,地图生成器尝试解析空的布局图。,Map generator attempts to parse empty layout diagrams.,マップジェネレータは空のレイアウト図を解析しようとしています。 +map_generator_has_no_starting_room_data,地图生成器没有起点房间数据。,Map generator has no starting room data.,マップ生成器に起点部屋データはありません。 +room_placement_strategy_terminates_map_generation,房间的放置策略终止了地图生成。,The room placement strategy terminates map generation.,部屋の配置ポリシーはマップ作成を終了します。 +start_room_placement_information_returns_empty,起始房间放置信息返回空。,Start room placement information returns empty.,スタートルーム放置情報は空に戻ります。 +start_room_placement_failed,起始房间放置失败。,Start room placement failed.,スタートルーム放置失敗です。 +room_data_missing,房间数据缺失。,Room data missing.,部屋データが欠落しています。 +failed_to_calculate_the_room_location,计算房间{0}位置时失败。,Failed to calculate the location of room {0}.,部屋{0}の位置を計算するのに失敗します。 +place_existing_rooms,放置已存在的房间{0}。,Place existing rooms {0}.,既存の部屋を置きます{0}。 +room_placement_failed,房间{0}放置失败。,Room {0} placement failed.,部屋{0}の放置に失敗します。 +room_placement_information,房间{0}已被成功放置在{1}。,Room {0} has been successfully placed in {1}.,部屋{0}を{1}に配置しました。 \ No newline at end of file diff --git a/locals/Log.en.translation b/locals/Log.en.translation index 0b1c04fd0f919c03540a50d13565083702ba7817..51b0b48cc4d5640449a580c3f54cbd67dc3f95c9 100644 GIT binary patch literal 1258 zcmaJ>Ye-XJ7(Tk=@-nrHI@6`o>6YNUMI>#Ac$+NL*aRy_YtDmC=aikZjKm`G$Cep{ z6jDM&DuD?SK|)CVsIWgt5d~IgH~Nu3#Qs#+?0I*wQ&b;3yzl$G*YEw{Gnq}5Oz5zX zkw6rX3^eozjxNVZuC>u^bMa1_;OKUN4ju`_r*-~?rSs@7GVJ`1jD{~2aC3aO$8G1V z&ThNSX%)Jyyq$A#OoG_wvUPDx445vC=WT5q&uoDa$l#bbsO>hs-745xoE#Gmv&CcY z2tWk{D(x>U{M${fZO-E-I+;9*#rfw#Xln!|AO|*Z zAQ&ki3)#e_Kvw{2AYa6ng!EDoR{_0NWSc@dy^IpD05lijV%FaEG$=cu?-KC^Ul)dy zuxX)50KF{5zrMB7+X_kXnSf&VsYh2KX|8=hxb7s|8TkV?)hq(S`DZ`hefkh~8juHE z9>4iaizMnpHN*Kj;SE0sBL`f8h#%c~F0U8%HXvQZzpA|!cLeb?E7cD7JN=<(f%1u? zd6yr^Zo3di`xNJ2i1Ms?!Oe_Be;uo5{DwX0ni)a198;5{Zz>p*8CV_b@XfmX@aI0a>l;|- zY%EzO>ByXPX+_%6H?FcU{(5Q0Mnp*!Jhfj^-_LA~)@@g1N6bk_%2Jks5yg~MnK`5| z+KEqiSKch4@P6Lk@zU5-DjzJ1BqA`!x1oWg1KQsj(s%({Q?1oY?j6%NSf`*EeCB4= z8CEx-4UDxJ)gr%BHosPbP7@lI`atXVdDm5S1JyditTyqZd^%8YIEI><=hwmkiB;3X zd0CQ6_o=-34`)8RT0s=9KcTsf2^-0(VOPr!D-J2tzUuh66sh9L`D}iK*@)~b>L>R> zpLgneuF=kq$Tv9@2nGa(5|s_IkL8wyShd1CnXeu-=zZP{2QrJP8vPb{F2;mk?k86! BPx}A> delta 34 lcmaFGd5LL*G$U)JL1tdgWCcbg0Y(M}26i9@(LupM&H$Fx2Ce`A diff --git a/locals/Log.jp.translation b/locals/Log.jp.translation index 1ba2594ab13b3d93dcf47c8c1eb39d5aa1eb271e..ef41ed48826b8172384212bec76cda36109ae3f9 100644 GIT binary patch literal 1797 zcma)7O>9(E6n-KV4d{*^6B0n8LL>rBj09sKVj^LINp;~uolK`s7-(mjc{7qo5bnJ# zR62zgIw_?<2dw>@wnO>t4^vnew~ek$l>~C;y_rT}(|84%I@7X(`%KGNf{W{68cQMW z4_f;J@nChWX}pSSbs}`ojQa}CWW{6Q$Ue`_3dO?paVQPr1zC3;uVXzAn&1As_UOd0;)9D4aM}(XL;IinYx38}Fxm+n<9yH1Z!>t*@wER3@%vU1JZ*ptL+j7Ip4?c8 z%fIda*nN5F4%oj5TZYbeG{0q9;m%9Pc<}SG8#QI(wpAn^e}%a3!-k>#_s*D1x4~R6 z5^tBCgt3+g@Fkk z2m+x(U7p=_o#dHf-;d6vR;E~@;Nv7POm8^fQ&lGRoF354ee|19Fm?a?>WPG-< zg_~Cwc^l+y_7T~+ma#zCClpnx zG^z7@yRxvS-81T>ki^~C`OTPbCg}{Ni>i64O1$u1m*s=amm$v_-il%}KE*zF$lJ~F_=kl5 J2UXz*@EMn>AQ1on delta 34 lcmZqWyTr6XnvpfVG`FH;vI3)$03!nf13M6d=%C;rX8@4z2A2Q; diff --git a/locals/Log.zh.translation b/locals/Log.zh.translation index 72fed090cb126d6a46ca49f83e30f28cc69248d0..dccd5581081b3186ce95a9ef115701cb4caaac96 100644 GIT binary patch literal 1417 zcma)6Ye-XJ7(SU+qD2r^LZB%{Qh38c>R$;-kiqI_Fy=hyau?Y-BTy<^noFHca&Eb$ z&Fji`QOwJ9?oagB>QA5rMf<*URzc9Oh^XH8>>M1!pbsA2%lAI-?K>RRWz{)GKA9jh z09k-Mz@-*mXVA5>4Oh$>Bd6E!I+GFH$+I2A`K-5}i(mb|sQCUz?t-9$05i*(EM_gM z)|<2%y_z?vIW22snLVj@MvZ}GvcY3uIZo5aa?DOJBnHdmfZC+tn$*0eUe7YS!K}Av zn^|6VU?q+>>x_*_8mBeuT6l0W%r-zVK+1HwtZb`E)%tP+cZw;&SUCS&2yP3Pp~%)I z1{YZfH~{zq2L!VNkSp8h+YkC7z)`@76n~|xSEu;Sf?k_qt7IKZ76PsUuuX*X@X23Y zpkQu<;xGNN)>8%cUK#k%c=vAh>vac6>__V9*v*$4pqI)}_>-B<8TDWs0Y5_FcYj%a zoelou;6n_JKYKFG2!2zMKsRDu6qLQtwv0e60p- zd_Kg77rApkAub~wzJI*aROa2E(mQE^@skd%3qI_n>=c^l!rM24q8 zePIdWioizTdt&ZtAP{eucvgjh5o&XghkhCuBVNB4bBMm)_+sGOO0O7N5d3!H=u33j z#gOw;yOj}EA|%{T?pvudj5f8!60SM=cuDNG3f3hO>rD8TsXJ6yXKG+8Yf?g{qQX!I z2}Vg|lG+9n({50b;qk>t1qO<-VcIv5%qY%xQrEmh_dXSat3otLyFDb_5syAVZ(8r^ zZKYk4@FVD7oEoFU4&g}z8(F+VX4+x=Et1h$ANAf7pD(~b@_f!PwFjkcq diff --git a/locals/UI.csv b/locals/UI.csv index 8df7ea3..1152037 100644 --- a/locals/UI.csv +++ b/locals/UI.csv @@ -29,4 +29,5 @@ cancel,取消,Cancel,キャンセル load,加载,Load,ろーど delete_selected_node,删除选中的节点,Delete selected node,選択されたノードを削除します re_create_map,重新创建地图,Re-create map,地図を再作成します -seed_info,种子:{0},Seed: {0},シード:{0} \ No newline at end of file +seed_info,种子:{0},Seed: {0},シード:{0} +tags,标签,Tags,と呼ぶ \ No newline at end of file diff --git a/locals/UI.en.translation b/locals/UI.en.translation index 5f3f49058c8bed8c754218aad588d28196cc8a64..9da8a621346a2a476e6a9f54d691f1ad2036e3d0 100644 GIT binary patch delta 129 zcmZ3-dx&>~G$U(HVoFNMWCg}cs?!)480G-+A|U>c1Xcj~tU#;)#OpSTGZ{0fG69*4 zK>VvzHsB+W<^W<&Aa1JGd3zBk0aDI7Ii4k(@!ICoELRwXLlV=Afnw}H4AK`A9OMiD Df0-k{ delta 109 zcmX@ayN-8*G$X4~rDnvvC@tUS4LvI65n)oBb240C{Z5fJ}J0xN)gRv=aY;&q$Vn2ecJnSe}2 zApTV<8_)z~@B-N&+*Gaewu700feXmynw-ay%{XcEEtYO(iN}pAo=)8JxN#d$f*puK JnuCIaoB?QVC!qiU delta 106 zcmeAb{3x(NnvvDK*tk4#vI65n)kzEt3^Rau9uWUW0!x5=Rv=aY;#Hf~n2ec38G%d? j{#7a)&;(@g0@=Ki>sYcGJ2t;!>1O6(hbjmP4sr$nSGgWF diff --git a/locals/UI.zh.translation b/locals/UI.zh.translation index 9242f7e0ff3fb1b970a3e11bed9e521def570a07..13e9ac6ebb15ac9d4aec5261b8bb974bbbc780ac 100644 GIT binary patch delta 122 zcmbQrw~}vzG$U(?L2i!4WCg~Ds?!)480G-+A|U>c1Xcj~tU#;)#OpSzF&Q(-F#(y3 wK>VvzHsB|aW{2XYYMr;5Oq0`DiWm(x-(t~W5`MOz{rTE`U InfoLogLevel) + { + return; + } + + GD.Print(string.Format(HandleMessage(WarningLogLevel, message).ToString(), args)); + } + /// /// This method is called when an exception is caught /// 当捕获异常后调用此方法 diff --git a/scripts/map/MapGenerator.cs b/scripts/map/MapGenerator.cs index f375907..4986f66 100644 --- a/scripts/map/MapGenerator.cs +++ b/scripts/map/MapGenerator.cs @@ -27,6 +27,8 @@ public static class MapGenerator /// private static ILayoutStrategy? _layoutStrategy; + private static bool _running; + /// /// Map root node /// 地图根节点 @@ -89,16 +91,26 @@ public static class MapGenerator /// public static async Task GenerateMap() { + if (_running) + { + LogCat.LogWarning("map_generator_is_running"); + return; + } + + _running = true; if (_layoutStrategy == null || _roomPlacementStrategy == null || _layoutParsingStrategy == null || _mapRoot == null) { LogCat.LogError("map_generator_missing_parameters"); + _running = false; return; } NodeUtils.DeleteAllChild(_mapRoot); if (!await _roomPlacementStrategy.StartGeneration(_mapRoot)) { + LogCat.LogError("room_placement_strategy_terminates_map_generation"); + _running = false; return; } @@ -109,6 +121,7 @@ public static class MapGenerator levelGraphEditorSaveData.RoomNodeDataList.Count == 0) { LogCat.LogError("map_generator_attempts_to_parse_empty_layout_diagrams"); + _running = false; return; } @@ -123,6 +136,7 @@ public static class MapGenerator if (startRoomNodeData == null || string.IsNullOrEmpty(startRoomNodeData.Id)) { LogCat.LogError("map_generator_has_no_starting_room_data"); + _running = false; return; } @@ -131,12 +145,16 @@ public static class MapGenerator startRoomNodeData); if (startingRoomPlacementData == null) { + LogCat.LogError("start_room_placement_information_returns_empty"); + _running = false; return; } var placeSuccess = await PlaceRoomAndAddRecord(startRoomNodeData.Id, startingRoomPlacementData, roomDictionary); if (!placeSuccess) { + LogCat.LogError("start_room_placement_failed"); + _running = false; return; } @@ -147,6 +165,7 @@ public static class MapGenerator var roomNodeData = await _layoutParsingStrategy.Next(); if (roomNodeData == null || string.IsNullOrEmpty(roomNodeData.Id)) { + LogCat.LogWarning("room_data_missing"); continue; } @@ -167,14 +186,17 @@ public static class MapGenerator roomNodeData); if (roomPlacementData == null) { + LogCat.LogWithFormat("failed_to_calculate_the_room_location", roomNodeData.Id); continue; } await PlaceRoomAndAddRecord(roomNodeData.Id, roomPlacementData, roomDictionary); } + //All rooms have been placed. //所有房间已放置完毕。 await _roomPlacementStrategy.GeneratedComplete(_mapRoot); + _running = false; } /// @@ -198,15 +220,18 @@ public static class MapGenerator if (dictionary.ContainsKey(roomNodeDataId)) { + LogCat.LogWithFormat("place_existing_rooms", roomNodeDataId); return false; } if (!await _roomPlacementStrategy.PlaceRoom(_mapRoot, roomPlacementData)) { + LogCat.LogWarningWithFormat("room_placement_failed", roomNodeDataId); return false; } dictionary.Add(roomNodeDataId, roomPlacementData.Room); + LogCat.LogWithFormat("room_placement_information",roomNodeDataId,roomPlacementData.Position.ToString()); return true; } } \ No newline at end of file diff --git a/scripts/map/room/RoomFactory.cs b/scripts/map/room/RoomFactory.cs index 3c9d6f3..0ef6993 100644 --- a/scripts/map/room/RoomFactory.cs +++ b/scripts/map/room/RoomFactory.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.IO; +using ColdMint.scripts.utils; using Godot; using FileAccess = Godot.FileAccess; @@ -74,7 +75,7 @@ public static class RoomFactory var room = new Room { - RoomScene = GD.Load(resPath) + RoomScene = GD.Load(ResUtils.GetAbsolutePath(resPath)) }; return room; } diff --git a/scripts/utils/ResUtils.cs b/scripts/utils/ResUtils.cs new file mode 100644 index 0000000..5c022bb --- /dev/null +++ b/scripts/utils/ResUtils.cs @@ -0,0 +1,18 @@ +using System; + +namespace ColdMint.scripts.utils; + +public class ResUtils +{ + /// + /// The game returns the res directory with a.remap suffix at runtime, causing an error while loading the resource + /// 游戏在运行时返回res目录后带有.remap后缀,导致加载资源时出错 + /// + /// + /// + public static string GetAbsolutePath(string path) + { + var index = path.LastIndexOf(".remap", StringComparison.Ordinal); + return index > -1 ? path[..index] : path; + } +} \ No newline at end of file