Skip to content

Commit

Permalink
battle base info
Browse files Browse the repository at this point in the history
  • Loading branch information
huww98 committed Dec 31, 2023
1 parent 35431e3 commit bf4831a
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 9 deletions.
75 changes: 74 additions & 1 deletion src/blueprint/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,78 @@ function storageParamParser(size: number): ParamParser<StorageParameters>{
}
}

export enum BattleBaseDroneConstructPriority {
REPARE = 0,
BALANCE = 1,
CONSTRUCT = 2,
}
export interface Fighter {
itemId: number;
}
export interface BattleBaseParameters extends StorageParameters {
workEnergyPerTick: number;
autoPickEnabled: boolean;
autoReplenishFleet: boolean;
combatEnabled: boolean;
autoReconstruct: boolean;
constructionDroneEnabled: boolean;
droneConstructPriority: BattleBaseDroneConstructPriority;
fighters: Fighter[];
}

function battleBaseParamParser(): ParamParser<BattleBaseParameters> {
const storageParser = storageParamParser(60);
const getBase = (p: StorageParameters) => {
switch (p.type) {
case StorageType.DEFAULT:
return 10;
case StorageType.FILTERED:
return 10 + 60;
default:
throw new Error('参数解析错误:未知的储存类型');
}
}
return {
encodedSize() {
return 110;
},
encode(p, a) {
storageParser.encode(p, a);
const base = getBase(p);
setParam(a, base + 0, p.workEnergyPerTick);
setParam(a, base + 1, p.autoPickEnabled ? 1 : 0);
setParam(a, base + 2, p.autoReplenishFleet ? 1 : 0);
setParam(a, base + 3, p.combatEnabled ? 1 : 0);
setParam(a, base + 4, p.autoReconstruct ? 1 : 0);
setParam(a, base + 5, p.constructionDroneEnabled ? 1 : 0);
setParam(a, base + 6, p.droneConstructPriority);
for (let i = 0; i < p.fighters.length; i++) {
setParam(a, base + 7 + i, p.fighters[i].itemId);
}
},
decode(a) {
const p = storageParser.decode(a);
const base = getBase(p);
const fighters: Fighter[] = [];
for (let i = 0; i < 12; i++) {
fighters.push({
itemId: getParam(a, base + 7 + i),
});
}
return Object.assign(p, {
workEnergyPerTick: getParam(a, base + 0),
autoPickEnabled: getParam(a, base + 1) > 0,
autoReplenishFleet: getParam(a, base + 2) > 0,
combatEnabled: getParam(a, base + 3) > 0,
autoReconstruct: getParam(a, base + 4) > 0,
constructionDroneEnabled: getParam(a, base + 5) > 0,
droneConstructPriority: getParam(a, base + 6),
fighters,
});
},
}
}

export interface EjectorParameters {
orbitId: number;
boost: boolean;
Expand Down Expand Up @@ -650,7 +722,7 @@ type AllParameters = AssembleParamerters | StationParameters | AdvancedMiningMac
SplitterParameters | LabParamerters | BeltParameters | InserterParameters |
TankParameters | StorageParameters | EjectorParameters |
PowerGeneratorParameters | ArtifacialStarParameters | EnergyExchangerParameters |
MonitorParameters | UnknownParamerters;
MonitorParameters | BattleBaseParameters | UnknownParamerters;

const parameterParsers = new Map<number, ParamParser<AllParameters>>([
[2103, stationParamsParser(stationDesc)],
Expand All @@ -672,6 +744,7 @@ const parameterParsers = new Map<number, ParamParser<AllParameters>>([
[2210, artifacialStarParamParser],
[2209, energyExchangerParamParser],
[2030, MonitorParamParser],
[3009, battleBaseParamParser()],
]);
for (const id of allAssemblers) {
parameterParsers.set(id, assembleParamParser);
Expand Down
79 changes: 79 additions & 0 deletions src/components/BattleBaseInfo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<template>
<div class="building-params">
<div>
<label>{{ t('基站自动拾取提示标题') }}</label>
<span class="v">{{ truth(p.autoPickEnabled) }}</span>
</div>
<div>
<label>{{ t('基站自动重建提示标题') }}</label>
<span class="v">{{ truth(p.autoReconstruct) }}</span>
</div>
<div>
<label>{{ t('基站建设无人机提示标题') }}</label>
<span class="v">{{ p.constructionDroneEnabled ? constructionPriority : truth(false) }}</span>
</div>
<div>
<label>{{ t('基站战斗机提示标题') }}</label>
<span class="v">{{ truth(p.combatEnabled) }}</span>
</div>
<div>
<div class="fleet-grid">
<BuildingIcon v-for="(f, i) in p.fighters" :key="i" :icon-id="itemIconId(f.itemId)" />
</div>
</div>
<div>
<label>{{ t('基站自动补充编队提示标题') }}</label>
<span class="v">{{ truth(p.autoReplenishFleet) }}</span>
</div>
<div>
<label>{{ t('最大充能功率') }}</label>
<span class="v">{{(p.workEnergyPerTick * 60 / 1_000_000).toLocaleString([], { minimumSignificantDigits: 3, maximumSignificantDigits: 3 })}} MW</span>
</div>
</div>
</template>

<script lang="ts" setup>
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { BattleBaseParameters, BlueprintBuilding, BattleBaseDroneConstructPriority } from '@/blueprint/parser';
import BuildingIcon from './BuildingIcon.vue';
import { itemIconId } from '@/data/icons';
import { truth } from '@/utils';
const { t } = useI18n();
const props = defineProps<{
building: BlueprintBuilding,
}>();
const p = computed(() => props.building.parameters as BattleBaseParameters);
const constructionPriority = computed(() => {
switch (p.value.droneConstructPriority) {
case BattleBaseDroneConstructPriority.REPARE:
return t('建设机优先修理标题');
case BattleBaseDroneConstructPriority.BALANCE:
return t('建设机均衡模式标题');
case BattleBaseDroneConstructPriority.CONSTRUCT:
return t('建设机优先建造标题');
default:
return '??';
}
});
</script>

<style lang="scss">
.fleet-grid {
display: grid;
grid-template-columns: repeat(6, 1fr);
grid-template-rows: repeat(2, 1fr);
gap: 2px;
grid-auto-flow: column;
.icon {
display: block;
padding: 2px;
background: #FFFFFF40;
}
}
</style>
4 changes: 3 additions & 1 deletion src/components/BuildingInfoPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<SplitterInfo v-if="isSplitter(building.itemId)" :building="building" />
<StationInfo v-if="isStation(building.itemId)" :building="building" />
<MonitorInfo v-if="isMonitor(building.itemId)" :building="building" />
<BattleBaseInfo v-if="isBattleBase(building.itemId)" :building="building" />
<StorageInfo v-if="isStorage(building.itemId)" :building="building" />
<div class="building-params">
<div v-if="filterItem">
Expand Down Expand Up @@ -89,14 +90,15 @@ import {
import { itemIconId } from '@/data/icons';
import {
isLab, allAssemblers, isBelt, isStation, itemsMap, isInserter, isStorage, isTank,
isEjector, isEnergyExchanger, isArtificialStar, isRayReciver, isMonitor, isSplitter
isEjector, isEnergyExchanger, isArtificialStar, isRayReciver, isMonitor, isSplitter, isBattleBase,
} from '@/data/items';
import { commandQueueKey } from '@/define';
import BuildingRecipe from './BuildingRecipe.vue';
import BuildingIcon from './BuildingIcon.vue';
import StationInfo from './StationInfo.vue';
import MonitorInfo from './MonitorInfo.vue';
import BattleBaseInfo from './BattleBaseInfo.vue';
import StorageInfo from './StorageInfo.vue';
import SwitchDSP from './SwitchDSP.vue';
const SplitterInfo = defineAsyncComponent(() => import(/* webpackChunkName: "renderer" */'./SpitterInfo.vue'));
Expand Down
9 changes: 3 additions & 6 deletions src/components/StorageInfo.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<template>
<div v-if="p.type === StorageType.FILTERED" class="storage-grid" :class="'capacity-' + capacity">
<template v-for="(g, i) in p.grids" :key="i" >
<div :class="{ban: i >= capacityForAutomation}">
<BuildingIcon v-if="g.filter > 0" :icon-id="itemIconId(g.filter)" />
</div>
</template>
<div v-for="(g, i) in p.grids" :key="i" :class="{ban: i >= capacityForAutomation}">
<BuildingIcon v-if="g.filter > 0" :icon-id="itemIconId(g.filter)" />
</div>
</div>
<div class="building-params">
<div>
Expand Down Expand Up @@ -58,7 +56,6 @@ const capacityForAutomation = computed(() => {
.icon {
display: block;
width: 100%;
}
}
</style>
8 changes: 7 additions & 1 deletion src/data/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function isLab(id: number) {
}

export function isStorage(id: number) {
return id === 2101 || id === 2102;
return id === 2101 || id === 2102 || id === 3009;
}

export function isTank(id: number) {
Expand Down Expand Up @@ -63,12 +63,18 @@ export function isMonitor(id: number) {
return id === 2030;
}

export function isBattleBase(id: number) {
return id === 3009;
}

export const allAssemblers = new Set([
2303, // 制造台
2304,
2305,
2318,
2302, // 熔炉
2315,
2319,
2308, // 原油精炼厂
2309, // 化工厂
2310, // 对撞机
Expand Down
8 changes: 8 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,19 @@
"吉他": "Guitar",
"周期秒": " seconds",
"图标布局": "Icon Layout",
"基站建设无人机提示标题": "Construction Drone",
"基站战斗机提示标题": "Combat Drone",
"基站自动拾取提示标题": "Auto Pickup",
"基站自动补充编队提示标题": "Auto Fleet Replenishment",
"基站自动重建提示标题": "Auto Reconstruction Marking",
"增产剂效果简": "Proliferator effect",
"声音警报": "Speaker alarm",
"小号": "Trumpet",
"小提琴": "Violin",
"建筑公式": "Buildings",
"建设机优先修理标题": "Prioritize Repair",
"建设机优先建造标题": "Prioritize Construction",
"建设机均衡模式标题": "Balanced",
"当前货物数": "Current",
"待机": "Idle",
"循环播放": " Loop",
Expand Down
8 changes: 8 additions & 0 deletions src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,19 @@
"吉他": "吉他",
"周期秒": "",
"图标布局": "图标布局",
"基站建设无人机提示标题": "建设无人机",
"基站战斗机提示标题": "战斗无人机",
"基站自动拾取提示标题": "自动拾取",
"基站自动补充编队提示标题": "自动补充编队",
"基站自动重建提示标题": "自动标记重建",
"增产剂效果简": "增产效果",
"声音警报": "声音警报",
"小号": "小号",
"小提琴": "小提琴",
"建筑公式": "建筑",
"建设机优先修理标题": "优先修理",
"建设机优先建造标题": "优先建造",
"建设机均衡模式标题": "均衡模式",
"当前货物数": "当前",
"待机": "待机",
"循环播放": "循环",
Expand Down

0 comments on commit bf4831a

Please sign in to comment.