fix(core): fixed map scopes

This commit is contained in:
Dmitry Popov
2025-12-12 19:48:26 +01:00
parent 07829caf0f
commit 71ae326cf7
2 changed files with 48 additions and 8 deletions
@@ -506,10 +506,25 @@ defmodule WandererApp.Map.Server.SystemsImpl do
# Check if the system matches the map's configured scopes before adding
should_add =
case scopes do
nil -> true
[] -> true
nil ->
true
[] ->
true
scopes when is_list(scopes) ->
ConnectionsImpl.can_add_location(scopes, location.solar_system_id)
# First check: does the location directly match scopes?
if ConnectionsImpl.can_add_location(scopes, location.solar_system_id) do
true
else
# Second check: wormhole border behavior
# If :wormholes scope is enabled AND old_location is a wormhole,
# allow this system to be added as a border system (so you can see
# where your wormhole exits to)
:wormholes in scopes and
not is_nil(old_location) and
ConnectionsImpl.can_add_location([:wormholes], old_location.solar_system_id)
end
end
if should_add do
@@ -227,20 +227,45 @@ defmodule WandererApp.Map.MapScopeFilteringTest do
"Null-sec should be allowed with [:wormholes, :null] scopes"
end
test "maybe_add_system filters out high-sec when scopes is [:wormholes, :null]" do
# When scopes is [:wormholes, :null], high-sec systems should be filtered
test "maybe_add_system filters out high-sec when not jumping from wormhole" do
# When scopes is [:wormholes, :null] and NOT jumping from wormhole,
# high-sec systems should be filtered
location = %{solar_system_id: @hs_system_halenan}
# old_location is nil (no previous system)
result = SystemsImpl.maybe_add_system("map_id", location, nil, [], [:wormholes, :null])
# Returns :ok because system was filtered out (not an error, just skipped)
assert result == :ok
# old_location is also high-sec (k-space to k-space)
old_location = %{solar_system_id: @hs_system_mili}
result = SystemsImpl.maybe_add_system("map_id", location, old_location, [], [:wormholes, :null])
assert result == :ok
end
test "maybe_add_system filters out low-sec when scopes is [:wormholes, :null]" do
test "maybe_add_system filters out low-sec when not jumping from wormhole" do
location = %{solar_system_id: @ls_system_halmah}
result = SystemsImpl.maybe_add_system("map_id", location, nil, [], [:wormholes, :null])
# old_location is high-sec (k-space to k-space)
old_location = %{solar_system_id: @hs_system_halenan}
result = SystemsImpl.maybe_add_system("map_id", location, old_location, [], [:wormholes, :null])
assert result == :ok
end
test "maybe_add_system allows border high-sec when jumping FROM wormhole" do
# When jumping FROM a wormhole TO high-sec with :wormholes scope,
# the high-sec should be added as a border system
location = %{solar_system_id: @hs_system_halenan}
old_location = %{solar_system_id: @wh_system_j100001}
# This should attempt to add the system (not filter it out)
# The result will be an error because the map doesn't exist,
# but that proves the filtering logic allowed it through
result = SystemsImpl.maybe_add_system("map_id", location, old_location, [], [:wormholes])
# The function attempts to add (returns error because map doesn't exist)
# This proves border behavior is working - system was NOT filtered out
assert match?({:error, _}, result),
"Border system should attempt to be added (error because map doesn't exist)"
end
test "is_connection_valid allows WH to HS with [:wormholes, :null] (border behavior)" do
# The connection is valid for border behavior - but individual systems are filtered
assert ConnectionsImpl.is_connection_valid(