367 lines
16 KiB
Erlang
367 lines
16 KiB
Erlang
%%----------------------------------------------------
|
|
%% 数据配置文件
|
|
%% @author whjing2011@gmail.com
|
|
%%----------------------------------------------------
|
|
-module(map_data).
|
|
-export([cfg/0, init_data/2]).
|
|
-include("data_config.hrl").
|
|
-include("common.hrl").
|
|
-include("map.hrl").
|
|
cfg() ->
|
|
#data_cfg{
|
|
name = map_data
|
|
,desc = "地图数据"
|
|
,source = "map_data.xml"
|
|
,target = "map_data.erl"
|
|
,sheet = [
|
|
{["DATA"], [
|
|
#f_column{type = int, name = bid, desc = "场景ID", primary = true, mod = all}
|
|
,#f_column{type = str, name = name, desc = "场景名称", mod = all}
|
|
,#f_column{type = int, name = type, desc = "场景类型", mod = all}
|
|
,#f_column{type = int, name = client_type, desc = "客户端类型",val = "0", mod = client}
|
|
,#f_column{type = str, name = desc, desc = "场景描述", mod = all}
|
|
,#f_column{type = str, name = music, desc = "场景音乐", mod = all}
|
|
,#f_column{type = int, name = min_lev, desc = "最小等级", val = "0", mod = all}
|
|
,#f_column{type = int, name = max_lev, desc = "最大等级", val = "0", mod = all}
|
|
,#f_column{type = str, name = battle_music, desc = "战斗音乐", mod = client}
|
|
|
|
]}
|
|
]
|
|
}.
|
|
|
|
init_data(DataCfg, SheetDatas) ->
|
|
put(walkable_num_list, []),
|
|
put(walkable_srv_list, []),
|
|
put(walkable_cli_list, []),
|
|
put(tile_res_srv_list, []),
|
|
put(map_srv_list, []),
|
|
put(map_cli_list, []),
|
|
put(map_ids, []),
|
|
put(map_start_ids, []),
|
|
put(map_type_ids, []),
|
|
put(unit_list, []),
|
|
put(unit_list_cli, []),
|
|
put(unit_id, 1),
|
|
put(world_unit_cli, []),
|
|
do_sheets(SheetDatas, DataCfg),
|
|
save_erl_file(),
|
|
save_lua_file(),
|
|
{DataCfg, SheetDatas}.
|
|
do_sheets([], _DataCfg) -> ok;
|
|
do_sheets([{_, _, Rows} | T], DataCfg) ->
|
|
do_rows(Rows),
|
|
do_sheets(T, DataCfg).
|
|
do_rows([]) -> ok;
|
|
do_rows([Row | T]) ->
|
|
do_row(Row),
|
|
do_rows(T).
|
|
do_row(Row) ->
|
|
Bid = cb_fun:get_val(bid, Row),
|
|
Mod = list_to_atom(lists:concat(["map_data_", Bid])),
|
|
Type = list_to_integer(cb_fun:get_val(type, Row)),
|
|
do_map(Bid, Type, Row, Mod:info()).
|
|
|
|
do_map(Bid, Type = 99, Row, #map_data{id = Id, walkable = Walkable, width = Width, height = Height, max_pre_layer = MaxPreLayer, tile_w = TileW, tile_h = TileH, start_type = StartType, unit_list = UnitList, rows = Rows, cols = Cols, back_res_id = BackId, res_id = ResId, fill_type = FillType, back_res_w = BackResW, back_res_h = BackResH, back_res_x = BackResX, back_res_y = BackResY, res_w = ResW, res_h = ResH, map_mod = MapMod, tile_res_list = TileResList, tile_res_info = TileResInfo}) -> %% 大世界
|
|
?P("do_map===>[~s]~n", [Bid]),
|
|
Name = cb_fun:get_val(name, Row),
|
|
CliName = cb_fun_lua:get_val(name, Row),
|
|
CliDesc = cb_fun_lua:get_val(desc, Row),
|
|
Music = cb_fun:get_val(music, Row),
|
|
ClientType = cb_fun:get_val(client_type, Row),
|
|
MinLev = cb_fun:get_val(min_lev, Row),
|
|
MaxLev = cb_fun:get_val(max_lev, Row),
|
|
WalkableSrv = "[" ++ string:join([util:to_string(Xl) || Xl <- Walkable], ",\n") ++ "]",
|
|
TileResSrv = "[" ++ string:join([util:to_string(Xl) || Xl <- TileResInfo], ",\n") ++ "]",
|
|
put(tile_res_srv_list, [?S("get(~ts) -> ~ts;", [Bid, TileResSrv]) | get(tile_res_srv_list)]),
|
|
WalkableNum = length(lists:flatten([[X || X <- Xl, X =:= 0] || Xl <- Walkable])),
|
|
ReliveList = [#unit_data{x = DefX, y = DefY} | _] = [E || E <- UnitList, E#unit_data.type =:= 0],
|
|
UnitList0 = [E#unit_data{id = put(unit_id,get(unit_id)+1)} || E <- UnitList, E#unit_data.type =/= 0],
|
|
put(world_unit_cli, grid_unit(UnitList0, Bid, get(world_unit_cli))),
|
|
CliStr = ?S("
|
|
[~ts] = {
|
|
bid = ~ts,
|
|
type = ~w,
|
|
client_type = ~ts,
|
|
min_lev = ~ts,
|
|
max_lev = ~ts,
|
|
name = '~ts',
|
|
def_x = ~w,
|
|
def_y = ~w,
|
|
width = ~w,
|
|
height = ~w,
|
|
rows = ~w,
|
|
cols = ~w,
|
|
tile_w = ~w,
|
|
tile_h = ~w,
|
|
backId = ~w,
|
|
sourceId = ~w,
|
|
fill_type = ~w,
|
|
b_img_w = ~w,
|
|
b_img_h = ~w,
|
|
b_img_x = ~w,
|
|
b_img_y = ~w,
|
|
s_img_w = ~w,
|
|
s_img_h = ~w,
|
|
misc_depict = '~ts',
|
|
misc_music = ~ts,
|
|
}", [Bid, Bid, Type,ClientType, MinLev, MaxLev, CliName, DefX, DefY, Width, Height, Rows, Cols, TileW, TileH, BackId, ResId, FillType, BackResW, BackResH, BackResX, BackResY, ResW, ResH, CliDesc, Music]),
|
|
put(map_cli_list, [CliStr | get(map_cli_list)]),
|
|
MapStr = ?S("
|
|
get(~ts) ->
|
|
#map_data{
|
|
bid = ~ts
|
|
,type = ~w
|
|
,name = ~ts
|
|
,width = ~w
|
|
,height = ~w
|
|
,def_xy = {~w,~w}
|
|
,grid_x = ~w
|
|
,grid_y = ~w
|
|
,min_lev = ~ts
|
|
,max_lev = ~ts
|
|
,max_pre_layer = ~w
|
|
,is_single = ~w
|
|
,start_type = ~w
|
|
,relive = ~ts
|
|
,unit_list = ~ts
|
|
,tile_res_list = [~ts]
|
|
};", [Bid, Bid, Type, Name, Width, Height, DefX, DefY, TileW, TileH, MinLev, MaxLev, MaxPreLayer, MapMod, StartType, util:to_string([{X,Y} || #unit_data{x = X, y = Y} <- ReliveList]), util:to_string([{Id1,Bid1, X,Y} || #unit_data{id=Id1,bid=Bid1, tx=X, ty=Y} <- UnitList0]), string:join([?S("#{id=>~w,evtid=>~w,list=>~ts}", [Id2,EvtId2,util:to_string(List2)])||#{id:=Id2,evtid:=EvtId2,list:=List2} <- TileResList],",")]),
|
|
put(map_srv_list, [MapStr | get(map_srv_list)]),
|
|
put(walkable_num_list, [?S("num(~ts) -> ~w;", [Bid, WalkableNum]) | get(walkable_num_list)]),
|
|
case get(WalkableSrv) of
|
|
undefined ->
|
|
put(WalkableSrv, Bid),
|
|
put(walkable_srv_list, [?S("get(~ts) -> ~ts;", [Bid, WalkableSrv]) | get(walkable_srv_list)]),
|
|
WalkableCli = "{" ++ string:join([util:to_string(list_to_tuple(Xl)) || Xl <- Walkable], ",\n") ++ "}",
|
|
put(walkable_cli_list, [?S("if bid == ~ts then return ~ts end", [Bid, WalkableCli]) | get(walkable_cli_list)]);
|
|
Bid1 ->
|
|
put(walkable_srv_list, [?S("get(~ts) -> ?MODULE:get(~ts);", [Bid, Bid1]) | get(walkable_srv_list)]),
|
|
put(walkable_cli_list, [?S("if bid == ~ts then return Config.MapBlock.get(~ts) end", [Bid, Bid1]) | get(walkable_cli_list)])
|
|
end,
|
|
ok;
|
|
do_map(Bid, Type, Row, #map_data{id = Id, walkable = Walkable, width = Width, height = Height, max_pre_layer = MaxPreLayer, tile_w = TileW, tile_h = TileH, start_type = StartType, unit_list = UnitList, rows = Rows, cols = Cols, back_res_id = BackId, res_id = ResId, fill_type = FillType, back_res_w = BackResW, back_res_h = BackResH, back_res_x = BackResX, back_res_y = BackResY, res_w = ResW, res_h = ResH, map_mod = MapMod, tile_res_list = TileResList, tile_res_info = TileResInfo}) ->
|
|
?P("do_map===>[~s]~n", [Bid]),
|
|
Name = cb_fun:get_val(name, Row),
|
|
CliName = cb_fun_lua:get_val(name, Row),
|
|
CliDesc = cb_fun_lua:get_val(desc, Row),
|
|
ClientType = cb_fun:get_val(client_type, Row),
|
|
Music = cb_fun:get_val(music, Row),
|
|
MinLev = cb_fun:get_val(min_lev, Row),
|
|
MaxLev = cb_fun:get_val(max_lev, Row),
|
|
WalkableSrv = "[" ++ string:join([util:to_string(Xl) || Xl <- Walkable], ",\n") ++ "]",
|
|
TileResSrv = "[" ++ string:join([util:to_string(Xl) || Xl <- TileResInfo], ",\n") ++ "]",
|
|
put(tile_res_srv_list, [?S("get(~ts) -> ~ts;", [Bid, TileResSrv]) | get(tile_res_srv_list)]),
|
|
WalkableNum = length(lists:flatten([[X || X <- Xl, X =:= 0] || Xl <- Walkable])),
|
|
ReliveList = [#unit_data{x = DefX, y = DefY} | _] = [E || E <- UnitList, E#unit_data.type =:= 0],
|
|
UnitList0 = [E#unit_data{id = put(unit_id,get(unit_id)+1)} || E <- UnitList, E#unit_data.type =:= 1],
|
|
EffList = [E || E <- UnitList, E#unit_data.type =:= 2],
|
|
put(unit_list, [?S("get(~w) -> {~w,~w,~w};",[Bid1,Id,X,Y])||#unit_data{bid=Bid1,x=X,y=Y}<-UnitList0] ++ get(unit_list)),
|
|
put(unit_list, [?S("get({1,~w}) -> {~w,~w,~w};",[Id1,Id,X,Y])||#unit_data{id = Id1,x=X,y=Y}<-UnitList0] ++ get(unit_list)),
|
|
put(unit_list_cli, [?S("\t[~w] = {~w,~w,~w}",[Bid1,Id,X,Y])||#unit_data{bid=Bid1,x=X,y=Y}<-UnitList0] ++ get(unit_list_cli)),
|
|
put(map_ids, [Id | get(map_ids)]),
|
|
case StartType of
|
|
1 -> put(map_start_ids, [Id | get(map_start_ids)]);
|
|
_ -> skip
|
|
end,
|
|
case lists:keyfind(Type, 1, get(map_type_ids)) of
|
|
false -> put(map_type_ids, [{Type, [Id]} | get(map_type_ids)]);
|
|
{_, L1} -> put(map_type_ids, lists:keyreplace(Type, 1, get(map_type_ids), {Type, [Id | L1]}))
|
|
end,
|
|
CliStr = ?S("
|
|
[~ts] = {
|
|
bid = ~ts,
|
|
type = ~w,
|
|
client_type = ~ts,
|
|
min_lev = ~ts,
|
|
max_lev = ~ts,
|
|
name = '~ts',
|
|
def_x = ~w,
|
|
def_y = ~w,
|
|
width = ~w,
|
|
height = ~w,
|
|
rows = ~w,
|
|
cols = ~w,
|
|
tile_w = ~w,
|
|
tile_h = ~w,
|
|
backId = ~w,
|
|
sourceId = ~w,
|
|
fill_type = ~w,
|
|
b_img_w = ~w,
|
|
b_img_h = ~w,
|
|
b_img_x = ~w,
|
|
b_img_y = ~w,
|
|
s_img_w = ~w,
|
|
s_img_h = ~w,
|
|
eff_list = ~ts,
|
|
unit_list = ~ts,
|
|
misc_depict = '~ts',
|
|
misc_music = ~ts,
|
|
}", [Bid, Bid, Type,ClientType, MinLev, MaxLev, CliName, DefX, DefY, Width, Height, Rows, Cols, TileW, TileH, BackId, ResId, FillType, BackResW, BackResH, BackResX, BackResY, ResW, ResH,util:to_string(list_to_tuple([{Bid1,X,Y,Layer}||#unit_data{bid=Bid1,x=X,y=Y,layer=Layer}<-EffList])), util:to_string(list_to_tuple([{Bid1,X,Y,Id1,Layer} || #unit_data{id=Id1,bid=Bid1,x=X,y=Y,layer=Layer}<-UnitList0])), CliDesc, Music]),
|
|
put(map_cli_list, [CliStr | get(map_cli_list)]),
|
|
MapStr = ?S("
|
|
get(~ts) ->
|
|
#map_data{
|
|
bid = ~ts
|
|
,type = ~w
|
|
,name = ~ts
|
|
,width = ~w
|
|
,height = ~w
|
|
,def_xy = {~w,~w}
|
|
,grid_x = ~w
|
|
,grid_y = ~w
|
|
,min_lev = ~ts
|
|
,max_lev = ~ts
|
|
,max_pre_layer = ~w
|
|
,is_single = ~w
|
|
,start_type = ~w
|
|
,relive = ~ts
|
|
,unit_list = ~ts
|
|
,tile_res_list = [~ts]
|
|
};", [Bid, Bid, Type, Name, Width, Height, DefX, DefY, TileW, TileH, MinLev, MaxLev, MaxPreLayer, MapMod, StartType, util:to_string([{X,Y} || #unit_data{x = X, y = Y} <- ReliveList]), util:to_string([{Id1,Bid1, X,Y} || #unit_data{id=Id1,bid=Bid1, x=X, y=Y} <- UnitList0]), string:join([?S("#{id=>~w,evtid=>~w,list=>~ts}", [Id2,EvtId2,util:to_string(List2)])||#{id:=Id2,evtid:=EvtId2,list:=List2} <- TileResList],",")]),
|
|
put(map_srv_list, [MapStr | get(map_srv_list)]),
|
|
put(walkable_num_list, [?S("num(~ts) -> ~w;", [Bid, WalkableNum]) | get(walkable_num_list)]),
|
|
case get(WalkableSrv) of
|
|
undefined ->
|
|
put(WalkableSrv, Bid),
|
|
put(walkable_srv_list, [?S("get(~ts) -> ~ts;", [Bid, WalkableSrv]) | get(walkable_srv_list)]),
|
|
WalkableCli = "{" ++ string:join([util:to_string(list_to_tuple(Xl)) || Xl <- Walkable], ",\n") ++ "}",
|
|
put(walkable_cli_list, [?S("if bid == ~ts then return ~ts end", [Bid, WalkableCli]) | get(walkable_cli_list)]);
|
|
Bid1 ->
|
|
put(walkable_srv_list, [?S("get(~ts) -> ?MODULE:get(~ts);", [Bid, Bid1]) | get(walkable_srv_list)]),
|
|
put(walkable_cli_list, [?S("if bid == ~ts then return Config.MapBlock.get(~ts) end", [Bid, Bid1]) | get(walkable_cli_list)])
|
|
end,
|
|
ok;
|
|
do_map(Bid, _Type, _Row, _) ->
|
|
?P("skip_map===>[~ts]~n", [Bid]),
|
|
skip.
|
|
|
|
%% 九宫格
|
|
grid_unit([], _Bid, L) ->
|
|
L;
|
|
grid_unit([#unit_data{bid = Bid, id = Id, tx = Tx, ty = Ty} | T], MapBid, L) ->
|
|
grid_unit(T, MapBid, [{MapBid, Tx, Ty, Id, Bid} | L]).
|
|
|
|
%% 保存服务端文件
|
|
save_erl_file() ->
|
|
S0 = ?S("
|
|
%% ---------------------------------------
|
|
%% 地图数据
|
|
%% @author cayleung@gmail.com
|
|
%% @end
|
|
%% ---------------------------------------
|
|
-module(map_data).
|
|
-export([
|
|
ids/1, get/1
|
|
]
|
|
).
|
|
-include(\"common.hrl\").
|
|
-include(\"map.hrl\").
|
|
|
|
ids(all) -> ~ts;
|
|
ids(start) -> ~ts;
|
|
~ts
|
|
ids(_) -> [].
|
|
|
|
~ts
|
|
get(_) -> undefined.
|
|
", [util:to_string(getr(map_ids)), util:to_string(getr(map_start_ids)), string:join([?S("ids({type,~w}) -> ~ts;", [Type, util:to_string(lists:reverse(Ids))]) || {Type,Ids} <- getr(map_type_ids)], "\n"), string:join(getr(map_srv_list), "")]),
|
|
write_file("../../server_core_data/data/", "./out/", "map_data.erl", list_to_binary(S0)),
|
|
|
|
S = ?S("%%----------------------------------------------------
|
|
%% 地图可行走区域\n
|
|
%%----------------------------------------------------
|
|
-module(map_data_walkable).
|
|
-export([get/1, num/1]).
|
|
|
|
~ts
|
|
num(_) -> 0.
|
|
|
|
~ts
|
|
get(_) -> undefined.
|
|
", [string:join(getr(walkable_num_list), "\n"), string:join(getr(walkable_srv_list), "\n")]),
|
|
write_file("../../server_core_data/data/", "./out/", "map_data_walkable.erl", S),
|
|
|
|
S1 = ?S("%% ---------------------------------------
|
|
%% 地图NPC数据
|
|
%% ---------------------------------------
|
|
-module(map_unit_data).
|
|
-export([
|
|
get/1
|
|
,get_map/1
|
|
]
|
|
).
|
|
-include(\"common.hrl\").
|
|
|
|
~ts
|
|
get(_) -> undefined.
|
|
|
|
get_map(NpcBid) ->
|
|
case ?MODULE:get(NpcBid) of
|
|
{MapBid, _, _} -> MapBid;
|
|
_Else -> 0
|
|
end.
|
|
", [string:join(getr(unit_list), "\n")]),
|
|
write_file("../../server_core_data/data/", "./out/", "map_unit_data.erl", S1),
|
|
|
|
S2 = ?S("%%----------------------------------------------------
|
|
%% 地图地貌\n
|
|
%%----------------------------------------------------
|
|
-module(map_data_tile_res).
|
|
-export([get/1]).
|
|
|
|
~ts
|
|
get(_) -> undefined.
|
|
", [string:join(getr(tile_res_srv_list), "\n")]),
|
|
write_file("../../server_core_data/data/", "./out/", "map_data_tile_res.erl", S2).
|
|
|
|
%% 保存客户端文件
|
|
save_lua_file() ->
|
|
S1 = ?S("
|
|
----------------------------------------------------------
|
|
-- 地图障碍配置
|
|
----------------------------------------------------------
|
|
Config = Config or {}
|
|
Config.MapBlock = {}
|
|
Config.MapBlock.data = function(bid)
|
|
~ts
|
|
end
|
|
|
|
Config.MapBlock.get = function(bid)
|
|
if not Config.MapBlock[bid] then
|
|
local base = Config.MapBlock.data(bid)
|
|
if not base then return end
|
|
Config.MapBlock[bid] = base
|
|
end
|
|
return Config.MapBlock[bid]
|
|
end
|
|
", [string:join(getr(walkable_cli_list), "\n")]),
|
|
write_file("../../client_config_core/src/config/", "./out/", "config_map_block.lua", S1),
|
|
S2 = ?S("
|
|
Config = Config or {}
|
|
Config.Map =
|
|
{ ~ts
|
|
}
|
|
", [string:join(getr(map_cli_list), ",")]),
|
|
write_file("../../client_config_core/src/config/", "./out/", "config_map.lua", S2),
|
|
S3 = ?S("Config = Config or {}
|
|
Config.MapUnit ={
|
|
~ts
|
|
}", [string:join(getr(unit_list_cli), ",\n")]),
|
|
write_file("../../client_config_core/src/config/", "./out/", "config_map_unit.lua", S3),
|
|
S4 = ?S("Config = Config or {}
|
|
Config.WorldUnit ={
|
|
~ts
|
|
}", [string:join([?S("['~ts_~w_~w'] = {~w,~w}", [MBid, X, Y, Id, Bid]) || {MBid,X,Y, Id, Bid} <- get(world_unit_cli)], ",\n")]),
|
|
write_file("../../client_config_core/src/config/", "./out/", "config_world_unit.lua", S4).
|
|
|
|
write_file(Path, DefPath, File, S) ->
|
|
case filelib:is_dir(Path) andalso get(gen_demo) =:= undefined of
|
|
true ->
|
|
?P("save=======>~ts~ts~n", [Path, File]),
|
|
file:write_file(Path ++ File, S);
|
|
_ ->
|
|
?P("save=======>~ts~ts~n", [DefPath, File]),
|
|
file:write_file(DefPath ++ File, S)
|
|
end.
|
|
getr(Key) -> lists:reverse(get(Key)).
|