feat(WIP): process 등용 등

- ColorSelect 색을 가득 채움,
- ColorSelect 결과값을 둥글게
- procGeneralList의 column 가변형 정의
- 등용 brief 조사 처리 버그 수정
This commit is contained in:
2021-12-20 01:08:08 +09:00
parent 78d95048d5
commit 64e36f038e
9 changed files with 325 additions and 123 deletions
+8 -17
View File
@@ -185,23 +185,14 @@ class che_군량매매 extends Command\GeneralCommand{
return true;
}
public function getForm(): string
public function exportJSVars(): array
{
ob_start();
?>
자신의 군량을 사거나 팝니다.<br>
<select id='buyRice' name="buyRice" size=1 style=color:white;background-color:black>
<option value='false'>팜</option>
<option value='true'>삼</option>
</select>
<select name=amount id='amount' size=1 style=text-align:right;color:white;background-color:black>
<?php foreach(GameConst::$resourceActionAmountGuide as $amount): ?>
<option value='<?=$amount?>'><?=$amount?></option>
<?php endforeach; ?>
</select> <input type=button id="commonSubmit" value="<?=$this->getName()?>"><br>
<?php
return ob_get_clean();
return [
'procRes' => [
'minAmount' => 100,
'maxAmount' => GameConst::$maxResourceActionAmount,
'amountGuide' => GameConst::$resourceActionAmountGuide,
]
];
}
}
+54 -60
View File
@@ -1,9 +1,13 @@
<?php
namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
@@ -21,30 +25,32 @@ use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_등용 extends Command\GeneralCommand{
class che_등용 extends Command\GeneralCommand
{
static protected $actionName = '등용';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
//NOTE: 사망 직전에 '등용' 턴을 넣을 수 있으므로, 존재하지 않는 장수여도 argTest에서 바로 탈락시키지 않음
if(!key_exists('destGeneralID', $this->arg)){
if (!key_exists('destGeneralID', $this->arg)) {
return false;
}
$destGeneralID = $this->arg['destGeneralID'];
if(!is_int($destGeneralID)){
if (!is_int($destGeneralID)) {
return false;
}
if($destGeneralID <= 0){
if ($destGeneralID <= 0) {
return false;
}
if($destGeneralID == $this->generalObj->getID()){
if ($destGeneralID == $this->generalObj->getID()) {
return false;
}
$this->arg = [
'destGeneralID'=>$destGeneralID
'destGeneralID' => $destGeneralID
];
return true;
}
@@ -59,11 +65,11 @@ class che_등용 extends Command\GeneralCommand{
$relYear = $this->env['year'] - $this->env['startyear'];
$this->permissionConstraints=[
$this->permissionConstraints = [
ConstraintHelper::ReqEnvValue('join_mode', '!=', 'onlyRandom', '랜덤 임관만 가능합니다'),
];
$this->minConditionConstraints=[
$this->minConditionConstraints = [
ConstraintHelper::ReqEnvValue('join_mode', '!=', 'onlyRandom', '랜덤 임관만 가능합니다'),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
@@ -79,7 +85,7 @@ class che_등용 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$relYear = $this->env['year'] - $this->env['startyear'];
$this->fullConditionConstraints=[
$this->fullConditionConstraints = [
ConstraintHelper::ReqEnvValue('join_mode', '!=', 'onlyRandom', '랜덤 임관만 가능합니다'),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
@@ -90,33 +96,37 @@ class che_등용 extends Command\GeneralCommand{
ConstraintHelper::ReqGeneralRice($reqRice),
];
if($this->destGeneralObj->getVar('officer_level') == 12){
if ($this->destGeneralObj->getVar('officer_level') == 12) {
$this->fullConditionConstraints[] = ConstraintHelper::AlwaysFail('군주에게는 등용장을 보낼 수 없습니다.');
}
}
public function canDisplay():bool{
public function canDisplay(): bool
{
return $this->env['join_mode'] !== 'onlyRandom';
}
public function getCost():array{
public function getCost(): array
{
$env = $this->env;
if(!$this->isArgValid){
if (!$this->isArgValid) {
return [$env['develcost'], 0];
}
$destGeneral = $this->destGeneralObj;
$reqGold = Util::round(
$env['develcost'] +
($destGeneral->getVar('experience') + $destGeneral->getVar('dedication')) / 1000
($destGeneral->getVar('experience') + $destGeneral->getVar('dedication')) / 1000
) * 10;
return [$reqGold, 0];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
@@ -124,12 +134,13 @@ class che_등용 extends Command\GeneralCommand{
{
$destGeneralName = $this->destGeneralObj->getName();
$name = $this->getName();
$josaUl = JosaUtil::pick($name, '을');
$josaUl = JosaUtil::pick($destGeneralName, '을');
return "{$destGeneralName}{$josaUl} {$name}";
}
public function run():bool{
if(!$this->hasFullConditionMet()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -145,11 +156,10 @@ class che_등용 extends Command\GeneralCommand{
$msg = ScoutMessage::buildScoutMessage($general->getID(), $destGeneralID, $reason, new \DateTime($general->getTurnTime()));
if($msg){
if ($msg) {
$logger->pushGeneralActionLog("<Y>{$destGeneralName}</>에게 등용 권유 서신을 보냈습니다. <1>$date</>");
$msg->send(true);
}
else{
} else {
$logger->pushGeneralActionLog("<Y>{$destGeneralName}</>에게 등용 권유 서신을 보내지 못했습니다. {$reason} <1>$date</>");
}
@@ -172,43 +182,27 @@ class che_등용 extends Command\GeneralCommand{
return true;
}
public function getForm(): string
public function exportJSVars(): array
{
$db = DB::db();
$destRawGenerals = $db->queryAllLists('SELECT no,name,nation,officer_level,npc,leadership,strength,intel FROM general WHERE npc < 2 AND officer_level != 12 AND no != %i ORDER BY npc,binary(name)', $this->generalObj->getID());
$nationList = [];
$destGenerals = [];
$destRawGenerals = $db->query('SELECT no,name,npc,nation FROM general WHERE npc < 2 AND no != %i AND officer_level != 12 ORDER BY npc,binary(name)',$this->generalObj->getID());
foreach($destRawGenerals as $destGeneral){
$destNationID = $destGeneral['nation'];
if(!key_exists($destNationID, $destGenerals)){
$destGenerals[$destNationID] = [];
}
$destGenerals[$destNationID][] = $destGeneral;
foreach ([getNationStaticInfo(0), ...getAllNationStaticInfo()] as $destNation) {
$nationList[] = [
'id' => $destNation['nation'],
'name' => $destNation['name'],
'color' => $destNation['color'],
'power' => $destNation['power'],
];
}
$nationList = array_merge([0=>getNationStaticInfo(0)], getAllNationStaticInfo());
ob_start();
?>
재야나 타국의 장수를 등용합니다.<br>
서신은 개인 메세지로 전달됩니다.<br>
등용할 장수를 목록에서 선택하세요.<br>
<select class='formInput' name="destGeneralID" id="destGeneralID" size='1' style='color:white;background-color:black;'>
<?php foreach($nationList as $destNation): ?>
<optgroup style='background-color:<?=$destNation['color']?>;color:<?=newColor($destNation['color'])?>;' label="【<?=$destNation['name']?>】" >
<?php foreach($destGenerals[$destNation['nation']]??[] as $destGeneral):
$nameColor = \sammo\getNameColor($destGeneral['npc']);
if($nameColor){
$nameColor = " style='color:{$nameColor}'";
}
?>
<option style="background-color:black;color:white" value='<?=$destGeneral['no']?>' <?=$nameColor?>><?=$destGeneral['name']?></option>
<?php endforeach; ?>
</optgroup>
<?php endforeach; ?>
</select> <input type=button id="commonSubmit" value="<?=$this->getName()?>"><br>
<?php
return ob_get_clean();
return [
'procRes' => [
'nationList' => $nationList,
'generals' => $destRawGenerals,
'generalsKey' => ['no', 'name', 'nationID', 'officerLevel', 'npc', 'leadership', 'strength', 'intel']
]
];
}
}
}
+4 -9
View File
@@ -26,7 +26,7 @@
<div
class="sam-nation-own-bgcolor"
:style="{
padding: '0.375rem 0.75rem',
padding: '0.545rem 0.75rem',
}"
>
{{ props.option.title }}
@@ -37,12 +37,13 @@
<div
:class="`sam-color-${props.option.title.slice(1)}`"
:style="{
margin: '-0.375rem -0.75rem',
margin: '-0.25rem -0.75rem',
}"
><div
class="sam-nation-own-bgcolor"
:style="{
padding: '0.375rem 0.75rem',
padding: '0.30rem 0.75rem',
borderRadius: '0.25rem',
}"
>{{ props.option.title }}</div
></div
@@ -102,9 +103,3 @@ export default defineComponent({
},
});
</script>
<style scoped>
.multiselect__option {
padding: 0;
}
</style>
@@ -0,0 +1,78 @@
<template>
<TopBackBar :title="commandName" type="chief" />
<div class="bg0">
<div>
자신의 군량을 사거나 팝니다.<br />
</div>
<div class="row">
<div class="col-2 col-md-1">
군량을 :
<b-button-group>
<b-button :pressed="buyRice" @click="buyRice=true"></b-button>
<b-button :pressed="!buyRice" @click="buyRice=false"></b-button>
</b-button-group>
</div>
<div class="col-10 col-md-4">
금액 :
<AmountSelect
:amountGuide="amountGuide"
v-model="amount"
:maxAmount="maxAmount"
:minAmount="minAmount"
/>
</div>
<div class="col-4 col-md-2 d-grid">
<b-button variant="primary" @click="submit">{{ commandName }}</b-button>
</div>
</div>
</div>
<BottomBar :title="commandName" />
</template>
<script lang="ts">
import AmountSelect from "@/processing/AmountSelect.vue";
import { defineComponent, ref } from "vue";
import { unwrap } from "@/util/unwrap";
import { Args } from "@/processing/args";
import TopBackBar from "@/components/TopBackBar.vue";
import BottomBar from "@/components/BottomBar.vue";
declare const commandName: string;
declare const procRes: {
minAmount: number;
maxAmount: number;
amountGuide: number[];
};
export default defineComponent({
components: {
AmountSelect,
TopBackBar,
BottomBar,
},
setup() {
const amount = ref(1000);
const buyRice = ref(true);
async function submit(e: Event) {
const event = new CustomEvent<Args>("customSubmit", {
detail: {
amount: amount.value,
buyRice: buyRice.value,
},
});
unwrap(e.target).dispatchEvent(event);
}
return {
buyRice,
amount,
minAmount: ref(procRes.minAmount),
maxAmount: ref(procRes.maxAmount),
amountGuide: procRes.amountGuide,
commandName,
submit,
};
},
});
</script>
+99
View File
@@ -0,0 +1,99 @@
<template>
<TopBackBar :title="commandName" type="chief" />
<div class="bg0">
<div>
재야나 타국의 장수를 등용합니다.<br />
서신은 개인 메세지로 전달됩니다.<br />
등용할 장수를 목록에서 선택하세요.<br />
</div>
<div class="row">
<div class="col-12 col-md-6">
장수 :
<GeneralSelect
:generals="generalList"
:groupByNation="nationList"
:textHelper="textHelpGeneral"
v-model="selectedGeneralID"
/>
</div>
<div class="col-4 col-md-2 d-grid">
<b-button variant="primary" @click="submit">{{ commandName }}</b-button>
</div>
</div>
</div>
<BottomBar :title="commandName" />
</template>
<script lang="ts">
import GeneralSelect from "@/processing/GeneralSelect.vue";
import { defineComponent, ref } from "vue";
import { unwrap } from "@/util/unwrap";
import { Args } from "@/processing/args";
import TopBackBar from "@/components/TopBackBar.vue";
import BottomBar from "@/components/BottomBar.vue";
import {
convertGeneralList,
procGeneralItem,
procGeneralKey,
procGeneralRawItemList,
procNationItem,
procNationList,
} from "../processingRes";
import { getNpcColor } from "@/common_legacy";
declare const mapTheme: string;
declare const commandName: string;
declare const procRes: {
generals: procGeneralRawItemList;
generalsKey: procGeneralKey[];
nationList: procNationList,
};
export default defineComponent({
components: {
GeneralSelect,
TopBackBar,
BottomBar,
},
setup() {
const generalList = convertGeneralList(
procRes.generalsKey,
procRes.generals
);
const selectedGeneralID = ref(generalList[0].no);
function textHelpGeneral(gen: procGeneralItem): string {
const nameColor = getNpcColor(gen.npc);
const name = nameColor
? `<span style="color:${nameColor}">${gen.name}</span>`
: gen.name;
return name;
}
async function submit(e: Event) {
const event = new CustomEvent<Args>("customSubmit", {
detail: {
destGeneralID: selectedGeneralID.value,
},
});
unwrap(e.target).dispatchEvent(event);
}
const nationList = new Map<number, procNationItem>();
for(const nationItem of procRes.nationList){
nationList.set(nationItem.id, nationItem);
}
return {
mapTheme: ref(mapTheme),
selectedGeneralID,
generalList,
nationList,
commandName,
textHelpGeneral,
submit,
};
},
});
</script>
+4
View File
@@ -1,9 +1,13 @@
import { default as che_건국} from "./che_건국.vue";
import { default as che_군량매매} from "./che_군량매매.vue";
import { default as che_등용} from "./che_등용.vue";
import { default as CityProcess} from "./che_이동.vue";
export const commandMap: Record<string, typeof CityProcess> = {
che_강행: CityProcess,
che_군량매매,
che_건국,
che_등용,
che_이동: CityProcess,
che_출병: CityProcess,
}
+64 -7
View File
@@ -5,6 +5,8 @@
:allow-empty="false"
:options="forFind"
:group-select="false"
:group-values="groupByNation ? 'values' : undefined"
group-label="nationID"
label="searchText"
track-by="value"
:show-labels="false"
@@ -18,7 +20,21 @@
:searchable="searchMode"
>
<template v-slot:option="props">
<div v-html="props.option.title"></div>
<div v-if="props.option.title" v-html="props.option.title"></div>
<div
v-if="props.option.$groupLabel !== undefined"
class="margin-filler"
:style="{
backgroundColor: groupByNation.get(props.option.$groupLabel).color,
color: isBrightColor(
groupByNation.get(props.option.$groupLabel).color
)
? 'black'
: 'white',
}"
>
{{ groupByNation.get(props.option.$groupLabel).name }}
</div>
</template>
<template v-slot:singleLabel="props">
{{ props.option.simpleName }}
@@ -29,10 +45,13 @@
import { getNpcColor } from "@/common_legacy";
import { automata초성All } from "@/util/automata초성";
import { filter초성withAlphabet } from "@/util/filter초성withAlphabet";
import { isBrightColor } from "@/util/isBrightColor";
import { unwrap } from "@/util/unwrap";
import { defineComponent, PropType } from "vue";
import {
procGeneralItem,
procGeneralList,
procNationItem,
} from "./processingRes";
type SelectedGeneral = {
@@ -58,6 +77,11 @@ export default defineComponent({
required: false,
default: undefined,
},
groupByNation: {
type: Map as PropType<Map<number, procNationItem>>,
required: false,
default: undefined,
},
},
emits: ["update:modelValue"],
watch: {
@@ -70,15 +94,41 @@ export default defineComponent({
},
},
data() {
const forFind = [];
const forFind: (
| SelectedGeneral
| {
values: SelectedGeneral[];
nationID: number;
}
)[] = [];
const forFindGroup = new Map<number, SelectedGeneral[]>();
const targets = new Map<number, SelectedGeneral>();
let selectedGeneral;
for (const gen of this.generals) {
let groupArray = forFind;
if (this.groupByNation) {
const nationID = gen.nationID ?? 0;
if (!forFindGroup.has(nationID)) {
const nationItem = unwrap(this.groupByNation.get(nationID));
let tmpArr: SelectedGeneral[] = [];
forFindGroup.set(nationID, tmpArr);
groupArray = tmpArr;
forFind.push({
nationID: nationItem.id,
values: tmpArr,
});
} else {
groupArray = unwrap(forFindGroup.get(nationID));
}
}
const nameColor = getNpcColor(gen.npc);
const name = nameColor?`<span style="color:${nameColor}">${gen.name}</span>`:gen.name;
const name = nameColor
? `<span style="color:${nameColor}">${gen.name}</span>`
: gen.name;
const [filteredTextH, filteredTextA] = filter초성withAlphabet(gen.name);
const [filteredTextHL1, filteredTextHL2] = automata초성All(filteredTextH);
@@ -86,9 +136,7 @@ export default defineComponent({
value: gen.no,
title: this.textHelper
? this.textHelper(gen)
: `${name} (${gen.leadership}/${gen.leadership}/${
gen.intel
})`,
: `${name} (${gen.leadership}/${gen.leadership}/${gen.intel})`,
simpleName: gen.name,
searchText: `${gen.name} ${filteredTextH} ${filteredTextA} ${filteredTextHL1} ${filteredTextHL2}`,
obj: gen,
@@ -96,14 +144,16 @@ export default defineComponent({
if (gen.no == this.modelValue) {
selectedGeneral = obj;
}
forFind.push(obj);
groupArray.push(obj);
targets.set(gen.no, obj);
}
console.log(forFind);
return {
selectedGeneral,
searchMode: true,
forFind,
targets,
isBrightColor,
};
},
});
@@ -128,5 +178,12 @@ export default defineComponent({
input {
color: $vue-multiselect-color;
}
.multiselect__option--group {
padding: 0;
}
.margin-filler {
padding: calc($vue-multiselect-padding-y + 0.17em) $vue-multiselect-padding-x;
}
}
</style>
+3 -3
View File
@@ -52,7 +52,7 @@ import BottomBar from "@/components/BottomBar.vue";
import {
convertGeneralList,
procGeneralItem,
procGeneralKeyList,
procGeneralKey,
procGeneralRawItemList,
procTroopList,
} from "../processingRes";
@@ -66,7 +66,7 @@ declare const procRes: {
cities: [number, string][];
troops: procTroopList;
generals: procGeneralRawItemList;
generalsKey: procGeneralKeyList;
generalsKey: procGeneralKey[];
};
export default defineComponent({
@@ -110,7 +110,7 @@ export default defineComponent({
const troops = (!gen.troopID)?'':`,${procRes.troops[gen.troopID].name}`;
const nameColor = getNpcColor(gen.npc);
const name = nameColor?`<span style="color:${nameColor}">${gen.name}</span>`:gen.name;
return `${name} [${citiesMap.get(gen.cityID)?.name}${troops}] (${gen.leadership}/${gen.leadership}/${gen.intel}) <병${gen.crew.toLocaleString()}/훈${gen.train}/사${gen.atmos}>`;
return `${name} [${citiesMap.get(unwrap(gen.cityID))?.name}${troops}] (${gen.leadership}/${gen.leadership}/${gen.intel}) <병${unwrap(gen.crew).toLocaleString()}/훈${gen.train}/사${gen.atmos}>`;
}
async function submit(e: Event) {
+11 -27
View File
@@ -3,42 +3,26 @@ import { combineArray } from "@/util/combineArray";
export type procGeneralItem = {
no: number,
name: string,
nationID?: number,
officerLevel: number,
npc: number,
gold: number,
rice: number,
gold?: number,
rice?: number,
leadership: number,
strength: number,
intel: number,
cityID: number,
crew: number,
train: number,
atmos: number,
troopID: number,
cityID?: number,
crew?: number,
train?: number,
atmos?: number,
troopID?: number,
}
export type procGeneralList = procGeneralItem[];
export type procGeneralKeyList = [
'no', 'name', 'officerLevel', 'npc', 'gold', 'rice', 'leadership', 'strength', 'intel', 'cityID', 'crew', 'train', 'atmos', 'troopID'
];
export type procGeneralKey = 'no'| 'name'| 'nationID' | 'officerLevel'| 'npc'| 'gold'| 'rice'| 'leadership'| 'strength'| 'intel'| 'cityID'| 'crew'| 'train'| 'atmos'| 'troopID';
export type procGeneralRawItem = [
procGeneralItem[procGeneralKeyList[0]],
procGeneralItem[procGeneralKeyList[1]],
procGeneralItem[procGeneralKeyList[2]],
procGeneralItem[procGeneralKeyList[3]],
procGeneralItem[procGeneralKeyList[4]],
procGeneralItem[procGeneralKeyList[5]],
procGeneralItem[procGeneralKeyList[6]],
procGeneralItem[procGeneralKeyList[7]],
procGeneralItem[procGeneralKeyList[8]],
procGeneralItem[procGeneralKeyList[9]],
procGeneralItem[procGeneralKeyList[10]],
procGeneralItem[procGeneralKeyList[11]],
procGeneralItem[procGeneralKeyList[12]],
procGeneralItem[procGeneralKeyList[13]],
];
export type procGeneralRawItem = procGeneralItem[procGeneralKey][];
export type procTroopItem = {
troop_leader: number,
@@ -49,7 +33,7 @@ export type procTroopList = Record<number, procTroopItem>;
export type procGeneralRawItemList = procGeneralRawItem[];
export function convertGeneralList(keys: procGeneralKeyList, rawList: procGeneralRawItemList): procGeneralList{
export function convertGeneralList(keys: procGeneralKey[], rawList: procGeneralRawItemList): procGeneralList{
return combineArray(rawList, keys) as procGeneralList;
}