Skip to content

Commit

Permalink
Stability++
Browse files Browse the repository at this point in the history
  • Loading branch information
starswaitforus authored and solcloud committed Sep 14, 2024
1 parent 5677c7b commit f06f871
Show file tree
Hide file tree
Showing 42 changed files with 470 additions and 204 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/electron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
persist-credentials: false

Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
composer-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
persist-credentials: false

Expand All @@ -38,3 +38,12 @@ jobs:
timeout-minutes: 1
run: |
composer check
- name: "Check code coverage min percentage"
timeout-minutes: 5
run: |
echo '<?php preg_match("~Lines:\s+([\d.]+)%~", stream_get_contents(STDIN), $m);exit((int)((float)$m[1] < 98.5));' > cc.php
XDEBUG_MODE=coverage php vendor/bin/phpunit -d memory_limit=70M \
--coverage-text --only-summary-for-coverage-text --stderr --no-progress --colors=never 2> cc.txt
cat cc.txt
grep 'Lines: ' cc.txt | php -d error_reporting=E_ALL cc.php
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor/
/electron/package-lock.json
/electron/build/
/electron/node_modules/
/electron/package-lock.json
/vendor/
/www/coverage/
2 changes: 1 addition & 1 deletion electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"build": "electron-packager . build --platform=all --asar --executable-name=start_game --ignore='\\.php$' --out='build'"
},
"devDependencies": {
"electron": "25.*",
"electron": "*",
"electron-packager": "*"
}
}
9 changes: 1 addition & 8 deletions server/src/Core/Bullet.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class Bullet
private bool $originPlayerIsAttacker;
private int $distanceTraveled;
private int $damage = 1;
private int $damageArmor = 1;
/** @var array<int,bool> [playerId => true] */
private array $playerSkipIds = [];

Expand All @@ -22,10 +21,9 @@ public function __construct(private AttackEnable $item, private int $distanceMax
$this->distanceTraveled = Setting::playerHeadRadius(); // shooting from center of player head so lets start on head edge
}

public function setProperties(int $damage = 1, int $damageArmor = 1): void
public function setProperties(int $damage): void
{
$this->damage = $damage;
$this->damageArmor = $damageArmor;
}

public function setOriginPlayer(int $playerId, bool $attackerSide, Point $origin): void
Expand Down Expand Up @@ -57,11 +55,6 @@ public function getDamage(): int
return $this->damage;
}

public function getDamageArmor(): int
{
return $this->damageArmor;
}

public function isActive(): bool
{
return ($this->damage > 0 && $this->distanceTraveled < $this->distanceMax);
Expand Down
8 changes: 5 additions & 3 deletions server/src/Core/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public function getRoundNumber(): int
return $this->roundNumber;
}

/** @infection-ignore-all */
public function addSoundEvent(SoundEvent $event): void
{
$this->addEvent($event);
Expand Down Expand Up @@ -308,7 +309,7 @@ public function playerFallDamageKilledEvent(Player $playerDead): void
$this->addSoundEvent($sound->setPlayer($playerDead));
}

public function playerBombKilledEvent(Player $playerDead): void
protected function playerBombKilledEvent(Player $playerDead): void
{
$this->addEvent(new KillEvent($playerDead, $playerDead, ItemId::BOMB, false));
$sound = new SoundEvent($playerDead->getPositionClone(), SoundType::PLAYER_DEAD);
Expand Down Expand Up @@ -467,7 +468,8 @@ private function calculateRoundMoneyAward(RoundEndEvent $roundEndEvent, Player $
$amount += match ($roundEndEvent->reason) {
RoundEndReason::ALL_ENEMIES_ELIMINATED => 3250,
RoundEndReason::BOMB_EXPLODED => 3500,
default => throw new GameException("New win reason? " . $roundEndEvent->reason->value),
RoundEndReason::TIME_RUNS_OUT,
RoundEndReason::BOMB_DEFUSED => throw new GameException('Invalid? ' . $roundEndEvent->reason->value), // @codeCoverageIgnore
};
} elseif (!$player->isAlive()) {
$amount += $this->score->getMoneyLossBonus(true);
Expand All @@ -481,7 +483,7 @@ private function calculateRoundMoneyAward(RoundEndEvent $roundEndEvent, Player $
$amount += match ($roundEndEvent->reason) {
RoundEndReason::ALL_ENEMIES_ELIMINATED, RoundEndReason::TIME_RUNS_OUT => 3250,
RoundEndReason::BOMB_DEFUSED => 3500,
default => throw new GameException("New win reason? " . $roundEndEvent->reason->value),
RoundEndReason::BOMB_EXPLODED => throw new GameException('Invalid? ' . $roundEndEvent->reason->value), // @codeCoverageIgnore
};
} else {
$amount += $this->score->getMoneyLossBonus(false);
Expand Down
1 change: 1 addition & 0 deletions server/src/Core/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function generateNeighbors(): void
/**
* @return array<string,string[]>
* @internal
* @codeCoverageIgnore
*/
public function internalGetGeneratedNeighbors(): array
{
Expand Down
15 changes: 7 additions & 8 deletions server/src/Core/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,19 @@ public function getScopeLevel(): int
return $this->scopeLevel;
}

/** @codeCoverageIgnore */
public function decrementQuantity(): void
{
// empty hook
}

/** @codeCoverageIgnore */
public function incrementQuantity(): void
{
// empty hook
}

/** @codeCoverageIgnore */
public function clone(): static
{
throw new GameException('Override clone() method if makes sense for item: ' . get_class($this));
Expand Down Expand Up @@ -111,14 +114,10 @@ public function getPrice(?self $alreadyHaveSlotItem = null): int

public function canPurchaseMultipleTime(self $newSlotItem): bool
{
if ($this->getType() === ItemType::TYPE_WEAPON_PRIMARY) {
return true;
}
if ($this->getType() === ItemType::TYPE_WEAPON_SECONDARY) {
return true;
}

return false;
return match ($this->getType()) {
ItemType::TYPE_WEAPON_PRIMARY, ItemType::TYPE_WEAPON_SECONDARY => true,
default => GameException::notImplementedYet('New item? ' . get_class($this)) // @codeCoverageIgnore
};
}

public function equip(): ?EquipEvent
Expand Down
12 changes: 6 additions & 6 deletions server/src/Core/PathFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class PathFinder
public function __construct(private readonly World $world, public readonly int $tileSize, public readonly int $colliderHeight)
{
if ($this->tileSize < 3 || $tileSize % 2 !== 1) {
throw new GameException('Tile size should be odd and greater than 1.');
throw new GameException('Tile size should be odd and greater than 1.'); // @codeCoverageIgnore
}

$this->tileSizeHalf = (int)ceil(($this->tileSize - 1) / 2);
Expand All @@ -37,7 +37,7 @@ public function __construct(private readonly World $world, public readonly int $
protected function canFullyMoveTo(Point $candidate, int $angle, int $targetDistance, int $radius, int $height): bool
{
if ($angle % 90 !== 0) {
GameException::notImplementedYet();
GameException::notImplementedYet(); // @codeCoverageIgnore
}

$looseFloor = false;
Expand Down Expand Up @@ -165,13 +165,13 @@ public function findTile(Point $pointOnFloor, int $radius): Point
}
}

GameException::notImplementedYet('Should always find something? ' . $pointOnFloor->hash());
GameException::notImplementedYet('Should always find something? ' . $pointOnFloor->hash()); // @codeCoverageIgnore
}

public function convertToNavMeshNode(Point $point): void
{
if ($point->x < 1 || $point->z < 1) {
throw new GameException('World start from 1');
throw new GameException('World start from 1'); // @codeCoverageIgnore
}

$fmodX = fmod($point->x, $this->tileSize);
Expand All @@ -188,7 +188,7 @@ public function buildNavigationMesh(Point $start, int $objectHeight): void
$startPoint = $start->clone();
$this->convertToNavMeshNode($startPoint);
if (!$this->world->findFloorSquare($startPoint, 1)) {
throw new GameException('No floor on start point');
throw new GameException('No floor on start point'); // @codeCoverageIgnore
}

/** @var SplQueue<Point> $queue */
Expand Down Expand Up @@ -226,7 +226,7 @@ public function buildNavigationMesh(Point $start, int $objectHeight): void
$this->graph->addNode($currentNode);
}
if (++$this->iterationCount === 10_000) {
GameException::notImplementedYet('New map, tileSize or bad test (no boundary box, bad starting point)?');
GameException::notImplementedYet('New map, tileSize or bad test (no boundary box, bad starting point)?'); // @codeCoverageIgnore
}
}
}
Expand Down
10 changes: 1 addition & 9 deletions server/src/Core/Point.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function to2D(string $XYaxis): Point2D
return new Point2D($this->z, $this->y);
}

GameException::notImplementedYet("New axis '$XYaxis'?");
GameException::notImplementedYet("New axis '$XYaxis'?"); // @codeCoverageIgnore
}

/**
Expand All @@ -160,12 +160,4 @@ public function toArray(): array
];
}

/**
* @return int[]
*/
public function toFlatArray(): array
{
return [$this->x, $this->y, $this->z];
}

}
40 changes: 0 additions & 40 deletions server/src/Core/Point2D.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,58 +9,18 @@ public function __construct(public int $x = 0, public int $y = 0)
{
}

public function equals(self $point): bool
{
return ($this->x === $point->x && $this->y === $point->y);
}

public function add(int $xAmount, int $yAmount): self
{
$this->x += $xAmount;
$this->y += $yAmount;
return $this;
}

public function addX(int $amount): self
{
$this->x += $amount;
return $this;
}

public function setX(int $int): self
{
$this->x = $int;
return $this;
}

public function addY(int $amount): self
{
$this->y += $amount;
return $this;
}

public function setY(int $int): self
{
$this->y = $int;
return $this;
}

public function __toString(): string
{
return "Point2D({$this->x},{$this->y})";
}

public function clone(): self
{
return new self($this->x, $this->y);
}

public function setFrom(self $point): void
{
$this->x = $point->x;
$this->y = $point->y;
}

/**
* @return array<string,int>
*/
Expand Down
Loading

0 comments on commit f06f871

Please sign in to comment.