Implemented houses

This commit is contained in:
Torsten Schulz
2025-05-08 17:38:51 +02:00
parent b15d93a798
commit a9e6c82275
17 changed files with 1129 additions and 156 deletions

View File

@@ -3,31 +3,50 @@
<StatusBar />
<div class="contentscroll">
<!-- Titel -->
<h2>{{ $t('falukant.family.title') }}</h2>
<!-- Ehepartner -->
<div class="spouse-section">
<h3>{{ $t('falukant.family.spouse.title') }}</h3>
<div v-if="relationships.length > 0">
<table>
<tr>
<td>{{ $t('falukant.family.relationships.name') }}</td>
<td>
{{ $t('falukant.titles.' + relationships[0].character2.gender + '.' +
relationships[0].character2.nobleTitle) }}
{{ relationships[0].character2.firstName }}
</td>
</tr>
<tr>
<td>{{ $t('falukant.family.spouse.age') }}</td>
<td>{{ relationships[0].character2.age }}</td>
</tr>
<tr>
<td>{{ $t('falukant.family.spouse.status') }}</td>
<td>{{ $t('falukant.family.statuses.' + relationships[0].relationshipType) }}</td>
</tr>
</table>
<div class="relationship">
<table>
<tr>
<td>{{ $t('falukant.family.relationships.name') }}</td>
<td>
{{ $t('falukant.titles.' + relationships[0].character2.gender + '.' +
relationships[0].character2.nobleTitle) }}
{{ relationships[0].character2.firstName }}
</td>
</tr>
<tr>
<td>{{ $t('falukant.family.spouse.age') }}</td>
<td>{{ relationships[0].character2.age }}</td>
</tr>
<tr>
<td>{{ $t('falukant.family.spouse.mood') }}</td>
<td>{{ $t(`falukant.mood.${relationships[0].character2.mood.tr}`) }}</td>
</tr>
<tr>
<td>{{ $t('falukant.family.spouse.status') }}</td>
<td>{{ $t('falukant.family.statuses.' + relationships[0].relationshipType) }}</td>
</tr>
<tr v-if="relationships[0].relationshipType === 'wooing'">
<td>{{ $t('falukant.family.spouse.progress') }}</td>
<td>
<div class="progress">
<div class="progress-inner" :style="{
width: relationships[0].progress + '%',
backgroundColor: progressColor(relationships[0].progress)
}"></div>
</div>
</td>
</tr>
</table>
<ul>
<li v-for="characteristic in relationships[0].character2.characterTrait"
:key="characteristic.id">{{ $t(`falukant.character.${characteristic.tr}`) }}</li>
</ul>
</div>
<div v-if="relationships[0].relationshipType === 'wooing'">
<h3>{{ $t('falukant.family.spouse.wooing.gifts') }}</h3>
<table class="spouse-table">
@@ -35,6 +54,7 @@
<tr>
<th></th>
<th>{{ $t('falukant.family.spouse.wooing.gift') }}</th>
<th>{{ $t('falukant.family.spouse.wooing.effect') }}</th>
<th>{{ $t('falukant.family.spouse.wooing.value') }}</th>
</tr>
</thead>
@@ -42,12 +62,14 @@
<tr v-for="gift in gifts" :key="gift.id">
<td><input type="radio" name="gift" :value="gift.id" v-model="selectedGiftId"></td>
<td>{{ $t(`falukant.gifts.${gift.name}`) }}</td>
<td>{{ $t(`falukant.family.spouse.giftAffect.${getEffect(gift)}`) }}</td>
<td>{{ formatCost(gift.cost) }}</td>
</tr>
</tbody>
</table>
<div>
<button @click="sendGift" class="button">{{ $t('falukant.family.spouse.wooing.sendGift') }}</button>
<button @click="sendGift" class="button">{{ $t('falukant.family.spouse.wooing.sendGift')
}}</button>
</div>
</div>
</div>
@@ -67,7 +89,7 @@
v-model="selectedProposalId"></td>
<td>{{
$t(`falukant.titles.${proposal.proposedCharacterGender}.${proposal.proposedCharacterNobleTitle}`)
}} {{ proposal.proposedCharacterName }}</td>
}} {{ proposal.proposedCharacterName }}</td>
<td>{{ proposal.proposedCharacterAge }}</td>
<td>{{ formatCost(proposal.cost) }}</td>
</tr>
@@ -80,7 +102,6 @@
</div>
</div>
<!-- Kinder -->
<div class="children-section">
<h3>{{ $t('falukant.family.children.title') }}</h3>
<div v-if="children && children.length > 0">
@@ -131,9 +152,6 @@
</div>
</div>
<!-- Dialog-Beispiele oder ähnliche Komponenten -->
<MessageDialog ref="messageDialog" />
<ErrorDialog ref="errorDialog" />
</template>
<script>
@@ -160,7 +178,9 @@ export default {
proposals: [],
selectedProposalId: null,
gifts: [],
selectedGiftId: null
selectedGiftId: null,
moodAffects: [],
characterAffects: []
}
},
computed: {
@@ -169,12 +189,13 @@ export default {
async mounted() {
await this.loadFamilyData();
await this.loadGifts();
await this.loadMoodAffects();
await this.loadCharacterAffects();
},
methods: {
async loadFamilyData() {
try {
const response = await apiClient.get('/api/falukant/family');
console.log(response.data);
this.relationships = response.data.relationships;
this.children = response.data.children;
this.lovers = response.data.lovers;
@@ -193,6 +214,22 @@ export default {
return new Intl.NumberFormat(navigator.language, { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(value);
},
getEffect(gift) {
const relationship = this.relationships[0];
const partner = relationship.character2;
const currentMoodId = partner.mood?.id ?? partner.mood_id;
const moodEntry = gift.moodsAffects.find(ma => ma.mood_id === currentMoodId);
const moodValue = moodEntry ? moodEntry.suitability : 0;
let highestCharacterValue = 0;
for (const trait of partner.characterTrait) {
const charEntry = gift.charactersAffects.find(ca => ca.trait_id === trait.id);
if (charEntry && charEntry.suitability > highestCharacterValue) {
highestCharacterValue = charEntry.suitability;
}
}
return Math.round((moodValue + highestCharacterValue) / 2);
},
async acceptProposal() {
const response = await apiClient.post('/api/falukant/family/acceptmarriageproposal'
, { proposalId: this.selectedProposalId });
@@ -200,19 +237,54 @@ export default {
},
async loadGifts() {
const response = await apiClient.get('/api/falukant/family/gifts');
this.gifts = response.data;
const response = await apiClient.get('/api/falukant/family/gifts');
this.gifts = response.data;
},
async sendGift() {
if (!this.selectedGiftId) {
alert('Please select a gift');
this.$root.$refs.errorDialog.open(`tr:falukant.family.sendgift.error.nogiftselected`);
return;
}
const response = await apiClient.post('/api/falukant/family/gift'
, { giftId: this.selectedGiftId });
this.loadFamilyData();
}
try {
await apiClient.post('/api/falukant/family/gift'
, { giftId: this.selectedGiftId });
this.loadFamilyData();
this.$root.$refs.messageDialog.open('tr:falukant.family.sendgift.success');
} catch (error) {
console.log(error.response);
if (error.response.status === 412) {
this.$root.$refs.errorDialog.open(`tr:falukant.family.sendgift.error.${error.response.data.error}`);
} else {
this.$root.$refs.errorDialog.open(`tr:falukant.family.sendgift.error.generic`);
}
}
},
async loadMoodAffects() {
try {
const response = await apiClient.get('/api/falukant/mood/affect');
this.moodAffects = response.data;
} catch (error) {
console.error(error);
}
},
async loadCharacterAffects() {
try {
const response = await apiClient.get('/api/falukant/character/affect');
this.characterAffects = response.data;
} catch (error) {
console.error(error);
}
},
progressColor(p) {
const pct = Math.max(0, Math.min(100, p)) / 100;
const red = Math.round(255 * (1 - pct));
const green = Math.round(255 * pct);
return `rgb(${red}, ${green}, 0)`;
},
}
}
</script>
@@ -284,4 +356,28 @@ export default {
h2 {
padding-top: 20px;
}
.relationship>table,
.relationship>ul {
display: inline-block;
margin-right: 1em;
vertical-align: top;
}
.relationship>ul {
list-style: none;
}
.progress {
width: 100%;
background-color: #e5e7eb;
border-radius: 0.25rem;
overflow: hidden;
height: 1rem;
}
.progress-inner {
height: 100%;
transition: width 0.3s ease, background-color 0.3s ease;
}
</style>