Fixed property adjustments on the stats page

This commit is contained in:
Thaum Rystra
2020-03-04 09:56:06 +02:00
parent f3d86ef274
commit dfa3b057b0
7 changed files with 46 additions and 39 deletions

View File

@@ -183,7 +183,7 @@ const damageProperty = new ValidatedMethod({
run({_id, operation, value}) { run({_id, operation, value}) {
let currentProperty = CreatureProperties.findOne(_id); let currentProperty = CreatureProperties.findOne(_id);
// Check permissions // Check permissions
assertPropertyEditPermission(currentProperty, this.UserId); assertPropertyEditPermission(currentProperty, this.userId);
// Check if property can take damage // Check if property can take damage
let schema = CreatureProperties.simpleSchema(currentProperty); let schema = CreatureProperties.simpleSchema(currentProperty);
if (!schema.allowsKey('damage')){ if (!schema.allowsKey('damage')){
@@ -194,23 +194,34 @@ const damageProperty = new ValidatedMethod({
} }
if (operation === 'set'){ if (operation === 'set'){
let currentValue = currentProperty.value; let currentValue = currentProperty.value;
console.log('currentValue is ', currentValue)
console.log('target value is ', value)
// Set represents what we want the value to be after damage // Set represents what we want the value to be after damage
// So we need the actual damage to get to that value // So we need the actual damage to get to that value
let damage = currentValue - value; let damage = currentValue - value;
console.log('required damage is ', damage)
// Damage can't exceed total value // Damage can't exceed total value
if (damage > currentValue) damage = currentValue; if (damage > currentValue) damage = currentValue;
// Damage must be positive // Damage must be positive
if (damage < 0) damage = 0; if (damage < 0) damage = 0;
CreatureProperties.update(_id, {$set: {damage}}); CreatureProperties.update(_id, {
$set: {damage}
}, {
selector: currentProperty
});
} else if (operation === 'increment'){ } else if (operation === 'increment'){
let currentValue = currentAttribute.value - (currentAttribute.damage || 0); let currentValue = currentProperty.value - (currentProperty.damage || 0);
let currentDamage = currentAttribute.damage; let currentDamage = currentProperty.damage;
let increment = value; let increment = value;
// Can't increase damage above the remaining value // Can't increase damage above the remaining value
if (increment > currentValue) increment = currentValue; if (increment > currentValue) increment = currentValue;
// Can't decrease damage below zero // Can't decrease damage below zero
if (-increment > currentDamage) increment = -currentDamage; if (-increment > currentDamage) increment = -currentDamage;
CreatureProperties.update(_id, {$inc: {damage: increment}}); CreatureProperties.update(_id, {
$inc: {damage: increment}
}, {
selector: currentProperty
});
} }
recomputeCreatures(currentProperty); recomputeCreatures(currentProperty);
}, },

View File

@@ -15,8 +15,8 @@
<ability-list-tile <ability-list-tile
v-bind="ability" v-bind="ability"
:key="ability._id" :key="ability._id"
:data-id="`ability-list-tile-${ability._id}`" :data-id="ability._id"
@click="clickAttribute({_id: ability._id})" @click="clickProperty({_id: ability._id})"
/> />
</template> </template>
</v-list> </v-list>
@@ -27,7 +27,7 @@
<attribute-card <attribute-card
v-bind="stat" v-bind="stat"
:data-id="stat._id" :data-id="stat._id"
@click="clickAttribute({_id: stat._id})" @click="clickProperty({_id: stat._id})"
/> />
</div> </div>
@@ -35,7 +35,7 @@
<attribute-card modifier <attribute-card modifier
v-bind="modifier" v-bind="modifier"
:data-id="modifier._id" :data-id="modifier._id"
@click="clickAttribute({_id: modifier._id})" @click="clickProperty({_id: modifier._id})"
/> />
</div> </div>
@@ -43,7 +43,7 @@
<attribute-card modifier <attribute-card modifier
v-bind="check" v-bind="check"
:data-id="check._id" :data-id="check._id"
@click="clickSkill({_id: check._id})" @click="clickProperty({_id: check._id})"
/> />
</div> </div>
@@ -57,7 +57,7 @@
v-bind="hitDie" v-bind="hitDie"
:data-id="hitDie._id" :data-id="hitDie._id"
:key="hitDice._id" :key="hitDice._id"
@click="clickAttribute({_id: hitDie._id})" @click="clickProperty({_id: hitDie._id})"
@change="e => incrementChange(hitDie._id, e)" @change="e => incrementChange(hitDie._id, e)"
/> />
</template> </template>
@@ -74,7 +74,7 @@
v-bind="save" v-bind="save"
:key="save._id" :key="save._id"
:data-id="save._id" :data-id="save._id"
@click="clickSkill({_id: save._id})" @click="clickProperty({_id: save._id})"
/> />
</v-list> </v-list>
</v-card> </v-card>
@@ -89,7 +89,7 @@
v-bind="skill" v-bind="skill"
:key="skill._id" :key="skill._id"
:data-id="skill._id" :data-id="skill._id"
@click="clickSkill({_id: skill._id})" @click="clickProperty({_id: skill._id})"
/> />
</v-list> </v-list>
</v-card> </v-card>
@@ -103,7 +103,7 @@
<resource-card <resource-card
v-bind="resource" v-bind="resource"
:data-id="resource._id" :data-id="resource._id"
@click="clickAttribute({_id: resource._id})" @click="clickProperty({_id: resource._id})"
@change="e => incrementChange(resource._id, e)" @change="e => incrementChange(resource._id, e)"
/> />
</div> </div>
@@ -117,7 +117,7 @@
v-bind="spellSlot" v-bind="spellSlot"
:key="spellSlot._id" :key="spellSlot._id"
:data-id="spellSlot._id" :data-id="spellSlot._id"
@click="clickAttribute({_id: spellSlot._id})" @click="clickProperty({_id: spellSlot._id})"
@change="e => incrementChange(spellSlot._id, e)" @change="e => incrementChange(spellSlot._id, e)"
/> />
</v-list> </v-list>
@@ -128,8 +128,7 @@
</template> </template>
<script> <script>
import CreatureProperties from '/imports/api/creature/CreatureProperties.js'; import CreatureProperties, { damageProperty } from '/imports/api/creature/CreatureProperties.js';
import AttributeCard from '/imports/ui/properties/attributes/AttributeCard.vue'; import AttributeCard from '/imports/ui/properties/attributes/AttributeCard.vue';
import AbilityListTile from '/imports/ui/properties/attributes/AbilityListTile.vue'; import AbilityListTile from '/imports/ui/properties/attributes/AbilityListTile.vue';
import ColumnLayout from '/imports/ui/components/ColumnLayout.vue'; import ColumnLayout from '/imports/ui/components/ColumnLayout.vue';
@@ -217,7 +216,7 @@
conMod, conMod,
key: hd._id, key: hd._id,
maxValue: hd.value, maxValue: hd.value,
value: hd.value + (hd.adjustment || 0), value: hd.value - (hd.damage || 0),
} }
}); });
}, },
@@ -250,23 +249,16 @@
}, },
}, },
methods: { methods: {
clickAttribute({_id}){ clickProperty({_id}){
this.$store.commit('pushDialogStack', { this.$store.commit('pushDialogStack', {
component: 'creature-property-dialog', component: 'creature-property-dialog',
elementId: `ability-list-tile-${_id}`, elementId: `${_id}`,
data: {_id},
});
},
clickSkill({_id}){
this.$store.commit('pushDialogStack', {
component: 'creature-property-dialog',
elementId: _id,
data: {_id}, data: {_id},
}); });
}, },
incrementChange(_id, {type, value}){ incrementChange(_id, {type, value}){
if (type === 'increment'){ if (type === 'increment'){
adjustAttribute.call({_id, increment: value}); damageProperty.call({_id, operation: 'increment' ,value: -value});
} }
}, },
insertAttribute(){ insertAttribute(){

View File

@@ -34,7 +34,7 @@
</v-progress-linear> </v-progress-linear>
<span <span
class="value" class="value"
style="margin-top: -20px; z-index: 1; font-size: 16px; font-weight: 600; height: 20px;" style="margin-top: -20px; z-index: 1; font-size: 15px; font-weight: 600; height: 20px;"
> >
{{ value }} / {{ maxValue }} {{ value }} / {{ maxValue }}
</span> </span>
@@ -130,7 +130,7 @@
this.editing = false; this.editing = false;
let value = +this.$refs.editInput.lazyValue; let value = +this.$refs.editInput.lazyValue;
let type = this.operation === null ? 'set' : 'increment'; let type = this.operation === null ? 'set' : 'increment';
if (this.operation === 1) { if (this.operation === 0) {
value = -value; value = -value;
} }
this.$emit('change', { type, value }); this.$emit('change', { type, value });

View File

@@ -3,7 +3,7 @@
<health-bar <health-bar
v-for="attribute in attributes" v-for="attribute in attributes"
:key="attribute._id" :key="attribute._id"
:value="attribute.value + (attribute.adjustment || 0)" :value="attribute.value - (attribute.damage || 0)"
:maxValue="attribute.value" :maxValue="attribute.value"
:name="attribute.name" :name="attribute.name"
:_id="attribute._id" :_id="attribute._id"

View File

@@ -7,7 +7,7 @@
</template> </template>
<script> <script>
import CreatureProperties from '/imports/api/creature/CreatureProperties.js'; import CreatureProperties, { damageProperty } from '/imports/api/creature/CreatureProperties.js';
import HealthBarCard from '/imports/ui/properties/attributes/HealthBarCard.vue'; import HealthBarCard from '/imports/ui/properties/attributes/HealthBarCard.vue';
export default { export default {
@@ -31,16 +31,17 @@
}, },
methods: { methods: {
healthBarClicked({_id}){ healthBarClicked({_id}){
this.$store.commit("pushDialogStack", { this.$store.commit('pushDialogStack', {
component: "attribute-dialog-container", component: 'creature-property-dialog',
elementId: _id, elementId: `${_id}`,
data: {_id}, data: {_id},
}); });
}, },
healthBarChanged({_id, change}){ healthBarChanged({_id, change}){
adjustAttribute.call({ damageProperty.call({
_id, _id,
[change.type]: change.value operation: change.type,
value: change.value
}); });
}, },
}, },

View File

@@ -41,7 +41,7 @@
}, },
computed: { computed: {
currentValue(){ currentValue(){
return this.value + (this.adjustment || 0); return this.value - (this.damage || 0);
}, },
}, },
methods: { methods: {

View File

@@ -61,7 +61,7 @@
clearable clearable
:value="model.baseProficiency" :value="model.baseProficiency"
:error-messages="errors.baseProficiency" :error-messages="errors.baseProficiency"
@change="(value, ack) => $emit('change', {path: ['baseProficiency'], value, ack})" @change="(value, ack) => {$emit('change', {path: ['baseProficiency'], value: value || 0, ack}); log({value, ack})}"
/> />
</div> </div>
</form-section> </form-section>
@@ -114,6 +114,9 @@
}, },
] ]
};}, };},
methods: {
log: console.log,
},
}; };
</script> </script>