Skip to content

Commit

Permalink
Code Cleanup
Browse files Browse the repository at this point in the history
Requested changes of 2024-04-05 (code cleanup).
Corrected DPS code for Salvation.
  • Loading branch information
PViddy72 committed Apr 5, 2024
1 parent ed163ae commit fdbc1bc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
13 changes: 7 additions & 6 deletions www/include/Git.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

// Improved error handling. Detect when commands fail. Exit script on failure.
// Removed use of shell_exec (does not reliably detect command failures).
// Wrapper for Git, exits on git failures.
class Git
{
private $repositoryUrl;
Expand All @@ -20,12 +19,10 @@ public function clone($destinationDirectory, $branch = 'master', $sparseFolders

if ($sparseFolders) {
$out = $this->execute("git clone --filter=blob:none --depth 1 --sparse {$escRepo} --branch {$escBranch} {$escDestDir}");
print_r($out);

foreach ($sparseFolders as $folder) {
$escFolder = escapeshellarg($folder);
$out = $this->execute("cd {$escDestDir} && git sparse-checkout add {$escFolder}");
print_r($out);
}
} else {
$out = $this->execute("git clone {$escRepo} {$escDestDir}");
Expand All @@ -39,8 +36,12 @@ private function execute($command)
$retval = null;
logDebug($command);
exec($command, $output, $retval);
logDebug("Returned with status $retval and output: \n");
if ($retval != 0) exit ($retval);

if ($retval != 0) {
logDebug("Returned with status $retval and output: \n");
print_r($output);
exit ($retval);
}

return $output;
}
Expand Down
22 changes: 10 additions & 12 deletions www/res/scripts/calculations.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ function calculateDps($stdClassWeapon, $unitID, $Projectile){

$weapon = arrayCastRecursive($stdClassWeapon); // StdClass are a PAIN to use in PHP

// Hardcoded exceptions - Removed arties, handled by Fragmentation code below
// 'UEL0103', // lobo
// 'XSL0103', // zthuee

// Hardcoded exceptions
$specials = [
'DAA0206', // mercy
'XAA0306' // solace
Expand Down Expand Up @@ -80,22 +77,23 @@ function calculateDps($stdClassWeapon, $unitID, $Projectile){
);

/*
Previous code for calculating missile/projectile count was re-written to improve accuracy and moved to calculateFireCycle.
Code for calculating missile/projectile count should only be done in calculateFireCycle.
We don't want to calculate fire cycles in two places. Just use the value returned from that function.
*/
$trueSalvoSize = $shots;

/// Added for Salvation
if ($unitID == "XAB2307") {
/// Salvation uses a shell that fragments into 6 shells, which then fragments into 6 more. I'm not going to try to code that. Just multiply by 36.
$trueSalvoSize = $trueSalvoSize * 36;
}

$trueDamage = $weapon["Damage"] * ($weapon["DoTPulses"] ?? 1) + ($weapon["InitialDamage"] ?? 0);

/// Added for weapons with fragmentation shells (Lobo, Zthuee).
/// For weapons with fragmentation shells (Lobo, Zthuee, Salvation).
if (isset($Projectile) && property_exists($Projectile->Physics, 'Fragments')) {
$trueSalvoSize = $trueSalvoSize * $Projectile->Physics->Fragments;
/// Exception for Salvation
if ($unitID == "XAB2307") {
/// Salvation uses a shell that fragments into 6 shells, which then fragments into 6 more.
/// Only first fragmentation is accounted for above. Hard code the 2nd one by multiplying by 6.
$trueSalvoSize = $trueSalvoSize * 6;
}

}

// beam weapons are a thing and do their own thing. yeah good luck working out that.
Expand Down
28 changes: 15 additions & 13 deletions www/res/scripts/functions.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
<?php

// When debugging, uncomment the following to display errors.

/*
error_reporting(E_ALL);
ini_set('display_errors', 1);

*/

include("calculations.php");

///////////////////////////////////////
/// ///
/// Functions follow. ///
/// ///
///////////////////////////////////////

function print_r2($val){
echo '<pre>';
print_r($val);
echo '</pre>';

///////////////////////////////////////
/// ///
/// Functions follow. ///
/// ///
///////////////////////////////////////

// Formats output of standard print_r function to make it display on a web page.
function print_r_web($val)
{
echo '<pre>';
print_r($val);
echo '</pre>';
}

// For some values, I want to see the decimals, unless they don't exist.
Expand Down

0 comments on commit fdbc1bc

Please sign in to comment.