diff --git a/app/imports/api/properties/Attributes.js b/app/imports/api/properties/Attributes.js index 8bc3a9c8..5c83a660 100644 --- a/app/imports/api/properties/Attributes.js +++ b/app/imports/api/properties/Attributes.js @@ -47,6 +47,18 @@ let AttributeSchema = createPropertySchema({ spellSlotLevel: { type: 'fieldToCompute', optional: true, + }, + // For type healthBar midColor, and lowColor can be set separately from the + // property's color, which is used as the undamaged color + 'healthBarColorMid': { + type: String, + regEx: /^#([a-f0-9]{3}){1,2}\b$/i, + optional: true, + }, + 'healthBarColorLow': { + type: String, + regEx: /^#([a-f0-9]{3}){1,2}\b$/i, + optional: true, }, // The starting value, before effects baseValue: { diff --git a/app/imports/ui/components/ColorPicker.vue b/app/imports/ui/components/ColorPicker.vue index 143f2b66..bb1115f6 100644 --- a/app/imports/ui/components/ColorPicker.vue +++ b/app/imports/ui/components/ColorPicker.vue @@ -13,7 +13,10 @@ v-on="on" > {{ label }} - + mdi-format-paint diff --git a/app/imports/ui/properties/components/attributes/HealthBar.vue b/app/imports/ui/properties/components/attributes/HealthBar.vue index a220c9e4..f71f8d89 100644 --- a/app/imports/ui/properties/components/attributes/HealthBar.vue +++ b/app/imports/ui/properties/components/attributes/HealthBar.vue @@ -3,9 +3,9 @@ wrap align-center justify-center - style="min-height: 48px;" + style="min-height: 42px;" :class="{ hover }" - class="my-3 health-bar" + class="my-1 health-bar" :data-id="_id" >
- - - - {{ value }} / {{ maxValue }} - - +
+
+ {{ value }} / {{ maxValue }} +
+
+
import IncrementMenu from '/imports/ui/components/IncrementMenu.vue'; +import isDarkColor from '/imports/ui/utility/isDarkColor.js'; +import chroma from 'chroma-js'; + export default { components: { IncrementMenu + }, + inject: { + theme: { + default: { + isDark: false, + }, + }, }, props: { value: Number, maxValue: Number, name: String, + color: { + type: String, + default() { + return this.$vuetify.theme.currentTheme.primary + }, + }, + midColor: { + type: String, + default: undefined, + }, + lowColor: { + type: String, + default: undefined, + }, _id: String, }, data() { @@ -87,6 +129,37 @@ import IncrementMenu from '/imports/ui/components/IncrementMenu.vue'; hover: false, }; }, + computed: { + barColor() { + const fraction = this.value / this.maxValue; + if (!Number.isFinite(fraction)) return this.color; + if (fraction > 0.5){ + return this.color; + } else if (this.midColor && this.lowColor) { + return chroma.mix(this.lowColor, this.midColor, fraction * 2).hex(); + } else if (this.midColor){ + return this.midColor; + } + return this.color; + }, + barBackgroundColor(){ + return chroma(this.barColor) + .darken(1.5) + .desaturate(1.5) + .hex(); + }, + isTextLight(){ + return isDarkColor(this.barBackgroundColor); + /* Change color at the halfway mark + const fraction = this.value / this.maxValue; + if (fraction >= 0.5){ + return isDarkColor(this.barColor); + } else { + return isDarkColor(this.barBackgroundColor); + } + */ + } + }, methods: { edit() { this.editing = true; diff --git a/app/imports/ui/properties/components/attributes/HealthBarCard.vue b/app/imports/ui/properties/components/attributes/HealthBarCard.vue index 496aa7e7..f05c7978 100644 --- a/app/imports/ui/properties/components/attributes/HealthBarCard.vue +++ b/app/imports/ui/properties/components/attributes/HealthBarCard.vue @@ -6,6 +6,9 @@ :value="attribute.value" :max-value="attribute.total" :name="attribute.name" + :color="attribute.color" + :mid-color="attribute.healthBarColorMid" + :low-color="attribute.healthBarColorLow" :_id="attribute._id" @change="e => $emit('change', {_id: attribute._id, change: e})" @click="e => $emit('click', {_id: attribute._id})" diff --git a/app/imports/ui/properties/forms/AttributeForm.vue b/app/imports/ui/properties/forms/AttributeForm.vue index e933eaf4..5d23e2bf 100644 --- a/app/imports/ui/properties/forms/AttributeForm.vue +++ b/app/imports/ui/properties/forms/AttributeForm.vue @@ -47,23 +47,25 @@ :hint="attributeTypeHints[model.attributeType]" @change="change('attributeType', ...arguments)" /> - - + + + + - - -
- -
+ + - + + + + + + +
+ +
+ +
+
+
+
-
-
- -
- + +