revert: LazyVarUpdater에 \BackedEnum 롤백

This commit is contained in:
2022-08-26 17:30:24 +09:00
parent 8a5a3b67f7
commit a88ec71b44
2 changed files with 13 additions and 49 deletions
+12 -45
View File
@@ -15,21 +15,15 @@ trait LazyVarUpdater{
return $this->raw; return $this->raw;
} }
function getVar(string|\BackedEnum $key){ function getVar(string $key){
if($key instanceof \BackedEnum){
$key = $key->value;
}
return $this->raw[$key]; return $this->raw[$key];
} }
function getVars(string|\BackedEnum ...$keys){ function getVars(string ...$keys){
return array_map([$this, 'getVar'], $keys); return array_map([$this, 'getVar'], $keys);
} }
function touchVar(string|\BackedEnum $key):bool{ function touchVar(string $key):bool{
if($key instanceof \BackedEnum){
$key = $key->value;
}
if(key_exists($key, $this->raw)){ if(key_exists($key, $this->raw)){
return false; return false;
} }
@@ -47,25 +41,16 @@ trait LazyVarUpdater{
} }
} }
function setVar(string|\BackedEnum $key, $value){ function setVar(string $key, $value){
if($key instanceof \BackedEnum){
$key = $key->value;
}
return $this->updateVar($key, $value); return $this->updateVar($key, $value);
} }
function getAuxVar(string|\BackedEnum $key){ function getAuxVar(string $key){
if($key instanceof \BackedEnum){
$key = $key->value;
}
$this->unpackAux(); $this->unpackAux();
return $this->raw['auxVar'][$key]??null; return $this->raw['auxVar'][$key]??null;
} }
function setAuxVar(string|\BackedEnum $key, $var){ function setAuxVar(string $key, $var){
if($key instanceof \BackedEnum){
$key = $key->value;
}
$oldVar = $this->getAuxVar($key); $oldVar = $this->getAuxVar($key);
if($oldVar === $var){ if($oldVar === $var){
@@ -81,10 +66,7 @@ trait LazyVarUpdater{
$this->auxUpdated = true; $this->auxUpdated = true;
} }
function updateVar(string|\BackedEnum $key, $value){ function updateVar(string $key, $value){
if($key instanceof \BackedEnum){
$key = $key->value;
}
if(($this->raw[$key]??null) === $value){ if(($this->raw[$key]??null) === $value){
return; return;
} }
@@ -94,10 +76,7 @@ trait LazyVarUpdater{
$this->raw[$key] = $value; $this->raw[$key] = $value;
} }
function updateVarWithLimit(string|\BackedEnum $key, $value, $min = null, $max = null){ function updateVarWithLimit(string $key, $value, $min = null, $max = null){
if($key instanceof \BackedEnum){
$key = $key->value;
}
if($min !== null && $value < $min){ if($min !== null && $value < $min){
$value = $min; $value = $min;
} }
@@ -107,11 +86,8 @@ trait LazyVarUpdater{
$this->updateVar($key, $value); $this->updateVar($key, $value);
} }
function increaseVar(string|\BackedEnum $key, $value) function increaseVar(string $key, $value)
{ {
if($key instanceof \BackedEnum){
$key = $key->value;
}
if($value === 0){ if($value === 0){
return; return;
} }
@@ -119,10 +95,7 @@ trait LazyVarUpdater{
$this->updateVar($key, $targetValue); $this->updateVar($key, $targetValue);
} }
function increaseVarWithLimit(string|\BackedEnum $key, $value, $min = null, $max = null){ function increaseVarWithLimit(string $key, $value, $min = null, $max = null){
if($key instanceof \BackedEnum){
$key = $key->value;
}
$targetValue = $this->raw[$key] + $value; $targetValue = $this->raw[$key] + $value;
if($min !== null && $targetValue < $min){ if($min !== null && $targetValue < $min){
$targetValue = $min; $targetValue = $min;
@@ -133,11 +106,8 @@ trait LazyVarUpdater{
$this->updateVar($key, $targetValue); $this->updateVar($key, $targetValue);
} }
function multiplyVar(string|\BackedEnum $key, $value) function multiplyVar(string $key, $value)
{ {
if($key instanceof \BackedEnum){
$key = $key->value;
}
if($value === 1){ if($value === 1){
return; return;
} }
@@ -145,10 +115,7 @@ trait LazyVarUpdater{
$this->updateVar($key, $targetValue); $this->updateVar($key, $targetValue);
} }
function multiplyVarWithLimit(string|\BackedEnum $key, $value, $min = null, $max = null){ function multiplyVarWithLimit(string $key, $value, $min = null, $max = null){
if($key instanceof \BackedEnum){
$key = $key->value;
}
$targetValue = $this->raw[$key] * $value; $targetValue = $this->raw[$key] * $value;
if($min !== null && $targetValue < $min){ if($min !== null && $targetValue < $min){
$targetValue = $min; $targetValue = $min;
+1 -4
View File
@@ -44,10 +44,7 @@ class WarUnitCity extends WarUnit{
return $this->getVar('name'); return $this->getVar('name');
} }
function getCityVar(string|\BackedEnum $key){ function getCityVar(string $key){
if($key instanceof \BackedEnum){
$key = $key->value;
}
return $this->raw[$key]; return $this->raw[$key];
} }