Some falukant fixes, added undeground ui - no save right now, changed menu (and verification)

This commit is contained in:
Torsten Schulz
2025-07-17 14:28:52 +02:00
parent fceea5b7fb
commit 89cf12a7a8
33 changed files with 1010 additions and 423 deletions

View File

@@ -1,291 +1,271 @@
<template>
<div class="contenthidden">
<StatusBar ref="statusBar" />
<div class="contentscroll">
<h2>{{ $t('falukant.branch.title') }}</h2>
<BranchSelection
:branches="branches"
:selectedBranch="selectedBranch"
@branchSelected="onBranchSelected"
@createBranch="createBranch"
@upgradeBranch="upgradeBranch"
ref="branchSelection"
/>
<DirectorInfo
v-if="selectedBranch"
:branchId="selectedBranch.id"
ref="directorInfo"
/>
<SaleSection
v-if="selectedBranch"
:branchId="selectedBranch.id"
ref="saleSection"
/>
<ProductionSection
v-if="selectedBranch"
:branchId="selectedBranch.id"
:products="products"
ref="productionSection"
/>
<StorageSection
v-if="selectedBranch"
:branchId="selectedBranch.id"
ref="storageSection"
/>
<RevenueSection
v-if="selectedBranch"
:products="products"
:calculateProductRevenue="calculateProductRevenue"
:calculateProductProfit="calculateProductProfit"
ref="revenueSection"
/>
</div>
<StatusBar ref="statusBar" />
<div class="contentscroll">
<h2>{{ $t('falukant.branch.title') }}</h2>
<BranchSelection :branches="branches" :selectedBranch="selectedBranch" @branchSelected="onBranchSelected"
@createBranch="createBranch" @upgradeBranch="upgradeBranch" ref="branchSelection" />
<DirectorInfo v-if="selectedBranch" :branchId="selectedBranch.id" ref="directorInfo" />
<SaleSection v-if="selectedBranch" :branchId="selectedBranch.id" ref="saleSection" />
<ProductionSection v-if="selectedBranch" :branchId="selectedBranch.id" :products="products"
ref="productionSection" />
<StorageSection v-if="selectedBranch" :branchId="selectedBranch.id" ref="storageSection" />
<RevenueSection v-if="selectedBranch" :products="products"
:calculateProductRevenue="calculateProductRevenue" :calculateProductProfit="calculateProductProfit"
ref="revenueSection" />
</div>
</div>
</template>
<script>
import StatusBar from '@/components/falukant/StatusBar.vue';
import BranchSelection from '@/components/falukant/BranchSelection.vue';
import DirectorInfo from '@/components/falukant/DirectorInfo.vue';
import SaleSection from '@/components/falukant/SaleSection.vue';
import ProductionSection from '@/components/falukant/ProductionSection.vue';
import StorageSection from '@/components/falukant/StorageSection.vue';
import RevenueSection from '@/components/falukant/RevenueSection.vue';
import apiClient from '@/utils/axios.js';
import { mapState } from 'vuex';
export default {
</template>
<script>
import StatusBar from '@/components/falukant/StatusBar.vue';
import BranchSelection from '@/components/falukant/BranchSelection.vue';
import DirectorInfo from '@/components/falukant/DirectorInfo.vue';
import SaleSection from '@/components/falukant/SaleSection.vue';
import ProductionSection from '@/components/falukant/ProductionSection.vue';
import StorageSection from '@/components/falukant/StorageSection.vue';
import RevenueSection from '@/components/falukant/RevenueSection.vue';
import apiClient from '@/utils/axios.js';
import { mapState } from 'vuex';
export default {
name: "BranchView",
components: {
StatusBar,
BranchSelection,
DirectorInfo,
SaleSection,
ProductionSection,
StorageSection,
RevenueSection,
StatusBar,
BranchSelection,
DirectorInfo,
SaleSection,
ProductionSection,
StorageSection,
RevenueSection,
},
data() {
return {
branches: [],
selectedBranch: null,
products: [],
};
return {
branches: [],
selectedBranch: null,
products: [],
};
},
computed: {
...mapState(['socket', 'daemonSocket']),
...mapState(['socket', 'daemonSocket']),
},
async mounted() {
await this.loadBranches();
const branchId = this.$route.params.branchId;
await this.loadProducts();
if (branchId) {
this.selectedBranch = this.branches.find(
b => b.id === parseInt(branchId, 10)
) || null;
} else {
this.selectMainBranch();
}
// Daemon-Socket
if (this.daemonSocket) {
this.daemonSocket.addEventListener('message', this.handleDaemonMessage);
}
// Live-Socket-Events
[
"production_ready",
"stock_change",
"price_update",
"director_death",
"production_started",
"selled_items",
"falukantUpdateStatus",
"falukantBranchUpdate",
"knowledge_update"
].forEach(eventName => {
if (this.socket) {
this.socket.on(eventName, data => this.handleEvent({ event: eventName, ...data }));
}
});
},
beforeUnmount() {
[
"production_ready",
"stock_change",
"price_update",
"director_death",
"production_started",
"selled_items",
"falukantUpdateStatus",
"falukantBranchUpdate",
"knowledge_update"
].forEach(eventName => {
if (this.socket) {
this.socket.off(eventName, this.handleEvent);
}
});
if (this.daemonSocket) {
this.daemonSocket.removeEventListener('message', this.handleDaemonMessage);
}
},
methods: {
async loadBranches() {
try {
const result = await apiClient.get('/api/falukant/branches');
this.branches = result.data.map(branch => ({
id: branch.id,
cityName: branch.region.name,
type: this.$t(`falukant.branch.types.${branch.branchType.labelTr}`),
isMainBranch: branch.isMainBranch,
}));
if (!this.selectedBranch) {
this.selectMainBranch();
}
} catch (error) {
console.error('Error loading branches:', error);
}
},
async loadProducts() {
try {
const productsResult = await apiClient.get('/api/falukant/products');
this.products = productsResult.data;
} catch (error) {
console.error('Error loading products:', error);
}
},
onBranchSelected(newBranch) {
this.selectedBranch = newBranch;
},
async createBranch() {
// Nach erfolgreichem Dialog-Event: neu laden
await this.loadBranches();
},
upgradeBranch() {
if (this.selectedBranch) {
alert(
this.$t(
'falukant.branch.actions.upgradeAlert',
{ branchId: this.selectedBranch.id }
)
);
const branchId = this.$route.params.branchId;
await this.loadProducts();
if (branchId) {
this.selectedBranch = this.branches.find(
b => b.id === parseInt(branchId, 10)
) || null;
} else {
this.selectMainBranch();
}
},
selectMainBranch() {
const main = this.branches.find(b => b.isMainBranch) || null;
if (main && main !== this.selectedBranch) {
this.selectedBranch = main;
// Daemon-Socket
if (this.daemonSocket) {
this.daemonSocket.addEventListener('message', this.handleDaemonMessage);
}
},
calculateProductRevenue(product) {
if (!product.knowledges || product.knowledges.length === 0) {
return { absolute: 0, perMinute: 0 };
}
const knowledgeFactor = product.knowledges[0].knowledge || 0;
const maxPrice = product.sellCost;
const minPrice = maxPrice * 0.6;
const revenuePerUnit = minPrice + (maxPrice - minPrice) * (knowledgeFactor / 100);
const perMinute = product.productionTime > 0
? revenuePerUnit / product.productionTime
: 0;
return {
absolute: revenuePerUnit.toFixed(2),
perMinute: perMinute.toFixed(2),
};
},
calculateProductProfit(product) {
const { absolute: revenueAbsoluteStr, perMinute: revenuePerMinuteStr }
= this.calculateProductRevenue(product);
const revenueAbsolute = parseFloat(revenueAbsoluteStr);
const costPerUnit = 6 * product.category;
const profitAbsolute = revenueAbsolute - costPerUnit;
const costPerMinute = product.productionTime > 0
? costPerUnit / product.productionTime
: 0;
const profitPerMinute = parseFloat(revenuePerMinuteStr) - costPerMinute;
return {
absolute: profitAbsolute.toFixed(2),
perMinute: profitPerMinute.toFixed(2),
};
},
handleEvent(eventData) {
switch (eventData.event) {
case 'production_ready':
this.$refs.productionSection?.loadProductions();
this.$refs.storageSection ?.loadStorageData();
this.$refs.saleSection ?.loadInventory();
break;
case 'stock_change':
this.$refs.storageSection ?.loadStorageData();
this.$refs.saleSection ?.loadInventory();
break;
case 'price_update':
this.$refs.revenueSection?.refresh();
break;
case 'director_death':
this.$refs.directorInfo?.loadDirector();
break;
case 'production_started':
this.$refs.productionSection?.loadProductions();
break;
case 'selled_items':
this.$refs.saleSection ?.loadInventory();
this.$refs.storageSection?.loadStorageData();
break;
case 'falukantUpdateStatus':
case 'falukantBranchUpdate':
this.$refs.statusBar?.fetchStatus();
this.$refs.productionSection?.loadProductions();
this.$refs.storageSection ?.loadStorageData();
this.$refs.saleSection ?.loadInventory();
break;
case 'knowledge_update':
this.loadProducts();
this.$refs.revenueSection.products = this.products;
break;
default:
console.log('Unhandled event:', eventData);
}
},
handleDaemonMessage(event) {
if (event.data === 'ping') return;
try {
const message = JSON.parse(event.data);
this.handleEvent(message);
} catch (error) {
console.error('Error processing daemon message:', error);
}
},
// Live-Socket-Events
[
"production_ready",
"stock_change",
"price_update",
"director_death",
"production_started",
"selled_items",
"falukantUpdateStatus",
"falukantBranchUpdate",
"knowledge_update"
].forEach(eventName => {
if (this.socket) {
this.socket.on(eventName, data => this.handleEvent({ event: eventName, ...data }));
}
});
},
};
</script>
<style scoped lang="scss">
h2 {
beforeUnmount() {
[
"production_ready",
"stock_change",
"price_update",
"director_death",
"production_started",
"selled_items",
"falukantUpdateStatus",
"falukantBranchUpdate",
"knowledge_update"
].forEach(eventName => {
if (this.socket) {
this.socket.off(eventName, this.handleEvent);
}
});
if (this.daemonSocket) {
this.daemonSocket.removeEventListener('message', this.handleDaemonMessage);
}
},
methods: {
async loadBranches() {
try {
const result = await apiClient.get('/api/falukant/branches');
this.branches = result.data.map(branch => ({
id: branch.id,
cityName: branch.region.name,
type: this.$t(`falukant.branch.types.${branch.branchType.labelTr}`),
isMainBranch: branch.isMainBranch,
}));
if (!this.selectedBranch) {
this.selectMainBranch();
}
} catch (error) {
console.error('Error loading branches:', error);
}
},
async loadProducts() {
try {
const productsResult = await apiClient.get('/api/falukant/products');
this.products = productsResult.data;
} catch (error) {
console.error('Error loading products:', error);
}
},
async onBranchSelected(newBranch) {
this.selectedBranch = newBranch;
await this.loadProducts();
this.$nextTick(() => {
this.$refs.directorInfo?.refresh();
this.$refs.saleSection?.loadInventory();
this.$refs.productionSection?.loadProductions();
this.$refs.storageSection?.loadStorageData();
this.$refs.revenueSection?.refresh && this.$refs.revenueSection.refresh();
});
},
async createBranch() {
await this.loadBranches();
},
upgradeBranch() {
if (this.selectedBranch) {
alert(
this.$t(
'falukant.branch.actions.upgradeAlert',
{ branchId: this.selectedBranch.id }
)
);
}
},
selectMainBranch() {
const main = this.branches.find(b => b.isMainBranch) || null;
if (main && main !== this.selectedBranch) {
this.selectedBranch = main;
}
},
calculateProductRevenue(product) {
if (!product.knowledges || product.knowledges.length === 0) {
return { absolute: 0, perMinute: 0 };
}
const knowledgeFactor = product.knowledges[0].knowledge || 0;
const maxPrice = product.sellCost;
const minPrice = maxPrice * 0.6;
const revenuePerUnit = minPrice + (maxPrice - minPrice) * (knowledgeFactor / 100);
const perMinute = product.productionTime > 0
? revenuePerUnit / product.productionTime
: 0;
return {
absolute: revenuePerUnit.toFixed(2),
perMinute: perMinute.toFixed(2),
};
},
calculateProductProfit(product) {
const { absolute: revenueAbsoluteStr, perMinute: revenuePerMinuteStr }
= this.calculateProductRevenue(product);
const revenueAbsolute = parseFloat(revenueAbsoluteStr);
const costPerUnit = 6 * product.category;
const profitAbsolute = revenueAbsolute - costPerUnit;
const costPerMinute = product.productionTime > 0
? costPerUnit / product.productionTime
: 0;
const profitPerMinute = parseFloat(revenuePerMinuteStr) - costPerMinute;
return {
absolute: profitAbsolute.toFixed(2),
perMinute: profitPerMinute.toFixed(2),
};
},
handleEvent(eventData) {
switch (eventData.event) {
case 'production_ready':
this.$refs.productionSection?.loadProductions();
this.$refs.storageSection?.loadStorageData();
this.$refs.saleSection?.loadInventory();
break;
case 'stock_change':
this.$refs.storageSection?.loadStorageData();
this.$refs.saleSection?.loadInventory();
break;
case 'price_update':
this.$refs.revenueSection?.refresh();
break;
case 'director_death':
this.$refs.directorInfo?.loadDirector();
break;
case 'production_started':
this.$refs.productionSection?.loadProductions();
break;
case 'selled_items':
this.$refs.saleSection?.loadInventory();
this.$refs.storageSection?.loadStorageData();
break;
case 'falukantUpdateStatus':
case 'falukantBranchUpdate':
this.$refs.statusBar?.fetchStatus();
this.$refs.productionSection?.loadProductions();
this.$refs.storageSection?.loadStorageData();
this.$refs.saleSection?.loadInventory();
break;
case 'knowledge_update':
this.loadProducts();
this.$refs.revenueSection.products = this.products;
break;
default:
console.log('Unhandled event:', eventData);
}
},
handleDaemonMessage(event) {
if (event.data === 'ping') return;
try {
const message = JSON.parse(event.data);
this.handleEvent(message);
} catch (error) {
console.error('Error processing daemon message:', error);
}
},
},
};
</script>
<style scoped lang="scss">
h2 {
padding-top: 20px;
}
</style>
}
</style>

View File

@@ -101,7 +101,7 @@ export default {
try {
const { data } = await apiClient.get('/api/falukant/health');
this.age = data.age;
this.healthStatus = data.status;
this.healthStatus = data.health;
this.measuresTaken = data.history;
this.availableMeasures = data.healthActivities;
} catch (err) {

View File

@@ -0,0 +1,343 @@
<template>
<div class="underground-view">
<StatusBar />
<h2>{{ $t('falukant.underground.title') }}</h2>
<SimpleTabs v-model="activeTab" :tabs="tabs" @change="onTabChange" />
<div class="tab-content">
<!-- Aktivitäten -->
<div v-if="activeTab === 'activities'" class="tab-pane">
<!-- Neues Activity-Formular -->
<div class="create-activity">
<h3>{{ $t('falukant.underground.activities.create') }}</h3>
<label class="form-label">
{{ $t('falukant.underground.activities.type') }}
<select v-model="newActivityTypeId" class="form-control">
<option v-for="type in undergroundTypes" :key="type.id" :value="type.id">
{{ $t(`falukant.underground.types.${type.tr}`) }}
({{ formatCost(type.cost) }})
</option>
</select>
</label>
<label class="form-label">
{{ $t('falukant.underground.activities.victim') }}
<input v-model="newVictimUsername" type="text" class="form-control"
:placeholder="$t('falukant.underground.activities.victimPlaceholder')" />
</label>
<!-- Bei sabotage: Ziel auswählen -->
<label v-if="selectedType && selectedType.tr === 'sabotage'" class="form-label">
{{ $t('falukant.underground.activities.sabotageTarget') }}
<select v-model="newSabotageTarget" class="form-control">
<option value="house">{{ $t('falukant.underground.targets.house') }}</option>
<option value="storage">{{ $t('falukant.underground.targets.storage') }}</option>
</select>
</label>
<!-- Bei corrupt_politician: Ziel erreichen -->
<label v-if="selectedType && selectedType.tr === 'corrupt_politician'" class="form-label">
{{ $t('falukant.underground.activities.corruptGoal') }}
<select v-model="newCorruptGoal" class="form-control">
<option value="elect">{{ $t('falukant.underground.goals.elect') }}</option>
<option value="tax_increase">{{ $t('falukant.underground.goals.taxIncrease') }}</option>
<option value="tax_decrease">{{ $t('falukant.underground.goals.taxDecrease') }}</option>
</select>
</label>
<button class="btn-create-activity" :disabled="!canCreate" @click="createActivity">
{{ $t('falukant.underground.activities.create') }}
</button>
</div>
<!-- /Neues Activity-Formular -->
<div v-if="loading.activities" class="loading">
{{ $t('loading') }}
</div>
<div v-else class="activities-table">
<table>
<thead>
<tr>
<th>{{ $t('falukant.underground.activities.type') }}</th>
<th>{{ $t('falukant.underground.activities.victim') }}</th>
<th>{{ $t('falukant.underground.activities.cost') }}</th>
<th>{{ $t('falukant.underground.activities.additionalInfo') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="act in activities" :key="act.id">
<!-- Typ -->
<td>{{ $t(`falukant.underground.types.${act.type}`) }}</td>
<!-- Victim -->
<td>{{ act.victimName }}</td>
<!-- Cost -->
<td>{{ formatCost(act.cost) }}</td>
<!-- Zusätzliche Informationen -->
<td>
<template v-if="act.type === 'sabotage'">
{{ $t(`falukant.underground.targets.${act.target}`) }}
</template>
<template v-else-if="act.type === 'corrupt_politician'">
{{ $t(`falukant.underground.goals.${act.goal}`) }}
</template>
</td>
</tr>
<tr v-if="!activities.length">
<td colspan="4">{{ $t('falukant.underground.activities.none') }}</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Angriffe -->
<div v-else-if="activeTab === 'attacks'" class="tab-pane">
<div v-if="loading.attacks" class="loading">
{{ $t('loading') }}
</div>
<div v-else class="attacks-list">
<table>
<thead>
<tr>
<th>{{ $t('falukant.underground.attacks.source') }}</th>
<th>{{ $t('falukant.underground.attacks.date') }}</th>
<th>{{ $t('falukant.underground.attacks.success') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="atk in attacks" :key="atk.id">
<td>{{ atk.targetName }}</td>
<td>{{ formatDate(atk.date) }}</td>
<td>{{ atk.success ? $t('yes') : $t('no') }}</td>
</tr>
<tr v-if="!attacks.length">
<td colspan="3">
{{ $t('falukant.underground.attacks.none') }}
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</template>
<script>
import StatusBar from '@/components/falukant/StatusBar.vue';
import SimpleTabs from '@/components/SimpleTabs.vue';
import apiClient from '@/utils/axios.js';
export default {
name: 'UndergroundView',
components: { StatusBar, SimpleTabs },
data() {
return {
activeTab: 'activities',
tabs: [
{ value: 'activities', label: 'falukant.underground.tabs.activities' },
{ value: 'attacks', label: 'falukant.underground.tabs.attacks' }
],
undergroundTypes: [],
activities: [],
attacks: [],
loading: { activities: false, attacks: false },
// Neue Activity-Formfelder
newActivityTypeId: null,
newVictimUsername: '',
newSabotageTarget: 'house',
newCorruptGoal: 'elect'
};
},
computed: {
selectedType() {
return this.undergroundTypes.find(t => t.id === this.newActivityTypeId) || null;
},
canCreate() {
if (!this.newActivityTypeId || !this.newVictimUsername.trim()) return false;
if (this.selectedType.tr === 'sabotage' && !this.newSabotageTarget) return false;
if (this.selectedType.tr === 'corrupt_politician' && !this.newCorruptGoal) return false;
return true;
}
},
async mounted() {
await this.loadUndergroundTypes();
if (this.undergroundTypes.length) {
this.newActivityTypeId = this.undergroundTypes[0].id;
}
await this.loadActivities();
},
methods: {
onTabChange(tab) {
if (tab === 'activities' && !this.activities.length) {
this.loadActivities();
}
if (tab === 'attacks' && !this.attacks.length) {
this.loadAttacks();
}
},
async loadUndergroundTypes() {
const { data } = await apiClient.get('/api/falukant/underground/types');
this.undergroundTypes = data;
},
async loadActivities() {
this.loading.activities = true;
try {
const { data } = await apiClient.get('/api/falukant/underground/activities');
this.activities = data;
} catch (err) {
console.error('Error loading activities', err);
} finally {
this.loading.activities = false;
}
},
async loadAttacks() {
this.loading.attacks = true;
try {
const { data } = await apiClient.get('/api/falukant/underground/attacks');
this.attacks = data;
} catch (err) {
console.error('Error loading attacks', err);
} finally {
this.loading.attacks = false;
}
},
async createActivity() {
if (!this.canCreate) return;
const payload = {
typeId: this.newActivityTypeId,
victimUsername: this.newVictimUsername.trim()
};
// je nach Typ noch ergänzen:
if (this.selectedType.tr === 'sabotage') {
payload.target = this.newSabotageTarget;
}
if (this.selectedType.tr === 'corrupt_politician') {
payload.goal = this.newCorruptGoal;
}
try {
await apiClient.post('/api/falukant/underground/activities', payload);
// zurücksetzen & neu laden
this.newVictimUsername = '';
this.newSabotageTarget = 'house';
this.newCorruptGoal = 'elect';
await this.loadActivities();
} catch (err) {
console.error('Error creating activity', err);
}
},
formatDate(ts) {
return new Date(ts).toLocaleDateString(this.$i18n.locale, {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
});
},
formatCost(value) {
return new Intl.NumberFormat(navigator.language, {
minimumFractionDigits: 0,
maximumFractionDigits: 0
}).format(value);
}
}
};
</script>
<style scoped>
.underground-view {
display: flex;
flex-direction: column;
}
h2 {
padding-top: 20px;
}
.tab-content {
margin-top: 1rem;
}
.tab-pane {
min-height: 200px;
}
.loading {
font-style: italic;
text-align: center;
margin: 1em 0;
}
/* --- Create Activity --- */
.create-activity {
border: 1px solid #ccc;
padding: 1rem;
margin-bottom: 1rem;
border-radius: 4px;
background: #fafafa;
display: inline-block;
}
.create-activity h3 {
margin-top: 0;
}
.form-label {
display: block;
margin-bottom: 0.5rem;
font-weight: bold;
}
.form-control {
display: block;
width: 100%;
padding: 0.4rem;
margin-bottom: 1rem;
border: 1px solid #ccc;
border-radius: 4px;
}
.btn-create-activity {
padding: 0.5rem 1rem;
cursor: pointer;
background: #4caf50;
color: white;
border: none;
border-radius: 4px;
}
.btn-create-activity:disabled {
background: #ccc;
cursor: not-allowed;
}
/* --- Activities List --- */
.activities-list ul {
list-style: disc;
margin-left: 1.5em;
}
/* --- Attacks Table --- */
.attacks-list table {
width: 100%;
border-collapse: collapse;
}
.attacks-list th,
.attacks-list td {
padding: 8px;
border: 1px solid #ddd;
text-align: left;
}
</style>