Skip to content

Commit

Permalink
Merge pull request #2131 from Wotuu/development
Browse files Browse the repository at this point in the history
Release v7.6 - Combined floors (as in MDT) for new dungeons now available
  • Loading branch information
Wotuu authored Nov 21, 2023
2 parents 2e09fe6 + 22b1b78 commit 07accbc
Show file tree
Hide file tree
Showing 67 changed files with 1,568 additions and 921 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/resouces/assets/js/precompile.js
/storage/*.key
/storage/debugbar/*.json
/storage/framework/maintenance.php
/vendor
/version
/.idea
Expand All @@ -34,4 +35,4 @@ docker-compose/mysql
docker-compose/mysql-combatlog
docker-compose/laravel-echo-server/laravel-echo-server.json
docker-compose/laravel-echo-server/laravel-echo-server.lock
docker-compose/redis-data
docker-compose/redis-data
2 changes: 1 addition & 1 deletion app/Console/Commands/MDT/ExportMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function handle(MDTMappingExportServiceInterface $mappingExportService)
continue;
}

$currentMappingVersion = $dungeon->getCurrentMappingVersion();
$currentMappingVersion = $dungeon->currentMappingVersion;
if ($currentMappingVersion === null) {
$this->comment(sprintf('Skipping %s, no current mapping version found', __($dungeon->name)));
continue;
Expand Down
31 changes: 23 additions & 8 deletions app/Http/Controllers/Ajax/AjaxBrushlineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Models\Brushline;
use App\Models\DungeonRoute;
use App\Models\Polyline;
use App\Service\Coordinates\CoordinatesServiceInterface;
use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Contracts\Routing\ResponseFactory;
Expand All @@ -23,14 +24,19 @@ class AjaxBrushlineController extends Controller
use SavesPolylines;

/**
* @param APIBrushlineFormRequest $request
* @param DungeonRoute $dungeonRoute
* @param Brushline|null $brushline
* @param APIBrushlineFormRequest $request
* @param CoordinatesServiceInterface $coordinatesService
* @param DungeonRoute $dungeonRoute
* @param Brushline|null $brushline
* @return Brushline
* @throws AuthorizationException
*/
function store(APIBrushlineFormRequest $request, DungeonRoute $dungeonRoute, ?Brushline $brushline = null)
{
function store(
APIBrushlineFormRequest $request,
CoordinatesServiceInterface $coordinatesService,
DungeonRoute $dungeonRoute,
?Brushline $brushline = null
) {
$dungeonRoute = optional($brushline)->dungeonRoute ?? $dungeonRoute;

$this->authorize('edit', $dungeonRoute);
Expand All @@ -54,11 +60,20 @@ function store(APIBrushlineFormRequest $request, DungeonRoute $dungeonRoute, ?Br
try {
if ($success) {
// Create a new polyline and save it
$polyline = $this->savePolyline(Polyline::findOrNew($brushline->polyline_id), $brushline, $validated['polyline']);
$changedFloor = null;
$polyline = $this->savePolyline(
$coordinatesService,
$dungeonRoute->mappingVersion,
Polyline::findOrNew($brushline->polyline_id),
$brushline,
$validated['polyline'],
$changedFloor
);

// Couple the path to the polyline
$brushline->update([
'polyline_id' => $polyline->id,
'floor_id' => optional($changedFloor)->id ?? $brushline->floor_id,
]);

// Load the polyline so it can be echoed back to the user
Expand All @@ -84,9 +99,9 @@ function store(APIBrushlineFormRequest $request, DungeonRoute $dungeonRoute, ?Br
}

/**
* @param Request $request
* @param Request $request
* @param DungeonRoute $dungeonRoute
* @param Brushline $brushline
* @param Brushline $brushline
* @return Response|ResponseFactory
* @throws AuthorizationException
*/
Expand Down
7 changes: 5 additions & 2 deletions app/Http/Controllers/Ajax/AjaxDungeonRouteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public function list(Request $request)
// Which relationship should be load?
$tagsRelationshipName = $teamPublicKey ? 'tagsteam' : 'tagspersonal';

$routes = DungeonRoute::with(['dungeon', 'affixes', 'author', 'routeattributes', 'ratings', 'metricAggregations', $tagsRelationshipName])
$routes = DungeonRoute::with(['faction', 'specializations', 'classes', 'races', 'dungeon', 'affixes',
'author', 'routeattributes', 'ratings', 'metricAggregations', $tagsRelationshipName])
// Specific selection of dungeon columns; if we don't do it somehow the Affixes and Attributes of the result is cleared.
// Probably selecting similar named columns leading Laravel to believe the relation is already satisfied.
->selectRaw('dungeon_routes.*, mapping_versions.enemy_forces_required_teeming, mapping_versions.enemy_forces_required, MAX(mapping_versions.id) as dungeon_latest_mapping_version_id')
Expand Down Expand Up @@ -234,7 +235,8 @@ public function htmlsearch(APIDungeonRouteSearchFormRequest $request, ExpansionS
$expansion = $expansionService->getCurrentExpansion(GameServerRegion::getUserOrDefaultRegion());
}

$query = DungeonRoute::with(['author', 'affixes', 'ratings', 'routeattributes', 'dungeon', 'mappingVersion'])
$query = DungeonRoute::with(['faction', 'specializations', 'classes', 'races', 'author', 'affixes',
'ratings', 'routeattributes', 'dungeon', 'dungeon.activeFloors', 'mappingVersion'])
->join('dungeons', 'dungeon_routes.dungeon_id', 'dungeons.id')
->join('mapping_versions', 'mapping_versions.dungeon_id', 'dungeons.id')
->when($expansion !== null, function (Builder $builder) use ($expansion) {
Expand Down Expand Up @@ -348,6 +350,7 @@ public function htmlsearch(APIDungeonRouteSearchFormRequest $request, ExpansionS
'dungeonroutes' => $result,
'showAffixes' => true,
'showDungeonImage' => true,
'orientation' => 'horizontal',
])->render();
}
}
Expand Down
49 changes: 37 additions & 12 deletions app/Http/Controllers/Ajax/AjaxMapIconController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use App\Models\MapIconType;
use App\Models\Mapping\MappingModelInterface;
use App\Models\Team;
use App\Service\Coordinates\CoordinatesServiceInterface;
use App\User;
use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Contracts\Routing\ResponseFactory;
Expand All @@ -34,14 +36,19 @@ protected function shouldCallMappingChanged(?MappingModelInterface $beforeModel,
}

/**
* @param MapIconFormRequest $request
* @param ?DungeonRoute $dungeonRoute
* @param MapIcon|null $mapIcon
* @param MapIconFormRequest $request
* @param CoordinatesServiceInterface $coordinatesService
* @param ?DungeonRoute $dungeonRoute
* @param MapIcon|null $mapIcon
* @return MapIcon|Model
* @throws AuthorizationException
* @throws Throwable
*/
public function store(MapIconFormRequest $request, ?DungeonRoute $dungeonRoute, MapIcon $mapIcon = null): MapIcon
public function store(
MapIconFormRequest $request,
CoordinatesServiceInterface $coordinatesService,
?DungeonRoute $dungeonRoute,
MapIcon $mapIcon = null): MapIcon
{
$dungeonRoute = optional($mapIcon)->dungeonRoute ?? $dungeonRoute;
$validated = $request->validated();
Expand Down Expand Up @@ -69,24 +76,42 @@ public function store(MapIconFormRequest $request, ?DungeonRoute $dungeonRoute,
}
}

return $this->storeModel($validated, MapIcon::class, $mapIcon, function (MapIcon $mapIcon) use ($validated, $dungeonRoute) {
return $this->storeModel($validated, MapIcon::class, $mapIcon, function (MapIcon $mapIcon) use ($validated, $dungeonRoute, $coordinatesService) {
// Set the team_id if the user has the rights to do this. May be null if not set or no rights for it.
$updateAttributes = [];

$teamId = $validated['team_id'];
if ($teamId !== null) {
$team = Team::find($teamId);
if ($team !== null && $team->isUserCollaborator(Auth::user())) {
$mapIcon->update([
$updateAttributes = [
'team_id' => $teamId,
'dungeon_route_id' => null,
]);
];
}
}

// The incoming lat/lngs are facade lat/lngs, save the icon on the proper floor
if (User::getCurrentUserMapFacadeStyle() === User::MAP_FACADE_STYLE_FACADE) {
$latLng = $coordinatesService->convertFacadeMapLocationToMapLocation(
$dungeonRoute->mappingVersion,
$mapIcon->getLatLng()
);

$updateAttributes = array_merge($updateAttributes, [
'lat' => $latLng->getLat(),
'lng' => $latLng->getLng(),
'floor_id' => $latLng->getFloor()->id,
]);

$mapIcon->setRelation('floor', $latLng->getFloor());
}

// Set the mapping version if it was placed in the context of a dungeon, or reset it to null if not in context
// of a dungeon
$mapIcon->update([
$mapIcon->update(array_merge($updateAttributes, [
'mapping_version_id' => $dungeonRoute === null ? $validated['mapping_version_id'] : null,
]);
]));

// Prevent people being able to update icons that only the admin should if they're supplying a valid dungeon route
if ($mapIcon->exists && $mapIcon->dungeon_route_id === null && $dungeonRoute !== null && $mapIcon->team_id === null) {
Expand All @@ -104,9 +129,9 @@ public function store(MapIconFormRequest $request, ?DungeonRoute $dungeonRoute,
}

/**
* @param Request $request
* @param Request $request
* @param DungeonRoute|null $dungeonRoute
* @param MapIcon $mapIcon
* @param MapIcon $mapIcon
* @return array|ResponseFactory|Response
* @throws Exception
*/
Expand Down Expand Up @@ -151,7 +176,7 @@ function delete(Request $request, ?DungeonRoute $dungeonRoute, MapIcon $mapIcon)

/**
* @param MapIconFormRequest $request
* @param MapIcon|null $mapIcon
* @param MapIcon|null $mapIcon
* @return MapIcon
* @throws AuthorizationException
* @throws Throwable
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Ajax/AjaxMappingModelBaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ protected function storeModel(array $validated, string $modelClass, MappingModel
}

if (Auth::check()) {
$model->load(['floor', 'floor.dungeon']);

broadcast(new ModelChangedEvent($model->floor->dungeon, Auth::getUser(), $model));
}

Expand Down
30 changes: 23 additions & 7 deletions app/Http/Controllers/Ajax/AjaxPathController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Models\DungeonRoute;
use App\Models\Path;
use App\Models\Polyline;
use App\Service\Coordinates\CoordinatesServiceInterface;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Contracts\Routing\ResponseFactory;
use Illuminate\Http\Request;
Expand All @@ -23,13 +24,18 @@ class AjaxPathController extends Controller
use SavesPolylines;

/**
* @param APIPathFormRequest $request
* @param DungeonRoute $dungeonRoute
* @param Path|null $path
* @param APIPathFormRequest $request
* @param CoordinatesServiceInterface $coordinatesService
* @param DungeonRoute $dungeonRoute
* @param Path|null $path
* @return Path
* @throws AuthorizationException
*/
function store(APIPathFormRequest $request, DungeonRoute $dungeonRoute, ?Path $path = null)
function store(
APIPathFormRequest $request,
CoordinatesServiceInterface $coordinatesService,
DungeonRoute $dungeonRoute,
?Path $path = null)
{
$dungeonRoute = optional($path)->dungeonRoute ?? $dungeonRoute;

Expand All @@ -54,11 +60,20 @@ function store(APIPathFormRequest $request, DungeonRoute $dungeonRoute, ?Path $p
try {
if ($success) {
// Create a new polyline and save it
$polyline = $this->savePolyline(Polyline::findOrNew($path->polyline_id), $path, $validated['polyline']);
$changedFloor = null;
$polyline = $this->savePolyline(
$coordinatesService,
$dungeonRoute->mappingVersion,
Polyline::findOrNew($path->polyline_id),
$path,
$validated['polyline'],
$changedFloor
);

// Couple the path to the polyline
$path->update([
'polyline_id' => $polyline->id,
'floor_id' => optional($changedFloor)->id ?? $path->floor_id,
]);

// Load the polyline so it can be echoed back to the user
Expand All @@ -82,13 +97,14 @@ function store(APIPathFormRequest $request, DungeonRoute $dungeonRoute, ?Path $p
} catch (Exception $ex) {
$result = response('Not found', Http::NOT_FOUND);
}

return $result;
}

/**
* @param Request $request
* @param Request $request
* @param DungeonRoute $dungeonRoute
* @param Path $path
* @param Path $path
* @return array|ResponseFactory|Response
* @throws AuthorizationException
*/
Expand Down
25 changes: 24 additions & 1 deletion app/Http/Controllers/Ajax/AjaxUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
namespace App\Http\Controllers\Ajax;


use App\Http\Requests\User\UserFormRequest;
use App\Logic\Datatables\UsersDatatablesHandler;
use App\User;
use Auth;
use Exception;
use Illuminate\Http\Request;
use Teapot\StatusCode;

class AjaxUserController
{
/**
* @param Request $request
* @return array|mixed
* @throws \Exception
* @throws Exception
*/
public function list(Request $request)
{
Expand All @@ -31,4 +35,23 @@ public function list(Request $request)

return $datatablesResult;
}

/**
* @param UserFormRequest $request
* @param string $publicKey
* @return User
*/
public function store(UserFormRequest $request, string $publicKey): User
{
/** @var User|null $user */
$user = User::where('public_key', $publicKey)->first();

if ($user === null || $user->public_key !== Auth::user()->public_key) {
abort(StatusCode::BAD_REQUEST);
}

$user->update($request->validated());

return $user->makeVisible('map_facade_style');
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Dungeon/DungeonExploreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function viewDungeonFloor(
'dungeon' => $dungeon,
'floor' => $floor,
'title' => __($dungeon->name),
'mapContext' => $mapContextService->createMapContextDungeonExplore($dungeon, $floor, $dungeon->getCurrentMappingVersion())
'mapContext' => $mapContextService->createMapContextDungeonExplore($dungeon, $floor, $dungeon->currentMappingVersion)
]);
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/DungeonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ public function savenew(DungeonFormRequest $request)
public function list()
{
return view('admin.dungeon.list', [
'models' => Dungeon::select('dungeons.*')
'models' => Dungeon::with(['currentMappingVersion'])
->select('dungeons.*')
->join('expansions', 'expansions.id', 'dungeons.expansion_id')
->orderByDesc('expansions.released_at')
->orderBy('dungeons.name')
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/DungeonRouteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ public function upgrade(Request $request, Dungeon $dungeon, DungeonRoute $dungeo

// Store it
$dungeonroute->update([
'mapping_version_id' => $dungeonroute->dungeon->getCurrentMappingVersion()->id,
'mapping_version_id' => $dungeonroute->dungeon->currentMappingVersion->id,
'updated_at' => Carbon::now()->toDateTimeString(),
]);

Expand Down
Loading

0 comments on commit 07accbc

Please sign in to comment.