-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display the stock amount of modules in the mod fab screen
Also recator a bit. #44
- Loading branch information
Showing
9 changed files
with
137 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/Module/Colony/View/ShowModuleFab/ModuleFabricationListItemTal.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Stu\Module\Colony\View\ShowModuleFab; | ||
|
||
use ColonyData; | ||
use ModuleQueue; | ||
use ModulesData; | ||
|
||
final class ModuleFabricationListItemTal | ||
{ | ||
private $colony; | ||
|
||
private $module; | ||
|
||
public function __construct( | ||
ModulesData $module, | ||
ColonyData $colony | ||
) { | ||
$this->colony = $colony; | ||
$this->module = $module; | ||
} | ||
|
||
public function getModule(): ModulesData | ||
{ | ||
return $this->module; | ||
} | ||
|
||
public function getModuleId(): int | ||
{ | ||
return (int)$this->module->getId(); | ||
} | ||
|
||
public function getGoodId(): int | ||
{ | ||
return (int)$this->module->getGoodId(); | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->module->getName(); | ||
} | ||
|
||
public function getEnergyCost(): int | ||
{ | ||
return (int)$this->module->getEcost(); | ||
} | ||
|
||
public function getConstructionCosts(): array | ||
{ | ||
return $this->module->getCost(); | ||
} | ||
|
||
public function getAmountQueued(): int | ||
{ | ||
return ModuleQueue::getAmountByColonyAndModule($this->colony->getId(), $this->module->getId()); | ||
} | ||
|
||
public function getAmountInStock(): int | ||
{ | ||
$result = $this->colony->getStorage()[$this->getGoodId()] ?? null; | ||
|
||
if ($result === null) { | ||
return 0; | ||
} | ||
return (int) $result->getAmount(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,15 +103,13 @@ static function countInstances($sql="") { #{{{ | |
return DB()->query("SELECT COUNT(*) FROM ".self::tablename." ".$sql,1); | ||
} # }}} | ||
|
||
/** | ||
*/ | ||
static function getByColonyAndModule($colony_id,$module_id) { #{{{ | ||
static function getAmountByColonyAndModule($colony_id,$module_id): int { | ||
$result = DB()->query("SELECT * FROM ".self::tablename." WHERE colony_id=".$colony_id." AND module_id=".$module_id,4); | ||
if ($result == 0) { | ||
return FALSE; | ||
return 0; | ||
} | ||
return new ModuleQueueData($result); | ||
} # }}} | ||
return (int) $result['count']; | ||
} | ||
|
||
/** | ||
*/ | ||
|
@@ -148,32 +146,3 @@ static function queueModule($colony_id,$function,$module_id,$count) { #{{{ | |
} # }}} | ||
|
||
} #}}} | ||
|
||
/** | ||
* @author Daniel Jakob <[email protected]> | ||
* @version $Revision: 1.4 $ | ||
* @access public | ||
*/ | ||
class ModuleQueueColonyWrapper { #{{{ | ||
|
||
private $module_id = 0; | ||
|
||
/** | ||
*/ | ||
function __construct($module_id) { #{{{ | ||
$this->module_id = $module_id; | ||
} # }}} | ||
|
||
/** | ||
*/ | ||
function __get($colony_id) { #{{{ | ||
$queue = ModuleQueue::getByColonyAndModule($colony_id,$this->module_id); | ||
if (!$queue) { | ||
return FALSE; | ||
} | ||
return $queue->getAmount(); | ||
} # }}} | ||
|
||
} #}}} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters