Skip to content

Commit

Permalink
GLoves fixes, knifes category changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hobsRKM committed Jun 6, 2024
1 parent cf8f7f2 commit c7324c0
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 67 deletions.
144 changes: 115 additions & 29 deletions app/Http/Controllers/WeaponSkinController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,35 @@ public function index()
// Group skins by weapon types dynamically
$weaponTypes = [];
foreach ($skins as $skin) {
$weaponType = explode('_', $skin['weapon_name'])[1]; // Extract weapon type
if(in_array($skin['weapon_defindex'], [
500,
503,
505,
506,
507,
508,
509,
512,
514,
515,
516,
517,
518,
519,
520,
521,
522,
523,
525,
526
])) {
$weaponType = 'knife';
} else {
$weaponType = explode('_', $skin['weapon_name'])[1]; // Extract weapon type
}
if (!isset($weaponTypes[$weaponType])) {
$weaponTypes[$weaponType] = [];
}

// Mark skin as applied if it exists in appliedSkins
$skin['is_applied'] = $appliedSkins->contains(function ($value) use ($skin) {
return $value->weapon_defindex == $skin['weapon_defindex'] && $value->weapon_paint_id == $skin['paint'];
Expand All @@ -51,6 +75,30 @@ public function load($type)
$appliedSkins = DB::table('wp_player_skins')->where('steamid', Auth::user()?->steam_id)->get();

$filteredSkins = array_filter($skins, function($skin) use ($type) {
if($type == 'knife' && in_array($skin['weapon_defindex'], [
500,
503,
505,
506,
507,
508,
509,
512,
514,
515,
516,
517,
518,
519,
520,
521,
522,
523,
525,
526
])){
return true;
}
return str_contains(strtolower($skin['weapon_name']), strtolower($type));
});

Expand Down Expand Up @@ -82,6 +130,37 @@ public function applySkin(Request $request)
return response()->json(['errors' => $validator->errors()], 422);
}
$validated = $validator->validated();
if(in_array($validated['weapon_defindex'], [
500,
503,
505,
506,
507,
508,
509,
512,
514,
515,
516,
517,
518,
519,
520,
521,
522,
523,
525,
526
])){
DB::table('wp_player_knife')->updateOrInsert(
[
'steamid' => $validated['steamid'],
],
[
'knife' => $request->input('weapon_name'),
]
);
}
DB::table('wp_player_skins')->updateOrInsert(
[
'steamid' => $validated['steamid'],
Expand Down Expand Up @@ -126,7 +205,11 @@ public function gloves()
$gloves = json_decode(File::get(resource_path('json/gloves.json')), true);

// Fetch applied gloves from the database
$appliedGloves = DB::table('wp_player_gloves')->where('steamid', Auth::user()?->steam_id)->get();
$appliedGloves = DB::table('wp_player_skins')
->where('steamid', Auth::user()?->steam_id)
->pluck('weapon_paint_id')
->toArray();

// Group gloves by paint name prefix
$gloveTypes = [];
foreach ($gloves as $glove) {
Expand All @@ -136,12 +219,11 @@ public function gloves()
}

// Mark glove as applied if it exists in appliedGloves
$glove['is_applied'] = $appliedGloves->contains(function ($value) use ($glove) {
return $value->weapon_defindex == $glove['weapon_defindex'];
});
$glove['is_applied'] = in_array($glove['paint'], $appliedGloves);

$gloveTypes[$paintPrefix][] = $glove;
}

// Sort applied gloves to be first in each category
foreach ($gloveTypes as $type => $gloves) {
usort($gloves, function($a, $b) {
Expand All @@ -152,20 +234,24 @@ public function gloves()

return view('weapons.gloves', compact('gloveTypes'));
}

public function loadGloves($type)
{
$gloves = json_decode(File::get(resource_path('json/gloves.json')), true);
$appliedGloves = DB::table('wp_player_gloves')->where('steamid', Auth::user()?->steam_id)->get();
$appliedGloves = DB::table('wp_player_skins')
->where('steamid', Auth::user()?->steam_id)
->pluck('weapon_paint_id')
->toArray();

$filteredGloves = array_filter($gloves, function($glove) use ($type) {
return str_contains(strtolower($glove['paint_name']), strtolower($type));
});

// Mark glove as applied if it exists in appliedGloves
foreach ($filteredGloves as &$glove) {
$glove['is_applied'] = $appliedGloves->contains(function ($value) use ($glove) {
return $value->weapon_defindex == $glove['weapon_defindex'];
});
$glove['is_applied'] = in_array($glove['paint'], $appliedGloves);
}

// Sort applied gloves to be first
usort($filteredGloves, function($a, $b) {
return $b['is_applied'] - $a['is_applied'];
Expand All @@ -174,6 +260,7 @@ public function loadGloves($type)
return view('weapons.partials.gloves-types', ['gloves' => $filteredGloves]);
}


public function music()
{
$music = json_decode(File::get(resource_path('json/music.json')), true);
Expand Down Expand Up @@ -231,6 +318,10 @@ public function applyGlove(Request $request)
$validator = Validator::make($request->all(), [
'steamid' => 'required|string',
'weapon_defindex' => 'required|integer',
'weapon_paint_id' => 'required|integer',
'wearSelect' => 'required|numeric',
'wear' => 'nullable|numeric',
'seed' => 'nullable|integer',
]);

if ($validator->fails()) {
Expand All @@ -240,6 +331,7 @@ public function applyGlove(Request $request)
$validated = $validator->validated();

try {
// Update or insert in wp_player_gloves table
DB::table('wp_player_gloves')->updateOrInsert(
[
'steamid' => $validated['steamid'],
Expand All @@ -249,6 +341,19 @@ public function applyGlove(Request $request)
]
);

// Update or insert in wp_player_skins table
DB::table('wp_player_skins')->updateOrInsert(
[
'steamid' => $validated['steamid'],
'weapon_defindex' => $validated['weapon_defindex'],
],
[
'weapon_paint_id' => $validated['weapon_paint_id'],
'weapon_wear' => $validated['wearSelect'],
'weapon_seed' => $validated['seed'] ?? 0,
]
);

return response()->json(['success' => 'Glove skin applied successfully!']);
} catch (\Exception $e) {
return response()->json(['error' => 'An unexpected error occurred.'], 500);
Expand All @@ -274,25 +379,6 @@ public function applyMusic(Request $request)
return response()->json(['success' => 'Music applied successfully!']);
}

public function applyKnife(Request $request)
{
$validated = $request->validate([
'steamid' => 'required|string',
'weapon_name' => 'required|string',
]);

DB::table('wp_player_knife')->updateOrInsert(
[
'steamid' => $validated['steamid'],
],
[
'knife' => $validated['weapon_name'],
]
);

return response()->json(['success' => 'Knife applied successfully!']);
}

}


2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
| Application Version
|--------------------------------------------------------------------------
*/
'version' => '3.0',
'version' => '3.1',
/*
|--------------------------------------------------------------------------
| Application Name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
</li>
<li class="nav-item dropdown">
<select id="language-dropdown" class="form-select">
<option {{ app()->getLocale() == 'en' ? 'selected' : '' }} value="en" data-image="{{ Vite::asset('resources/images/1x1/us.svg') }}">English</option>
<option {{ app()->getLocale() == 'en' ? 'seRlected' : '' }} value="en" data-image="{{ Vite::asset('resources/images/1x1/us.svg') }}">English</option>
<option {{ app()->getLocale() == 'de' ? 'selected' : '' }} value="de" data-image="{{ Vite::asset('resources/images/1x1/de.svg') }}">German</option>
<option {{ app()->getLocale() == 'es' ? 'selected' : '' }} value="es" data-image="{{ Vite::asset('resources/images/1x1/es.svg') }}">Spanish</option>
<option {{ app()->getLocale() == 'fr' ? 'selected' : '' }} value="fr" data-image="{{ Vite::asset('resources/images/1x1/fr.svg') }}">French</option>
<option {{ app()->getLocale() == 'it' ? 'selected' : '' }} value="it" data-image="{{ Vite::asset('resources/images/1x1/it.svg') }}">Italian</option>
<option {{ app()->getLocale() == 'ja' ? 'selected' : '' }} value="ja" data-image="{{ Vite::asset('resources/images/1x1/jp.svg') }}">Japanese</option>
<option {{ app()->getLocale() == 'ko' ? 'selected' : '' }} value="ko" data-image="{{ Vite::asset('resources/images/1x1/kr.svg') }}">Korean</option>
<option {{ app()->getLocale() == 'pt' ? 'selected' : '' }} value="pt" data-image="{{ Vite::asset('resources/images/1x1/br.svg') }}">Portuguese</option>
<option {{ app()->getLocale() == 'ru' ? 'selected' : '' }} value="ru" data-image="{{ Vite::asset('resources/images/1x1/ru.svg') }}">Russian</option>
<option {{ app()->getLocale() == 'ru' ? 'selected' : '' }} value="ru" data-image="{{ Vite::asset('resources/images/1x1/ru.svg') }}">Russia</option>
<option {{ app()->getLocale() == 'zh_CN' ? 'selected' : '' }} value="zh_CN" data-image="{{ Vite::asset('resources/images/1x1/cn.svg') }}">Chinese</option>
<option {{ app()->getLocale() == 'ro' ? 'selected' : '' }} value="ro" data-image="{{ Vite::asset('resources/images/1x1/ro.svg') }}">Romanian </option>

Expand Down
54 changes: 44 additions & 10 deletions resources/views/weapons/gloves.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,37 @@
<img id="selectedGloveImage" src="" alt="Glove Preview" class="img-fluid" style="max-width: 100px;"> <!-- Set max-width to control the size -->
<h5 id="selectedGloveName" class="mt-3"></h5>
<form id="applyGloveForm">
<input type="hidden" id="steamid" name="steamid" value="{{Auth::user()->steam_id}}">
<input type="hidden" id="steamid" name="steamid" value="{{ Auth::user()->steam_id }}">
<input type="hidden" id="weapon_defindex" name="weapon_defindex">
<input type="hidden" id="paint_id" name="paint_id">
<button type="button" class="btn btn-primary mt-3" id="saveGloveButton">Save</button>
<input type="hidden" id="weapon_paint_id" name="weapon_paint_id">
<input type="hidden" id="weapon_name" name="weapon_name">

<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="wearSelect">Select Wear</label>
<select class="form-select" id="wearSelect" name="wearSelect" onchange="updateWearValue(this.value)">
<option value="0.00">Select Wear</option>
<option value="0.00">Factory New</option>
<option value="0.07">Minimal Wear</option>
<option value="0.15">Field-Tested</option>
<option value="0.38">Well-Worn</option>
<option value="0.45">Battle-Scarred</option>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="seed">Seed</label>
<input type="text" class="form-control" id="seed" name="seed" oninput="validateSeed(this)">
</div>
</div>
</div>
<div class="form-group mt-3">
<label for="wear">Wear</label>
<input type="text" class="form-control" id="wear" name="wear" value="0">
</div>
<button type="button" class="btn btn-primary mt-3" id="saveGloveButton">Apply</button>
</form>
</div>
</div>
Expand Down Expand Up @@ -107,12 +134,14 @@
const gloveImage = card.find('img').attr('src');
const gloveName = card.find('b').text();
const weaponDefIndex = $(this).data('weapon-defindex');
const paint = $(this).data('paint-id');
const weaponPaintId = $(this).data('paint-id');
const weaponName = $(this).data('weapon-name');
// Set the image source and name
$('#selectedGloveImage').attr('src', gloveImage);
$('#selectedGloveName').text(gloveName);
$('#weapon_defindex').val(weaponDefIndex);
$('#paint_id').val(paint);
$('#weapon_paint_id').val(weaponPaintId);
$('#weapon_name').val(weaponName);
// Show the apply glove modal
$('#applyGloveModal').modal('show');
});
Expand All @@ -129,7 +158,7 @@
}).then(response => response.json()).then(data => {
if (data.success) {
$('.glove_active').html('');
$('#glove_'+$('#paint_id').val()).html('Active');
$('#glove_'+$('#weapon_paint_id').val()).html('Active');
Snackbar.show({
text: 'Skin Applied Successfully.',
actionTextColor: '#fff',
Expand Down Expand Up @@ -169,11 +198,16 @@
$('#glovePreviewModal').modal('show');
});
});
</script>



function validateSeed(input) {
if (!/^\d*$/.test(input.value)) {
input.value = input.value.replace(/[^\d]/g, '');
}
}
function updateWearValue(value) {
$('#wear').val(value);
}
</script>

</x-slot:footerFiles>
</x-base-layout>
Loading

0 comments on commit c7324c0

Please sign in to comment.