Skip to content

Commit

Permalink
added punishments in web builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Naumann committed Jan 26, 2024
1 parent edf0353 commit f16ef63
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 62 deletions.
1 change: 0 additions & 1 deletion builder_website/JSON

This file was deleted.

1 change: 0 additions & 1 deletion builder_website/Java

This file was deleted.

1 change: 1 addition & 0 deletions builder_website/challenges_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
"default": 1,
"description": "The number of effects that are applied at once.",
"maximum": 10,
"minimum": 1,
"type": "integer"
},
"randomizeEffectsAtOnce": {
Expand Down
44 changes: 6 additions & 38 deletions builder_website/src/assets/constraints.sch
Original file line number Diff line number Diff line change
@@ -1,46 +1,14 @@
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xpath">
<pattern>


<rule context="root/rules/enabledGlobalPunishments">
<assert test="not(exists(endPunishment))">
End Punishment exists, but it may not (DUMMY RULE)
<rule context="root/rules/enabledRules/noDeath">
<assert test="not(exists(punishments/deathPunishment))">
NoDeath rule cannnot contain the Death punishment.
</assert>
</rule>
<rule context="root/goals/mobGoal/mobs">
<assert test="not(exists(WITHER))">
Wither may not be selected in MobGoal (DUMMY RULE)
<rule context="root/rules">
<assert test="not(exists(enabledRules/noDeath) and exists(enabledGlobalPunishments/deathPunishment))">
Global Death punishment and NoDeath rule cannot be both active.
</assert>
</rule>
<!--rule context="root">
<assert test="false">
test
</assert>
</rule-->
<!--rule context="root/rules">
<assert test="exists(NoDamage)">
NoDamage does not exist! (This is just a test rule, not an actual rule)
</assert>
</rule>
<rule context="root/rules/NoDeath">
<assert test="not(exists(punishments/Death))">
NoDeath rule should not contain the Death punishment.
</assert>
</rule>
<rule context="rules/RandomDrops/materialRandomizations">
<assert test="count(randomize/@from) = count(distinct-values(randomize/@from))">
Two entries cannot have the same key.
</assert>
</rule-->
<!--rule context="rules/RandomDrops/materialRandomizations" >
<let name="uniqueFromValues" value="distinct-values(randomize/@from)"/>
<assert test="count(randomize/@from) = count($uniqueFromValues)">
Duplicate entries found for 'from' key: <value-of select="string-join($uniqueFromValues[. = current()/@from], ', ')".
</assert>
</rule-->
</pattern>
</schema>
2 changes: 1 addition & 1 deletion builder_website/src/components/model/punishments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface RandomEffectPunishmentConfig extends BasePunishmentConfig {
/**
* The number of effects that are applied at once.
*
* @minmum 1
* @minimum 1
* @maximum 10
* @default 1
* @TJS-type integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<div class="flex justify-between" v-if="punishable">
<div class="flex items-center space-x-2">
<Checkbox :model-value="punishable.active.value" @input="(newActive) => updateIfValid(newActive)" :binary="true"
input-id="0" />
<label for="0" class="ml-2">{{ punishmentView.label }}</label>
:input-id="props.punishmentView.id" />
<label :for="props.punishmentView.id" class="ml-2">{{ punishmentView.label }}</label>
</div>
<div class="flex items-center space-x-2">
<p v-tooltip="{ value: 'Who the punishment applies to, if violated', showDelay: 500, hideDelay: 250}">Affected:</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ watch(heartsLost, (newHeartsLost) => {
})
const randomizeHeartsLost = ref(defaultRandomizeHeartsLost)
watch(randomizeHeartsLost, (isRandomizeHeartsLost) => {
heartsLost.value = 1 // reset hearts lost, since it will be disabled now
randomizeHeartsLost.value = isRandomizeHeartsLost
heartsLost.value = defaultHeartsLost // reset hearts lost, since it will be disabled now
//randomizeHeartsLost.value = isRandomizeHeartsLost
getPunishmentBasePath(config.model, props).healthPunishment!.randomizeHeartsLost = isRandomizeHeartsLost
})
Expand Down
8 changes: 5 additions & 3 deletions builder_website/src/components/punishments/PunishmentList.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<template>
<div class="flex flex-col overflow-y-auto w-[32rem] h-96 max-h-96" v-if="isGlobal !== undefined">
<div class="flex flex-col overflow-y-auto w-[40rem] h-96 max-h-96" v-if="isGlobal !== undefined">
<div class="shrink-0 flex justify-center items-center">
<h1 v-if="isGlobal === true" class="text-3xl">Global Punishments</h1>
<h1 v-else class="text-3xl">Local Punishments for {{ rulesView.allrules[currentRule as RuleName].label }}</h1>
</div>
<div class="shrink-0 flex flex-col space-y-4 mx-2">
<div v-for="punishment in allPunishmentsView" :key="punishment.id" >
<HealthPunishment v-if="punishment.id === 'healthPunishment'" :punishment-view="punishment" :global="isGlobal" :rule-name="currentRule" />
<DefaultPunishment v-else :punishment-view="punishment" :global="isGlobal" :rule-name="currentRule" :assign-when-created="{affects: 'All'}"/>
<RandomEffectPunishment v-else-if="punishment.id === 'randomEffectPunishment'" :punishment-view="punishment" :global="isGlobal" :rule-name="currentRule"/>
<DefaultPunishment v-else :punishment-view="punishment" :global="isGlobal" :rule-name="currentRule" :assign-when-created="{affects: 'All'}" />

</div>
</div>
Expand All @@ -24,6 +25,7 @@ import type { PunishmentView } from '../view/punishments';
import DefaultPunishment from './DefaultPunishment.vue';
import type { BaseRuleConfig, PunishableRuleConfig, RuleName } from '../model/rules';
import HealthPunishment from './HealthPunishment.vue';
import RandomEffectPunishment from './RandomEffectPunishment.vue';
const config = useConfigStore().model
const rulesView = useRulesViewStore()
Expand Down Expand Up @@ -74,7 +76,7 @@ function getRuleConfig(): PunishableRuleConfig {
const allPunishments: PunishmentName[] = [
'endPunishment', 'healthPunishment'
'endPunishment', 'healthPunishment', 'deathPunishment', 'randomEffectPunishment', 'randomItemPunishment'
]
const allPunishmentsView: PunishmentView[] = allPunishments.map(punishmentName => punishmentsViewStore.allpunishments[punishmentName as PunishmentName])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<template>
<DefaultPunishment v-bind="props" v-slot="slotProps" @clear-on-disabled="clearOnDisabled">
<div v-if="slotProps.punishable.active.value">
<div class="flex items-center space-x-4">
<p>Effects at once:</p>
<InputNumber input-style="width:32px" v-model="effectsAtOnce" show-buttons mode="decimal" :min="minEffectsAtOnce" :max="maxEffectsAtOnce" :disabled="randomizeEffectsAtOnce"/>
<Checkbox v-model="randomizeEffectsAtOnce" :binary="true" input-id="randomizeEffectsAtOnce"/>
<label for="randomizeEffectsAtOnce" class="ml-2">Randomize every time?</label>
</div>
</div>
</DefaultPunishment>
</template>

<script setup lang="ts">
import DefaultPunishment, { type PunishmentProps } from './DefaultPunishment.vue';
import InputNumber from 'primevue/inputnumber';
import Checkbox from 'primevue/checkbox';
import { ref, watch } from 'vue';
import { useConfigStore, useJSONSchemaConfigStore } from '@/main';
import { usePunishableCommons } from './Punishable';
const props = defineProps<PunishmentProps>()
const model = useConfigStore().model
const jsonSchema = useJSONSchemaConfigStore()
const { getPunishmentBasePath } = usePunishableCommons()
const minEffectsAtOnce = jsonSchema.RandomEffectPunishmentConfig.properties.effectsAtOnce.minimum
const maxEffectsAtOnce = jsonSchema.RandomEffectPunishmentConfig.properties.effectsAtOnce.maximum
const defaultEffectsAtOnce = jsonSchema.RandomEffectPunishmentConfig.properties.effectsAtOnce.default
const effectsAtOnce = ref(defaultEffectsAtOnce)
watch(effectsAtOnce, (newEffectsAtOnce) => {
getPunishmentBasePath(model, props).randomEffectPunishment!.effectsAtOnce = newEffectsAtOnce
})
const defaultRandomizeEffectsAtOnce = jsonSchema.RandomEffectPunishmentConfig.properties.randomizeEffectsAtOnce.default
const randomizeEffectsAtOnce = ref(defaultRandomizeEffectsAtOnce)
watch(randomizeEffectsAtOnce, (isRandomizeEffectsAtOnce) => {
effectsAtOnce.value = defaultEffectsAtOnce
getPunishmentBasePath(model, props).randomEffectPunishment!.randomizeEffectsAtOnce = isRandomizeEffectsAtOnce
})
function clearOnDisabled() {
effectsAtOnce.value = defaultEffectsAtOnce
randomizeEffectsAtOnce.value = defaultRandomizeEffectsAtOnce
}
</script>
6 changes: 3 additions & 3 deletions builder_website/src/components/rules/NoBlockPlace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<img
class="w-6"
:alt="slotProps.option"
:src="'/img/' + slotProps.option.image + '.png'"
:src="'/rendered_items/' + slotProps.option.image + '.png'"
@error="$event.target.src = 'unknown.png'"
/>
<div>{{ slotProps.option.label }}</div>
Expand Down Expand Up @@ -47,7 +47,7 @@
<img
class="w-6"
:alt="item.code"
:src="'/img/' + item.image + '.png'"
:src="'/rendered_items/' + item.image + '.png'"
@error="$event.target.src = 'unknown.png'"
/>
<p>{{ item.label }}</p>
Expand All @@ -61,7 +61,7 @@ import DefaultPunishableRule from './DefaultPunishableRule.vue'
import MultiSelect from 'primevue/multiselect'
import Sidebar from 'primevue/sidebar'
import { ref, defineComponent, toRef, toRaw, computed } from 'vue'
import matList from '../../assets/placeableBlocks.csv?raw'
import matList from '../../assets/items.csv?raw'
import PunishmentSettingsInRule from '../punishments/PunishmentSettingsInRule.vue'
import {
useConfigStore,
Expand Down
17 changes: 16 additions & 1 deletion builder_website/src/components/rules/RuleSelectionEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { defineProps } from 'vue'
import { useConfigStore, useDefaultConfigStore } from '@/main';
import type { NoBlockBreakRuleConfig, RuleName, RulesConfig, BaseRuleConfig } from '../model/rules';
import type { RuleView } from '../view/rules';
import { useValidator } from '../validator';
import type { Model } from '../model/model';
const props = defineProps({
rule: {
Expand All @@ -33,11 +35,24 @@ const props = defineProps({
const store = useConfigStore().model
const defaultConfig = useDefaultConfigStore()
const validator = useValidator()
function addDefaultSectionToConfig() {
const { valid, messages } = validator.isValid(store, (copy) => {
addSection(copy)
})
if(valid) {
addSection(store)
}
console.log("added default section to", props.rule.id)
store.rules.enabledRules[props.rule.id] = defaultConfig.rules.enabledRules[props.rule.id as keyof BaseRuleConfig]
//store.rules[props.rule.id] = props.rule.defaultSection
}
function addSection(model: Model) {
model.rules.enabledRules[props.rule.id] = defaultConfig.rules.enabledRules[props.rule.id as keyof BaseRuleConfig]
}
</script>
21 changes: 16 additions & 5 deletions builder_website/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ import './assets/tailwind.css'
import Tooltip from 'primevue/tooltip';
import { defineStore } from 'pinia'
import type { Model } from './components/model/model'
import type { NoBlockBreakRule } from './components/model/rules'
import type { RuleName } from './components/model/rules'
import type { MobGoal } from './components/model/goals'
import type { RulesView } from './components/view/rules'
import modelSchema from '../test-output-schema.json'
import modelSchema from '../challenges_schema.json'
import type { PunishmentsView } from './components/view/punishments'
import type { GoalsView } from './components/view/goals'
import ConfirmationService from 'primevue/confirmationservice';
import { useValidator } from './components/validator'

const pinia = createPinia()
const app = createApp(App)
Expand Down Expand Up @@ -143,6 +139,21 @@ const punishmentsView: PunishmentsView = {
id: 'healthPunishment',
label: 'Health',
description: 'TODO'
},
deathPunishment: {
id: 'deathPunishment',
label: 'Death',
description: 'TODO'
},
randomEffectPunishment: {
id: 'randomEffectPunishment',
label: 'Random Effect',
description: 'TODO'
},
randomItemPunishment: {
id: 'randomItemPunishment',
label: 'Random Item',
description: 'TODO'
}
}
}
Expand Down
1 change: 1 addition & 0 deletions plugin/src/main/resources/challenges_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
"default": 1,
"description": "The number of effects that are applied at once.",
"maximum": 10,
"minimum": 1,
"type": "integer"
},
"randomizeEffectsAtOnce": {
Expand Down
13 changes: 8 additions & 5 deletions plugin/src/main/resources/dummy_data.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
"rules": {
"enabledRules": {
"noBlockBreak": {
"noDeath": {
"punishments": {
"healthPunishment": {
"affects": "All",
"heartsLost": 1,
"randomizeHeartsLost": false
"deathPunishment": {

}
}
}
},
"enabledGlobalPunishments": {
"deathPunishment": {

}
}
}
}

0 comments on commit f16ef63

Please sign in to comment.