Skip to content

Commit

Permalink
Merge pull request #2156 from Wotuu/development
Browse files Browse the repository at this point in the history
Release v7.7 - Combined Floor mode improvements, various bugfixes and QOL improvements
  • Loading branch information
Wotuu authored Nov 29, 2023
2 parents 01a6892 + 39b1884 commit 8a813da
Show file tree
Hide file tree
Showing 326 changed files with 18,802 additions and 405 deletions.
30 changes: 18 additions & 12 deletions app/Console/Commands/Cache/RedisClearIdleKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RedisClearIdleKeys extends Command
*
* @var string
*/
protected $description = 'Clears all idle keys in redis that have not been accessed in a specific time in seconds';
protected $description = 'Clears all idle keys in redis for Laravel Model Cache that have not been accessed in a specific time in seconds';

/**
* Execute the console command.
Expand All @@ -30,6 +30,13 @@ public function handle(): int
{
$seconds = (int)$this->argument('seconds');

// Only keys starting with this prefix may be cleaned up by this task, ex.
// keystoneguru-live-cache:d8123999fdd7267f49290a1f2bb13d3b154b452a:f723072f44f1e4727b7ae26316f3d61dd3fe3d33
// keystoneguru-live-cache:p79vfrAn4QazxHVtLb5s4LssQ5bi6ZaWGNTMOblt
$keyWhitelistRegex = [
sprintf('/keystoneguru-%s-cache:.{40}(?::.{40})*/', config('app.type')),
];

Log::channel('scheduler')->info(sprintf('Clearing idle keys in redis that haven\'t been accessed in %d seconds', $seconds));
$i = 0;
$nextKey = 0;
Expand All @@ -42,17 +49,16 @@ public function handle(): int

$toDelete = [];
foreach ($result[1] as $redisKey) {
// Just to get an insight in what is stored here
if ($i < 100) {
Log::channel('scheduler')->debug(sprintf('%d: %s (next: %d)', $i, $redisKey, $nextKey));
}

// if (strlen($redisKey) === 40 || Str::endsWith($redisKey, 'forever_ref')) {
// }

$idleTime = Redis::command('OBJECT', ['idletime', $redisKey]);
if ($idleTime > $seconds) {
$toDelete[] = $redisKey;
$output = [];
foreach ($keyWhitelistRegex as $regex) {
if (preg_match($regex, $redisKey, $output) !== false) {
$idleTime = Redis::command('OBJECT', ['idletime', $redisKey]);
if ($idleTime > $seconds) {
$toDelete[] = $redisKey;
}

break;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,7 @@ public function list(Request $request)
*/
public function store(DungeonFloorSwitchMarkerFormRequest $request, DungeonFloorSwitchMarker $dungeonFloorSwitchMarker = null): DungeonFloorSwitchMarker
{
$validated = $request->validated();

if ((int)$validated['source_floor_id'] === -1) {
$validated['source_floor_id'] = null;
}

if ((int)$validated['direction'] === -1) {
$validated['direction'] = null;
}

return $this->storeModel($validated, DungeonFloorSwitchMarker::class, $dungeonFloorSwitchMarker);
return $this->storeModel($request->validated(), DungeonFloorSwitchMarker::class, $dungeonFloorSwitchMarker);
}

/**
Expand Down
22 changes: 13 additions & 9 deletions app/Http/Controllers/Ajax/AjaxDungeonRouteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,17 +402,21 @@ public function htmlsearchcategory(Request $request, string $category, DiscoverS
}
break;
case 'thisweek':
if ($dungeon instanceof Dungeon) {
$result = $discoverService->popularByDungeonAndAffixGroup($dungeon, $affixGroup = $currentAffixGroup);
} else {
$result = $discoverService->popularByAffixGroup($affixGroup = $currentAffixGroup);
if ($currentAffixGroup !== null) {
if ($dungeon instanceof Dungeon) {
$result = $discoverService->popularByDungeonAndAffixGroup($dungeon, $affixGroup = $currentAffixGroup);
} else {
$result = $discoverService->popularByAffixGroup($affixGroup = $currentAffixGroup);
}
}
break;
case 'nextweek':
if ($dungeon instanceof Dungeon) {
$result = $discoverService->popularByDungeonAndAffixGroup($dungeon, $affixGroup = $currentAffixGroup);
} else {
$result = $discoverService->popularByAffixGroup($affixGroup = $expansionService->getNextAffixGroup($expansion, $region));
if ($currentAffixGroup !== null) {
if ($dungeon instanceof Dungeon) {
$result = $discoverService->popularByDungeonAndAffixGroup($dungeon, $affixGroup = $currentAffixGroup);
} else {
$result = $discoverService->popularByAffixGroup($affixGroup = $expansionService->getNextAffixGroup($expansion, $region));
}
}
break;
case 'new':
Expand All @@ -433,7 +437,7 @@ public function htmlsearchcategory(Request $request, string $category, DiscoverS
'affixgroup' => $affixGroup,
'showAffixes' => true,
'showDungeonImage' => $dungeon === null,
'cols' => 2,
'cols' => 4,
])->render();
}
}
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/Ajax/AjaxMapIconController.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ public function store(

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

$latLng = $coordinatesService->convertFacadeMapLocationToMapLocation(
$dungeonRoute->mappingVersion,
optional($dungeonRoute)->mappingVersion ?? $mapIcon->mappingVersion,
$mapIcon->getLatLng()
);

Expand Down
21 changes: 17 additions & 4 deletions app/Http/Controllers/Dungeon/DungeonExploreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public function list(Request $request)
public function viewDungeon(Request $request, Dungeon $dungeon)
{
/** @var Floor $defaultFloor */
$defaultFloor = Floor::where('dungeon_id', $dungeon->id)->where('default', true)->first();
$defaultFloor = Floor::where('dungeon_id', $dungeon->id)
->defaultOrFacade()
->first();

return redirect()->route('dungeon.explore.view.floor', [
'dungeon' => $dungeon,
Expand All @@ -62,22 +64,33 @@ public function viewDungeonFloor(
}

/** @var Floor $floor */
$floor = Floor::where('dungeon_id', $dungeon->id)->where('index', $floorIndex)->first();
$floor = Floor::where('dungeon_id', $dungeon->id)
->indexOrFacade($floorIndex)
->first();

if ($floor === null) {
/** @var Floor $defaultFloor */
$defaultFloor = Floor::where('dungeon_id', $dungeon->id)->where('default', true)->first();
$defaultFloor = Floor::where('dungeon_id', $dungeon->id)
->defaultOrFacade()
->first();

return redirect()->route('dungeon.explore.view.floor', [
'dungeon' => $dungeon,
'floorIndex' => optional($defaultFloor)->index ?? '1',
]);
} else {
if ($floor->index !== (int)$floorIndex) {
return redirect()->route('dungeon.explore.view.floor', [
'dungeon' => $dungeon,
'floorIndex' => $floor->index,
]);
}

return view('dungeon.explore.view', [
'dungeon' => $dungeon,
'floor' => $floor,
'title' => __($dungeon->name),
'mapContext' => $mapContextService->createMapContextDungeonExplore($dungeon, $floor, $dungeon->currentMappingVersion)
'mapContext' => $mapContextService->createMapContextDungeonExplore($dungeon, $floor, $dungeon->currentMappingVersion),
]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

namespace App\Http\Requests\DungeonFloorSwitchMarker;

use App\Models\DungeonFloorSwitchMarker;
use App\Models\Floor\Floor;
use App\Models\Floor\FloorCoupling;
use App\Models\Mapping\MappingVersion;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

/**
* @property string $source_floor_id
* @property string $linked_dungeon_floor_switch_marker_id
* @property string $direction
*/
class DungeonFloorSwitchMarkerFormRequest extends FormRequest
{
/**
Expand All @@ -20,6 +26,16 @@ public function authorize(): bool
return true;
}

protected function prepareForValidation(): void
{
$this->merge([
'source_floor_id' => (int)$this->source_floor_id === -1 ? null : $this->source_floor_id,
'linked_dungeon_floor_switch_marker_id' =>
(int)$this->linked_dungeon_floor_switch_marker_id === -1 ? null : $this->linked_dungeon_floor_switch_marker_id,
'direction' => (int)$this->direction === -1 ? null : $this->direction,
]);
}

/**
* Get the validation rules that apply to the request.
*
Expand All @@ -28,14 +44,15 @@ public function authorize(): bool
public function rules(): array
{
return [
'id' => 'int',
'mapping_version_id' => ['required', Rule::exists(MappingVersion::class, 'id')],
'floor_id' => ['required', Rule::exists(Floor::class, 'id')],
'source_floor_id' => ['nullable', Rule::in(array_merge([-1], Floor::all('id')->pluck('id')->toArray()))],
'target_floor_id' => ['nullable', Rule::exists(Floor::class, 'id')],
'direction' => ['nullable', Rule::in(array_merge(FloorCoupling::ALL, ['-1', '', null]))],
'lat' => 'numeric',
'lng' => 'numeric',
'id' => 'int',
'mapping_version_id' => ['required', Rule::exists(MappingVersion::class, 'id')],
'floor_id' => ['required', Rule::exists(Floor::class, 'id')],
'source_floor_id' => ['nullable', Rule::in(array_merge([-1], Floor::all('id')->pluck('id')->toArray()))],
'target_floor_id' => ['nullable', Rule::exists(Floor::class, 'id')],
'linked_dungeon_floor_switch_marker_id' => ['nullable', Rule::exists(DungeonFloorSwitchMarker::class, 'id')],
'direction' => ['nullable', Rule::in(array_merge(FloorCoupling::ALL, ['-1', '', null]))],
'lat' => 'numeric',
'lng' => 'numeric',
];
}
}
3 changes: 2 additions & 1 deletion app/Logic/MapContext/DungeonRouteProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public function getFloors(): Collection
}

/**
* @param array $publicKeys
* @param CoordinatesServiceInterface $coordinatesService
* @param array $publicKeys
* @return Collection
*/
private function getDungeonRoutesProperties(CoordinatesServiceInterface $coordinatesService, array $publicKeys): Collection
Expand Down
104 changes: 84 additions & 20 deletions app/Models/DungeonFloorSwitchMarker.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@
use App\Models\Traits\HasLatLng;
use Eloquent;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;

/**
* @property int $id
* @property int $mapping_version_id
* @property int $floor_id
* @property int $source_floor_id
* @property int $target_floor_id
* @property float $lat
* @property float $lng
* @property string $direction
* @property int $id
* @property int $mapping_version_id
* @property int $floor_id
* @property int $source_floor_id
* @property int $target_floor_id
* @property int|null $linked_dungeon_floor_switch_marker_id
* @property float $lat
* @property float $lng
* @property string $direction
*
* @property Floor $floor
* @property Floor|null $sourceFloor
* @property Floor $targetFloor
* @property string $floorCouplingDirection
*
* @property Floor $floor
* @property Floor|null $sourceFloor
* @property Floor $targetFloor
* @property DungeonFloorSwitchMarker|null $linkedDungeonFloorSwitchMarker
*
* @mixin Eloquent
*/
Expand All @@ -32,41 +37,70 @@ class DungeonFloorSwitchMarker extends CacheModel implements MappingModelInterfa
use CloneForNewMappingVersionNoRelations;
use HasLatLng;

protected $appends = ['floorCouplingDirection'];
protected $appends = ['floorCouplingDirection']; // , 'ingameX', 'ingameY'
protected $hidden = ['floor', 'targetFloor', 'sourceFloor', 'laravel_through_key'];
protected $fillable = [
'id',
'mapping_version_id',
'floor_id',
'source_floor_id',
'target_floor_id',
'linked_dungeon_floor_switch_marker_id',
'direction',
'lat',
'lng',
];
protected $casts = [
'mapping_version_id' => 'integer',
'floor_id' => 'integer',
'source_floor_id' => 'integer',
'target_floor_id' => 'integer',
'lat' => 'float',
'lng' => 'float',
'mapping_version_id' => 'integer',
'floor_id' => 'integer',
'source_floor_id' => 'integer',
'target_floor_id' => 'integer',
'linked_dungeon_floor_switch_marker_id' => 'integer',
'lat' => 'float',
'lng' => 'float',
];

public $timestamps = false;

private string $floorCouplingDirection = 'unknown';

// /** @var float Future Laravel-me, please find a better solution for this Q.Q */
// private float $ingameX = 0;
// private float $ingameY = 0;

/**
* @return string
*/
public function getFloorCouplingDirectionAttribute(): string
{
/** @var FloorCoupling $floorCoupling */
// Prevent double setting
if ($this->floorCouplingDirection !== 'unknown') {
return $this->floorCouplingDirection;
}

/** @var FloorCoupling|null $floorCoupling */
$floorCoupling = FloorCoupling::where('floor1_id', $this->source_floor_id ?? $this->floor_id)
->where('floor2_id', $this->target_floor_id)
->first();

return $floorCoupling === null ? 'unknown' : $floorCoupling->direction;
return $this->floorCouplingDirection = ($floorCoupling === null ? 'unknown' : $floorCoupling->direction);
}
//
// /**
// * @return float
// */
// public function getIngameXAttribute(): float
// {
// return $this->ingameX;
// }
//
// /**
// * @return float
// */
// public function getIngameYAttribute(): float
// {
// return $this->ingameY;
// }

/**
* @return BelongsTo
Expand All @@ -92,6 +126,14 @@ public function targetFloor(): BelongsTo
return $this->belongsTo(Floor::class);
}

/**
* @return HasOne
*/
public function linkedDungeonFloorSwitchMarker(): HasOne
{
return $this->hasOne(DungeonFloorSwitchMarker::class);
}

/**
* @return int|null
*/
Expand Down Expand Up @@ -124,4 +166,26 @@ public function getMdtDirection(): int

return $result;
}

// /**
// * @param float $ingameX
// * @return DungeonFloorSwitchMarker
// */
// public function setIngameX(float $ingameX): DungeonFloorSwitchMarker
// {
// $this->ingameX = $ingameX;
//
// return $this;
// }
//
// /**
// * @param float $ingameY
// * @return DungeonFloorSwitchMarker
// */
// public function setIngameY(float $ingameY): DungeonFloorSwitchMarker
// {
// $this->ingameY = $ingameY;
//
// return $this;
// }
}
Loading

0 comments on commit 8a813da

Please sign in to comment.