Skip to content
Snippets Groups Projects
Tile.vue 8.03 KiB
Newer Older
Griefed's avatar
Griefed committed
<template>
   <div id="parent" class="hexagon"
Trungel's avatar
Trungel committed
    :class="[tile.typeId,isViewRadiusBorder(), ((tile.x == store.state.centerX) && (tile.y == store.state.centerY))?'centerTile':'']">
    <div class="hexTop" :class="((tile.x == store.state.centerX) && (tile.y == store.state.centerY))?'centerTop':''"></div>
    <div class="hexBottom" :class="((tile.x == store.state.centerX) && (tile.y == store.state.centerY))?'centerBottom':''"></div>
Griefed's avatar
Griefed committed
    <q-btn-dropdown
      class="buttonshift without-icon custom-width"
Trungel's avatar
Trungel committed
      :label="tile.typeId"
Griefed's avatar
Griefed committed
      align="center"
      size="11px"
      dropdown-icon=" "
      v-model="menuState">
      <q-list>

Trungel's avatar
Trungel committed
        <q-item v-for="type in types" v-bind:key="type" clickable v-close-popup @click="setType(type)">
Griefed's avatar
Griefed committed
          <q-item-section avatar>
            <q-avatar>
Trungel's avatar
Trungel committed
              <img :src="'./tiles/'+type+'.webp'" />
Griefed's avatar
Griefed committed
            </q-avatar>
          </q-item-section>
          <q-item-section>
Trungel's avatar
Trungel committed
            <q-item-label>{{type.toUpperCase()}}</q-item-label>
Griefed's avatar
Griefed committed
          </q-item-section>
        </q-item>
      </q-list>
    </q-btn-dropdown>
Trungel's avatar
Trungel committed
    <q-tooltip :disable="$q.platform.is.mobile">
      {{tile.x+'/'+tile.y+": "+ tile.typeId}}
    </q-tooltip>
Trungel's avatar
Trungel committed
   </div>
Griefed's avatar
Griefed committed
</template>

<script>
import {inject, ref} from "vue";
Griefed's avatar
Griefed committed

export default {
Trungel's avatar
Trungel committed
  props:{
    tile: Object,
    typeValue: String
  },
  setup (props) {
Trungel's avatar
Trungel committed
    var types = ["barren", "clay", "desert", "fish", "forest", "grass", "ice", "iron", "mountain", "salt", "stone", "water", "wheat", "wool"];
    const store = inject('store');

    const isViewRadiusBorder = function() {
      var borders = [];
      //leftBorder
Trungel's avatar
Trungel committed
      if( props.tile.x == (this.store.state.centerX-this.store.state.radiusX+1) &&
          ((this.store.state.centerY-this.store.state.radiusY+1) <= props.tile.y && props.tile.y <= (this.store.state.centerY+this.store.state.radiusY-1))){
            borders.push("viewBorderLeft");
      }
Trungel's avatar
Trungel committed
      if( props.tile.x == (this.store.state.centerX+this.store.state.radiusX-1) &&
          ((this.store.state.centerY-this.store.state.radiusY+1) <= props.tile.y && props.tile.y <= (this.store.state.centerY+this.store.state.radiusY-1))){
            borders.push("viewBorderRight")
      }
Trungel's avatar
Trungel committed
      if( props.tile.y == (this.store.state.centerY+this.store.state.radiusY-1) &&
          ((this.store.state.centerX-this.store.state.radiusX+1) <= props.tile.x && props.tile.x <= (this.store.state.centerX+this.store.state.radiusX-1))){
            borders.push("viewBorderTop")
      }
Trungel's avatar
Trungel committed
      if( props.tile.y == (this.store.state.centerY-this.store.state.radiusY+1) &&
          ((this.store.state.centerX-this.store.state.radiusX+1) <= props.tile.x && props.tile.x <= (this.store.state.centerX+this.store.state.radiusX-1))){
            borders.push("viewBorderBottom")
      }

      return borders;
    }

Griefed's avatar
Griefed committed
    return {
      isViewRadiusBorder,
      store,
Trungel's avatar
Trungel committed
      types,
Griefed's avatar
Griefed committed
      menuState: ref(false),
      label: 'grass',
      color: 'green-8',
      textcolor: 'white',
      backgroundImage: 'background-image: url(./tiles/grass_tile.webp);'
Griefed's avatar
Griefed committed
    }
Trungel's avatar
Trungel committed
  },
  emits: ['update:typeValue'],
  updated(){

Griefed's avatar
Griefed committed
  },
  methods: {
Trungel's avatar
Trungel committed
    setType(type){
      this.$emit('update:typeValue', type);
Griefed's avatar
Griefed committed
    },
  }
}
</script>

Trungel's avatar
Trungel committed
<style lang="scss">
Griefed's avatar
Griefed committed
.buttonshift {
Griefed's avatar
Griefed committed
  margin-top: 15px;
}

button.without-icon i {
  display: none;
}

.custom-width {
  width: 93.5px;
}

.hexagon {
  position: relative;
  width: 100px;
  height: 57.74px;
  margin: 28.87px 0;
  background-size: auto 108.5419px;
  background-position: center;
Griefed's avatar
Griefed committed
  border-left: solid 3px #333333;
  border-right: solid 3px #333333;
}

Trungel's avatar
Trungel committed

Griefed's avatar
Griefed committed
  position: absolute;
Griefed's avatar
Griefed committed
  width: 70.71px;
  height: 70.71px;
Griefed's avatar
Griefed committed
  -webkit-transform: scaleY(0.5774) rotate(-45deg);
  -ms-transform: scaleY(0.5774) rotate(-45deg);
  transform: scaleY(0.5774) rotate(-45deg);
  background: inherit;
  left: 11.64px;
}

/*counter transform the bg image on the caps*/
.hexTop:after,
.hexBottom:after {
  content: "";
  position: absolute;
  width: 94.0000px;
  height: 54.270925303824825px;
  -webkit-transform:  rotate(45deg) scaleY(1.7321) translateY(-27.1355px);
  -ms-transform:      rotate(45deg) scaleY(1.7321) translateY(-27.1355px);
  transform:          rotate(45deg) scaleY(1.7321) translateY(-27.1355px);
  -webkit-transform-origin: 0 0;
  -ms-transform-origin: 0 0;
  transform-origin: 0 0;
  background: inherit;
Griefed's avatar
Griefed committed
}

Griefed's avatar
Griefed committed
  top: -35.3553px;
  border-top: solid 4.2426px #333333;
  border-right: solid 4.2426px #333333;
}

.hexTop:after {
  background-position: center top;
}

.hexBottom {
Griefed's avatar
Griefed committed
  bottom: -35.3553px;
  border-bottom: solid 4.2426px #333333;
  border-left: solid 4.2426px #333333;
}

.hexBottom:after {
  background-position: center bottom;
}

.hexagon:after {
  content: "";
  position: absolute;
  top: 1.7321px;
  left: 0;
  width: 94.0000px;
  height: 54.2709px;
  z-index: 2;
  background: inherit;
}
Trungel's avatar
Trungel committed

.viewBorderLeft {
  z-index: 1001;
  border-left: dashed 3px blue;
}

.viewBorderRight {
  z-index: 1001;
  border-right: dashed 3px blue;
}

.viewBorderTop {
  z-index: 1001;
  .hexTop {
    border-top: dashed 3px blue;
    border-right: dashed 3px blue;
  }
}
.viewBorderBottom {
  z-index: 1001;
  .hexBottom {
    border-bottom: dashed 3px blue;
    border-left: dashed 3px blue;
  }
}

.notShifted{
  .viewBorderLeft{
    .hexTop{
      border-top: dashed 3px blue;
    }
    .hexBottom{
      border-left: dashed 3px blue;
    }
Trungel's avatar
Trungel committed
    .centerTop {
      border-top: solid 4.2426px red;
      border-right: solid 4.2426px red;
    }

    .centerBottom {
      border-bottom: solid 4.2426px red;
      border-left: solid 4.2426px red;
    }
  }
}
.shifted{
  .viewBorderRight{
    .hexTop{
      border-right: dashed 3px blue;
    }
    .hexBottom{
      border-bottom: dashed 3px blue;
    }
Trungel's avatar
Trungel committed
    .centerTop {
      border-top: solid 4.2426px red;
      border-right: solid 4.2426px red;
    }

    .centerBottom {
      border-bottom: solid 4.2426px red;
      border-left: solid 4.2426px red;
    }
Trungel's avatar
Trungel committed
.barren {
  background-image: url("../assets/tiles/barren_tile.webp");
  button {
    background-color: $brown-6;
    color: white;
  }
}

.clay {
  background-image: url("../assets/tiles/clay_tile.webp");
  button {
    background-color: $orange-6;
    color: white;
  }
}

.desert {
  background-image: url("../assets/tiles/desert_tile.webp");
  button {
    background-color: $yellow-4;
    color: black;
  }
}
.fish {
  background-image: url("../assets/tiles/fish_tile.webp");
  button {
    background-color: $amber-12;
    color: black;
  }
}
.forest {
  background-image: url("../assets/tiles/forest_tile.webp");
  button {
    background-color: $green-10;
    color: white;
  }
}
.grass {
  background-image: url("../assets/tiles/grass_tile.webp");
  button {
    background-color: $green-8;
    color: white;
  }
}
.ice {
  background-image: url("../assets/tiles/ice_tile.webp");
  button {
    background-color: $cyan-2;
    color: black;
  }
}
.iron {
  background-image: url("../assets/tiles/iron_tile.webp");
  button {
    background-color: $blue-grey-5;
    color: white;
  }
}
.mountain {
  background-image: url("../assets/tiles/mountain_tile.webp");
  button {
    background-color: $grey-13;
    color: white;
  }
}
.salt {
  background-image: url("../assets/tiles/salt_tile.webp");
  button {
    background-color: $grey-4;
    color: black;
  }
}
.stone {
  background-image: url("../assets/tiles/stone_tile.webp");
  button {
    background-color: $blue-grey-13;
    color: white;
  }
}
.water {
  background-image: url("../assets/tiles/water_tile.webp");
  button {
    background-color: $blue-10;
    color: white;
  }
}
.wheat {
  background-image: url("../assets/tiles/wheat_tile.webp");
  button {
    background-color: $amber-12;
    color: black;
  }
}
.wool {
  background-image: url("../assets/tiles/wool_tile.webp");
  button {
    background-color: $brown-13;
    color: black;
  }
}

.centerTop {
  border-top: solid 4.2426px red;
  border-right: solid 4.2426px red;
}

.centerBottom {
  border-bottom: solid 4.2426px red;
  border-left: solid 4.2426px red;
}
Trungel's avatar
Trungel committed

.centerTile {
  z-index: 1002;
  border-left: solid 3px red;
  border-right: solid 3px red;
}
Griefed's avatar
Griefed committed
</style>