summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2018-10-11 17:49:47 +0200 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2018-10-11 17:49:47 +0200 |
commit | aea6e1872eeccffdef926b6561767ff59aecf87e (patch) | |
tree | 78b8848ccfa8d6002075bfe738ac0d66682e8add | |
parent | 4182b46e67185e1f024a24e7cba0d82e24f29baa (diff) |
(Broken) 'spe' to add new map to player.
-rw-r--r-- | src/map/map_shim.erl | 8 | ||||
-rw-r--r-- | src/map/struct/map_map.erl | 34 | ||||
-rw-r--r-- | src/query/qry_shim.erl | 5 | ||||
-rw-r--r-- | src/shared/struct/shr_db_user.erl | 4 | ||||
-rw-r--r-- | src/shared/struct/shr_tile.erl.m4 | 6 | ||||
-rw-r--r-- | src/special/spe_map.erl | 52 | ||||
-rw-r--r-- | src/special/spe_player.erl | 4 |
7 files changed, 95 insertions, 18 deletions
diff --git a/src/map/map_shim.erl b/src/map/map_shim.erl index a7f00cc..600af60 100644 --- a/src/map/map_shim.erl +++ b/src/map/map_shim.erl @@ -7,7 +7,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export([generate_random_map/2]). +-export([generate_random_map/1]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -52,8 +52,8 @@ demo_map () -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec generate_random_map (non_neg_integer(), binary()) -> map_map:type(). -generate_random_map (ID, Owner) -> - Map = map_map:from_list(ID, Owner, 32, 32, demo_map()), +-spec generate_random_map (binary()) -> map_map:type(). +generate_random_map (Owner) -> + Map = map_map:from_list(Owner, 32, 32, demo_map()), Map. diff --git a/src/map/struct/map_map.erl b/src/map/struct/map_map.erl index 55c1a41..0e9474b 100644 --- a/src/map/struct/map_map.erl +++ b/src/map/struct/map_map.erl @@ -9,7 +9,6 @@ ( map, { - id :: id(), owner :: binary(), width :: integer(), height :: integer(), @@ -28,7 +27,6 @@ -export ( [ - get_id/1, get_owner/1, get_width/1, get_height/1, @@ -49,8 +47,9 @@ -export ( [ - from_list/5, - update_from_list/4 + from_list/4, + update_from_list/4, + default/1 ] ). @@ -75,9 +74,6 @@ location_to_array_index (ArrayWidth, {X, Y}) -> %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% Accessors --spec get_id (type()) -> id(). -get_id (Map) -> Map#map.id. - -spec get_owner (type()) -> binary(). get_owner (Map) -> Map#map.owner. @@ -106,19 +102,17 @@ get_tile_instances_field () -> #map.tile_instances. -spec from_list ( - non_neg_integer(), binary(), non_neg_integer(), non_neg_integer(), list(list(non_neg_integer())) ) -> type(). -from_list (ID, Owner, Width, Height, List) -> +from_list (Owner, Width, Height, List) -> TileInstances = lists:map(fun shr_tile:instance_from_ints/1, List), #map { - id = list_to_binary(integer_to_list(ID)), owner = Owner, width = Width, height = Height, @@ -142,3 +136,23 @@ update_from_list (Map, Width, Height, List) -> height = Height, tile_instances = array:from_list(TileInstances) }. + +-spec default (binary()) -> type(). +default (Owner) -> + DefaultTileInstance = shr_tile:default_tile_instance(), + + #map + { + owner = Owner, + width = 32, + height = 32, + tile_instances = + array:new + ( + [ + {size, 1024}, + {default, DefaultTileInstance}, + {fixed, true} + ] + ) + }. diff --git a/src/query/qry_shim.erl b/src/query/qry_shim.erl index d5940d1..f9a959e 100644 --- a/src/query/qry_shim.erl +++ b/src/query/qry_shim.erl @@ -22,8 +22,11 @@ generate_player_0 () -> <<"Player1@tacticians.online">> ), + spe_map:generate(shr_player:get_id(Player)), + Player. + -spec generate_player_1 () -> shr_player:type(). generate_player_1 () -> Player = @@ -34,6 +37,8 @@ generate_player_1 () -> <<"Player2@tacticians.online">> ), + spe_map:generate(shr_player:get_id(Player)), + Player. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/shared/struct/shr_db_user.erl b/src/shared/struct/shr_db_user.erl index 6087833..8368024 100644 --- a/src/shared/struct/shr_db_user.erl +++ b/src/shared/struct/shr_db_user.erl @@ -31,4 +31,6 @@ can_access (janitor, janitor) -> true; can_access (List, {user, User}) -> lists:member({user, User}, List); can_access (List, janitor) -> - lists:member(janitor, List). + lists:member(janitor, List); +can_access (List, User) -> + can_access(List, {user, User}). diff --git a/src/shared/struct/shr_tile.erl.m4 b/src/shared/struct/shr_tile.erl.m4 index 750e59a..906dc84 100644 --- a/src/shared/struct/shr_tile.erl.m4 +++ b/src/shared/struct/shr_tile.erl.m4 @@ -42,7 +42,8 @@ ( [ instance_to_int_list/1, - instance_from_ints/1 + instance_from_ints/1, + default_tile_instance/0 ] ). @@ -123,3 +124,6 @@ instance_from_ints (L) -> -spec instance_to_int_list (instance()) -> list(non_neg_integer()). instance_to_int_list (I) -> I. + +-spec default_tile_instance () -> instance(). +default_tile_instance () -> [1, 0]. diff --git a/src/special/spe_map.erl b/src/special/spe_map.erl new file mode 100644 index 0000000..f12b0aa --- /dev/null +++ b/src/special/spe_map.erl @@ -0,0 +1,52 @@ +-module(spe_map). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-export([generate/1]). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec generate (binary()) -> map_map:type(). +generate (OwnerID) -> + Map = map_map:default(OwnerID), + + {ok, MapID} = + shr_database:insert + ( + map_db, + any, + [{user, OwnerID}], + Map + ), + + MapSummary = shr_map_summary:new(<<"Untitled Map">>, MapID), + + PlayerUpdateQueryOps = + [ + %% FIXME: shr_db_query:add_to_field handles lists, + %% shr_player:get_map_summaries_field() points to an array. + shr_db_query:add_to_field + ( + shr_player:get_map_summaries_field(), + [MapSummary], + false + ) + ], + + ok = + shr_database:commit + ( + shr_db_query:new(player_db, OwnerID, admin, PlayerUpdateQueryOps) + ), + + Map. diff --git a/src/special/spe_player.erl b/src/special/spe_player.erl index 6f0eebc..a74f53a 100644 --- a/src/special/spe_player.erl +++ b/src/special/spe_player.erl @@ -52,7 +52,7 @@ generate_inventory (PlayerID) -> shr_database:insert ( inventory_db, - [{user, PlayerID}], + any, [{user, PlayerID}], Inventory ), @@ -66,7 +66,7 @@ generate_roster (PlayerID) -> shr_database:insert ( roster_db, - [{user, PlayerID}], + any, [{user, PlayerID}], Roster ), |