Files
fc/server/tools/gen_data/cfg/battle_map_data.erl
T

118 lines
5.1 KiB
Erlang
Raw Normal View History

2026-05-23 22:10:14 +08:00
%%----------------------------------------------------
%% 數據配置文件
%% @author whjing2011@gmail.com
%%----------------------------------------------------
-module(battle_map_data).
-export([cfg/0, init_data/2]).
-include("data_config.hrl").
-include("common.hrl").
cfg() ->
#data_cfg{
name = battle_map_data
,lua_name = battle_map_data
,desc = "配置數據"
%% ,source = "battle_map_data.xml"
,source = undefined
,target = "battle_map_data.erl"
,inc = []
,callback = [
]
,callback_cli = [
]
,sheet = [
{["地圖數據"], [
#f_column{type = int, name = bid, desc = "地圖BID", primary = true, mod = client}
,#f_column{type = int, name = sourceId, desc = "主資源ID", mod = client}
,#f_column{type = int, name = width, desc = "地圖寬度", mod = client}
,#f_column{type = int, name = height, desc = "地圖高度", mod = client}
,#f_column{type = int, name = tile_h, desc = "格子高", mod = client}
,#f_column{type = int, name = tile_w, desc = "格子寬", mod = client}
,#f_column{type = int, name = b_img_w, desc = "前景層寬度", mod = client}
,#f_column{type = int, name = b_img_h, desc = "前景層高度", mod = client}
,#f_column{type = int, name = s_img_w, desc = "場景層寬度", mod = client}
,#f_column{type = int, name = s_img_h, desc = "場景層高度", mod = client}
,#f_column{type = int, name = backId, desc = "背景資源ID", mod = client}
,#f_column{type = int, name = posGroup, desc = "位置組", mod = client}
]},
{["位置數據"],[
#f_column{type = int, name = posGroupID, desc = "位置組ID", mod = client}
,#f_column{type = term, name = role_pos_list, desc = "人物位置", mod = client}
,#f_column{type = term, name = mon_pos_list, desc = "怪物位置", mod = client}
,#f_column{type = term, name = role_born_pos_list, desc = "人物出生點", mod = client}
,#f_column{type = term, name = mon_born_pos_list, desc = "怪物出生點", mod = client}
,#f_column{type = term, name = camera_pos_list, desc = "攝像機點", mod = client}
]}
]
}.
init_data(DataCfg, SheetDatas) ->
put(battle_map_list, []),
FileList = filelib:fold_files( "../gen_data/battle_map", ".erl", false, fun(File, Acc) -> [File|Acc] end, []),
CFun = fun(E)->
SS = string:tokens(E, "/"),
Name=string:tokens(lists:last(SS), "."),
[H | _] = Name,
[list_to_atom(H)]
end,
ModList = lists:flatmap(CFun, FileList),
%%ModList = main:cfg_file("../../../editor/data/battle_map"),
[do_file(Mod) || Mod <- lists:sort(ModList)],
S = ?S("--------------------------------------
-- 此文件由數據工具生成 戰鬥地圖
--------------------------------------
Config = Config or {}
Config.BattleMapData = Config.BattleMapData or {}
Config.BattleMapData.get = {~ts}
", [string:join(lists:reverse(get(battle_map_list)), ",\n\t")]),
%% ?P("===~ts", [S]),
write_file("../../client/src/config/", "./out/", "battle_map_data.lua", S),
{DataCfg, SheetDatas}.
do_file(Mod) ->
#{id := Id, res_id := ResId, back_res_id := BackResId, width := Width, height := Height, res_w := ResW, res_h := ResH, back_res_w := BackResW, back_res_h := BackResH, back_res_x := BackResX, back_res_y := BackResY, fighter_list := FList} = Mod:info(),
FList1 = do_fighter_list(FList, []),
FS = string:join([?S("\t\t[~w]={\n~s\n\t\t}", [Wave, string:join(lists:sort(L1), ",\n")]) || {Wave, L1} <- FList1], ",\n"),
S = ?S("
[~w] = {
id = ~w
,res_id = '~s'
,back_res_id = '~s'
,width = ~w
,height = ~w
,s_res_w = ~w
,s_res_h = ~w
,b_res_w = ~w
,b_res_h = ~w
,b_res_x = ~w
,b_res_y = ~w
,pos_info = {
~s
}
}
", [Id, Id, ResId, BackResId, Width, Height, ResW, ResH, BackResW, BackResH, BackResX, BackResY, FS]),
%% ?P("===~s", [S]),
put(battle_map_list, [S | get(battle_map_list)]).
do_fighter_list([], L) ->
lists:keysort(1, L);
do_fighter_list([I = #{ wave := Wave, type := Type} | T], L) ->
Fun = fun(#{wave := Wave1, type := Type1}) -> Wave =:= Wave1 andalso Type =:= Type1 end,
{L1, L2} = lists:partition(Fun, T),
TypeS = ?S("\t\t\t[~w]={\n~s\n\t\t\t}", [Type, string:join([?S("\t\t\t\t[~w]={x=~w,y=~w}", [Bid, X, Y]) || #{bid := Bid, x := X, y := Y} <- [I | L1]], ",\n")]),
NewL =
case lists:keyfind(Wave, 1, L) of
false ->
[{Wave, [TypeS]} | L];
{Wave, L3} ->
lists:keyreplace(Wave, 1, L, {Wave, [TypeS | L3]})
end,
do_fighter_list(L2, NewL).
write_file(Path, DefPath, File, S) ->
?P("save=======>~ts~n", [File]),
case filelib:is_dir(Path) of
true -> file:write_file(Path ++ File, S);
_ -> file:write_file(DefPath ++ File, S)
end.