diff --git a/hwe/func_tournament.php b/hwe/func_tournament.php index ffdaef12..c020270d 100644 --- a/hwe/func_tournament.php +++ b/hwe/func_tournament.php @@ -383,10 +383,12 @@ function getDummyBettingInfo(string $tnmt_type): BettingInfo name: $tnmt_type, finished: true, selectCnt: 1, + isExclusive: null, reqInheritancePoint: false, openYearMonth: 0, closeYearMonth: 0, - candidates: [] + candidates: [], + winner: null, ); } @@ -425,6 +427,7 @@ function startBetting($type, $unit) $candidates[$general['no']] = new \sammo\DTO\SelectItem( title: $general['name'], info: "{$statName}: {$general[$statKey]}", + isHtml: null, aux: $general ); } @@ -436,10 +439,12 @@ function startBetting($type, $unit) name: $typeText, finished: false, selectCnt: 1, + isExclusive: null, reqInheritancePoint: false, openYearMonth: $openYearMonth, closeYearMonth: $closeYearMonth, candidates: $candidates, + winner: null, )); $betting = new Betting($bettingID); diff --git a/hwe/index.php b/hwe/index.php index e6badc42..a8fc6416 100644 --- a/hwe/index.php +++ b/hwe/index.php @@ -116,7 +116,7 @@ $lastVoteID = $gameStor->lastVote; $lastVote = null; if($lastVoteID){ $voteStor = KVStorage::getStorage($db, 'vote'); - $lastVote = new VoteInfo($voteStor->getValue("vote_{$lastVoteID}")); + $lastVote = VoteInfo::fromArray($voteStor->getValue("vote_{$lastVoteID}")); if($lastVote->endDate && $lastVote->endDate < TimeUtil::now()){ $lastVote = null; } diff --git a/hwe/sammo/API/Betting/GetBettingDetail.php b/hwe/sammo/API/Betting/GetBettingDetail.php index 017780f6..069032c4 100644 --- a/hwe/sammo/API/Betting/GetBettingDetail.php +++ b/hwe/sammo/API/Betting/GetBettingDetail.php @@ -47,7 +47,7 @@ class GetBettingDetail extends \sammo\BaseAPI } try{ - $bettingInfo = new BettingInfo($rawBettingInfo); + $bettingInfo = BettingInfo::fromArray($rawBettingInfo); } catch(\Error $e){ return $e->getMessage(); diff --git a/hwe/sammo/API/Betting/GetBettingList.php b/hwe/sammo/API/Betting/GetBettingList.php index aecd111f..e639d6a0 100644 --- a/hwe/sammo/API/Betting/GetBettingList.php +++ b/hwe/sammo/API/Betting/GetBettingList.php @@ -49,7 +49,7 @@ class GetBettingList extends \sammo\BaseAPI $bettingList = []; foreach ($bettingStor->getAll() as $_key => $rawItem) { - $item = new BettingInfo($rawItem); + $item = BettingInfo::fromArray($rawItem); if ($reqType !== null && $item->type != $reqType) { continue; } diff --git a/hwe/sammo/API/Vote/AddComment.php b/hwe/sammo/API/Vote/AddComment.php index 1122415b..f3811157 100644 --- a/hwe/sammo/API/Vote/AddComment.php +++ b/hwe/sammo/API/Vote/AddComment.php @@ -29,6 +29,7 @@ class AddComment extends \sammo\BaseAPI if (!$v->validate()) { return $v->errorStr(); } + $this->args['voteID'] = (int)$this->args['voteID']; return null; } @@ -46,11 +47,12 @@ class AddComment extends \sammo\BaseAPI $comment = new VoteComment( - vote_id: $voteID, - general_id: $generalID, - nation_id: $nationID, - nation_name: $nationName, - general_name: $generalName, + id: null, + voteID: $voteID, + generalID: $generalID, + nationID: $nationID, + nationName: $nationName, + generalName: $generalName, text: $text, date: $date ); diff --git a/hwe/sammo/API/Vote/GetVoteDetail.php b/hwe/sammo/API/Vote/GetVoteDetail.php index b40daa66..07b71f01 100644 --- a/hwe/sammo/API/Vote/GetVoteDetail.php +++ b/hwe/sammo/API/Vote/GetVoteDetail.php @@ -40,7 +40,7 @@ class GetVoteDetail extends \sammo\BaseAPI if (!$rawVote) { return '설문조사가 없습니다.'; } - $voteInfo = new VoteInfo(...$rawVote); + $voteInfo = VoteInfo::fromArray($rawVote); $votes = array_map(fn ($arr) => [Json::decode($arr[0]), $arr[1]], $db->queryAllLists( @@ -48,13 +48,13 @@ class GetVoteDetail extends \sammo\BaseAPI $voteID )); - $comments = VoteComment::arrayOf($db->query('SELECT * FROM vote_comment WHERE vote_id = %i ORDER BY `id` ASC', $voteID)); + $comments = array_map(fn ($arr) => VoteComment::fromArray($arr), $db->query('SELECT * FROM vote_comment WHERE vote_id = %i ORDER BY `id` ASC', $voteID)); $myVote = null; - if($session->isGameLoggedIn()){ + if ($session->isGameLoggedIn()) { $generalID = $session->generalID; $rawMyVote = $db->queryFirstField('SELECT selection FROM vote WHERE vote_id = %i AND general_id = %i', $voteID, $generalID); - if($rawMyVote){ + if ($rawMyVote) { $myVote = Json::decode($rawMyVote); } } diff --git a/hwe/sammo/API/Vote/GetVoteList.php b/hwe/sammo/API/Vote/GetVoteList.php index a772fd90..93ba279c 100644 --- a/hwe/sammo/API/Vote/GetVoteList.php +++ b/hwe/sammo/API/Vote/GetVoteList.php @@ -33,7 +33,7 @@ class GetVoteList extends \sammo\BaseAPI continue; } $voteID = (int)substr($voteKey, 5); - $votes[$voteID] = new VoteInfo(...$rawVote); + $votes[$voteID] = VoteInfo::fromArray($rawVote); } return [ diff --git a/hwe/sammo/API/Vote/NewVote.php b/hwe/sammo/API/Vote/NewVote.php index f8662462..47cb1544 100644 --- a/hwe/sammo/API/Vote/NewVote.php +++ b/hwe/sammo/API/Vote/NewVote.php @@ -43,7 +43,7 @@ class NewVote extends \sammo\BaseAPI if (!$rawLastVoteInfo) { return; } - $lastVoteInfo = new VoteInfo(...$rawLastVoteInfo); + $lastVoteInfo = VoteInfo::fromArray($rawLastVoteInfo); if ($lastVoteInfo->endDate) { return; } diff --git a/hwe/sammo/API/Vote/Vote.php b/hwe/sammo/API/Vote/Vote.php index 7ecc5220..f530044a 100644 --- a/hwe/sammo/API/Vote/Vote.php +++ b/hwe/sammo/API/Vote/Vote.php @@ -58,7 +58,7 @@ class Vote extends \sammo\BaseAPI if (!$rawVoteInfo) { return '설문조사가 없습니다.'; } - $voteInfo = new VoteInfo(...$rawVoteInfo); + $voteInfo = VoteInfo::fromArray($rawVoteInfo); if ($voteInfo->endDate && $voteInfo->endDate < new \DateTimeImmutable()) { return '설문조사가 종료되었습니다.'; diff --git a/hwe/sammo/Betting.php b/hwe/sammo/Betting.php index 59767609..8054d910 100644 --- a/hwe/sammo/Betting.php +++ b/hwe/sammo/Betting.php @@ -43,7 +43,7 @@ class Betting if ($rawBettingInfo === null) { throw new \RuntimeException("해당 베팅이 없습니다: {$bettingID}"); } - $this->info = new BettingInfo($rawBettingInfo); + $this->info = BettingInfo::fromArray($rawBettingInfo); } private function _convertBettingKey(array $bettingType): string @@ -148,13 +148,14 @@ class Betting } } - $bettingItem = new BettingItem([ - 'betting_id' => $this->bettingID, - 'general_id' => $generalID, - 'user_id' => $userID, - 'betting_type' => $bettingTypeKey, - 'amount' => $amount - ]); + $bettingItem = new BettingItem( + rowID: null, + bettingID: $this->bettingID, + generalID: $generalID, + userID: $userID, + bettingType: $bettingTypeKey, + amount: $amount + ); $db->insertUpdate( 'ng_betting', diff --git a/hwe/sammo/DTO/BettingInfo.php b/hwe/sammo/DTO/BettingInfo.php index 81970429..c53579cc 100644 --- a/hwe/sammo/DTO/BettingInfo.php +++ b/hwe/sammo/DTO/BettingInfo.php @@ -2,33 +2,32 @@ namespace sammo\DTO; +use sammo\DTO\Attr\Convert; +use sammo\DTO\Converter\MapConverter; use sammo\DTO\SelectItem; -use Spatie\DataTransferObject\Attributes\CastWith; -use Spatie\DataTransferObject\Attributes\Strict; -use Spatie\DataTransferObject\DataTransferObject; -use Spatie\DataTransferObject\Casters\ArrayCaster; //https://json2dto.atymic.dev/ - - -#[Strict] -class BettingInfo extends DataTransferObject +class BettingInfo extends DTO { - public int $id; - public string $type; - public string $name; - public bool $finished; - public int $selectCnt; - public ?bool $isExlusive; - public bool $reqInheritancePoint; - public int $openYearMonth; - public int $closeYearMonth; + public function __construct( + public int $id, + public string $type, + public string $name, + public bool $finished, + public int $selectCnt, + public ?bool $isExclusive, + public bool $reqInheritancePoint, + public int $openYearMonth, + public int $closeYearMonth, - /** @var \sammo\DTO\SelectItem[] */ - #[CastWith(ArrayCaster::class, itemType: SelectItem::class)] - public array $candidates; - public ?array $winner; + + /** @var \sammo\DTO\SelectItem[] */ + #[Convert(MapConverter::class, [SelectItem::class])] + public array $candidates, + public ?array $winner, + ) { + } } diff --git a/hwe/sammo/DTO/BettingItem.php b/hwe/sammo/DTO/BettingItem.php index d88426aa..9aff3354 100644 --- a/hwe/sammo/DTO/BettingItem.php +++ b/hwe/sammo/DTO/BettingItem.php @@ -2,32 +2,28 @@ namespace sammo\DTO; -use Spatie\DataTransferObject\Attributes\MapFrom; -use Spatie\DataTransferObject\Attributes\MapTo; -use Spatie\DataTransferObject\Attributes\Strict; -use Spatie\DataTransferObject\DataTransferObject; +use sammo\DTO\Attr\NullIsUndefined; +use sammo\DTO\Attr\RawName; -#[Strict] -class BettingItem extends DataTransferObject +class BettingItem extends DTO { - #[MapFrom('id')] - #[MapTo('id')] - public null|int $rowID = null; + public function __construct( + #[RawName('id')] + #[NullIsUndefined] + public ?int $rowID, - #[MapFrom('betting_id')] - #[MapTo('betting_id')] - public int $bettingID; + #[RawName('betting_id')] + public int $bettingID, - #[MapFrom('general_id')] - #[MapTo('general_id')] - public int $generalID; + #[RawName('general_id')] + public int $generalID, - #[MapFrom('user_id')] - #[MapTo('user_id')] - public null|int $userID; + #[RawName('user_id')] + public ?int $userID, - #[MapFrom('betting_type')] - #[MapTo('betting_type')] - public string $bettingType; - public int $amount; + #[RawName('betting_type')] + public string $bettingType, + public int $amount, + ) { + } } diff --git a/hwe/sammo/DTO/SelectItem.php b/hwe/sammo/DTO/SelectItem.php index df599b00..f68a27d0 100644 --- a/hwe/sammo/DTO/SelectItem.php +++ b/hwe/sammo/DTO/SelectItem.php @@ -2,14 +2,17 @@ namespace sammo\DTO; -use Spatie\DataTransferObject\Attributes\Strict; -use Spatie\DataTransferObject\DataTransferObject; +use sammo\DTO\Attr\Convert; +use sammo\DTO\Converter\MapConverter; -#[Strict] -class SelectItem extends DataTransferObject +class SelectItem extends DTO { - public string $title; - public ?string $info; - public ?bool $isHtml; - public ?array $aux; + public function __construct( + public string $title, + public ?string $info, + public ?bool $isHtml, + #[Convert(MapConverter::class, ['string', 'int', 'float', 'array', 'null', 'bool'])] + public ?array $aux, + ) { + } } diff --git a/hwe/sammo/DTO/VoteComment.php b/hwe/sammo/DTO/VoteComment.php index ca44eed6..8881b170 100644 --- a/hwe/sammo/DTO/VoteComment.php +++ b/hwe/sammo/DTO/VoteComment.php @@ -2,37 +2,33 @@ namespace sammo\DTO; -use Spatie\DataTransferObject\Attributes\MapFrom; -use Spatie\DataTransferObject\Attributes\MapTo; -use Spatie\DataTransferObject\Attributes\Strict; -use Spatie\DataTransferObject\DataTransferObject; +use sammo\DTO\Attr\NullIsUndefined; +use sammo\DTO\Attr\RawName; -#[Strict] -class VoteComment extends DataTransferObject +class VoteComment extends DTO { - public ?int $id; + public function __construct( + #[NullIsUndefined] + public ?int $id, - #[MapFrom('vote_id')] - #[MapTo('vote_id')] - public int $voteID; + #[RawName('vote_id')] + public int $voteID, - #[MapFrom('general_id')] - #[MapTo('general_id')] - public int $generalID; + #[RawName('general_id')] + public int $generalID, - #[MapFrom('nation_id')] - #[MapTo('nation_id')] - public int $nationID; + #[RawName('nation_id')] + public int $nationID, - #[MapFrom('nation_name')] - #[MapTo('nation_name')] - public string $nationName; + #[RawName('nation_name')] + public string $nationName, - #[MapFrom('general_name')] - #[MapTo('general_name')] - public string $generalName; + #[RawName('general_name')] + public string $generalName, - public string $text; + public string $text, - public string $date; + public string $date, + ) { + } } diff --git a/hwe/sammo/DTO/VoteInfo.php b/hwe/sammo/DTO/VoteInfo.php index c2f29b0b..f54a6a57 100644 --- a/hwe/sammo/DTO/VoteInfo.php +++ b/hwe/sammo/DTO/VoteInfo.php @@ -2,23 +2,18 @@ namespace sammo\DTO; -use Spatie\DataTransferObject\Attributes\CastWith; -use Spatie\DataTransferObject\Attributes\Strict; -use Spatie\DataTransferObject\DataTransferObject; -use Spatie\DataTransferObject\Casters\ArrayCaster; - -//https://json2dto.atymic.dev/ - -#[Strict] -class VoteInfo extends DataTransferObject +class VoteInfo extends DTO { - public int $id; - public string $title; - public int $multipleOptions; + public function __construct( + public int $id, + public string $title, + public int $multipleOptions, - public string $startDate; - public ?string $endDate; + public string $startDate, + public ?string $endDate, - /** @var string[] */ - public array $options; + /** @var string[] */ + public array $options, + ) { + } } diff --git a/hwe/sammo/Event/Action/OpenNationBetting.php b/hwe/sammo/Event/Action/OpenNationBetting.php index fb04c43f..26746242 100644 --- a/hwe/sammo/Event/Action/OpenNationBetting.php +++ b/hwe/sammo/Event/Action/OpenNationBetting.php @@ -72,7 +72,7 @@ class OpenNationBetting extends \sammo\Event\Action aux: $nationRaw, ); } - + $bettingID = \sammo\Betting::genNextBettingID(); Betting::openBetting(new BettingInfo( id: $bettingID, @@ -80,10 +80,12 @@ class OpenNationBetting extends \sammo\Event\Action name: "{$name} 예상", finished: false, selectCnt: $this->nationCnt, + isExclusive: null, reqInheritancePoint: true, openYearMonth: $openYearMonth, closeYearMonth: $closeYearMonth, candidates: $candidates, + winner: null, )); $db->insert('event', [ diff --git a/hwe/sammo/GeneralAI.php b/hwe/sammo/GeneralAI.php index 4300375a..770c5006 100644 --- a/hwe/sammo/GeneralAI.php +++ b/hwe/sammo/GeneralAI.php @@ -3996,7 +3996,7 @@ class GeneralAI if (!key_exists($chiefLevel, $this->chiefGenerals) && !key_exists($chiefLevel, $nextChiefs)) { $newChiefProb = 1; } else { - $newChiefProb = $this->rng->nextBool(0.1); + $newChiefProb = $this->rng->nextBool(0.1)?1:0; } if ($newChiefProb < 1 && !$this->rng->nextBool($newChiefProb)) { diff --git a/hwe/ts/PageInheritPoint.vue b/hwe/ts/PageInheritPoint.vue index ec553105..2bfef428 100644 --- a/hwe/ts/PageInheritPoint.vue +++ b/hwe/ts/PageInheritPoint.vue @@ -155,7 +155,7 @@
통/무/지
- +
- +
- +
@@ -144,10 +144,10 @@
- +
- +

@@ -174,7 +174,7 @@
도시
-