diff --git a/src/inventory.ts b/src/inventory.ts index ab80f27..37405eb 100644 --- a/src/inventory.ts +++ b/src/inventory.ts @@ -7,6 +7,7 @@ import { Level } from './levels/main-level'; import { Unit, UnitType, UnitsConfig } from './unit'; import { Vector } from 'excalibur'; import { SfxrSounds } from './resources'; +import { classMap } from 'lit/directives/class-map'; export type InventoryConfig = Record; @@ -20,6 +21,14 @@ export class Inventory extends LitElement { knight: 0, archer: 0 } as any; + public pulse: Record = { + dragon: false, + orc: false, + goblin: false, + rat: false, + knight: false, + archer: false + } as any; left = 0; top = 0; @@ -91,6 +100,57 @@ export class Inventory extends LitElement { align-items: center; } + @keyframes pulse { + from { + opacity: 0; + } + + to { + opacity: 1; + } + } + + .box { + position: relative; + box-shadow: 0 0 5px rgba(255, 255, 255, 0.2); + -webkit-transition: all 0.6s cubic-bezier(0.165, 0.84, 0.44, 1); + transition: all 0.6s cubic-bezier(0.165, 0.84, 0.44, 1); + } + + .box::after { + content: ""; + border-radius: 5px; + position: absolute; + z-index: -1; + top: 0; + left: 0; + width: 100%; + height: 100%; + box-shadow: 0 0 25px rgba(255, 255, 255, 0.8); + opacity: 0; + -webkit-transition: all 0.6s cubic-bezier(0.165, 0.84, 0.44, 1); + transition: all 0.6s cubic-bezier(0.165, 0.84, 0.44, 1); + } + + .box:hover { + /* -webkit-transform: scale(1.25, 1.25); + transform: scale(1.25, 1.25); */ + } + + .box:hover::after { + /* opacity: 1; */ + animation-duration: 1.5s; + animation-name: pulse; + animation-iteration-count: infinite; + animation-direction: alternate; + } + .pulse.box::after { + animation-duration: 1.5s; + animation-name: pulse; + animation-iteration-count: infinite; + animation-direction: alternate; + } + .unit-image { background-image: var(--monster-image-path); width: 32px; @@ -142,6 +202,11 @@ export class Inventory extends LitElement { this.requestUpdate(); } + setPulse(monster: UnitType, pulse: boolean = true){ + this.pulse[monster] = pulse; + this.requestUpdate(); + } + setLevel(level: Level) { this.level = level; } @@ -155,7 +220,7 @@ export class Inventory extends LitElement { this.requestUpdate(); } } - + override firstUpdated(_changedProperties: PropertyValueMap | Map): void { const container = this.renderRoot.querySelector('.container') as HTMLElement; container.style.setProperty('--monster-image-path', `url(${monsterSheetPng})`); @@ -166,7 +231,7 @@ export class Inventory extends LitElement { onSelection = (type: UnitType) => { return () => { if (this.counts[type] > 0) { - const unit = new Unit({type}); + const unit = new Unit({ type }); if (this.level.currentSelection) { this.level.cancelSelection(); } @@ -174,7 +239,7 @@ export class Inventory extends LitElement { this.counts[type]--; SfxrSounds.selectInventory.play(); this.requestUpdate(); - this.dispatchEvent(new CustomEvent('selection', { detail: type})); + this.dispatchEvent(new CustomEvent('selection', { detail: type })); } } } @@ -191,11 +256,17 @@ export class Inventory extends LitElement {
    ${Object.entries(this.counts).map(([type, count]) => count > 0 ? html`
  • -
  • ` : html``)} diff --git a/src/levels/tutorial.ts b/src/levels/tutorial.ts index 1204c39..9290e30 100644 --- a/src/levels/tutorial.ts +++ b/src/levels/tutorial.ts @@ -164,19 +164,26 @@ export class Tutorial extends Level { } waitForSelection = (selection: UnitType) => { + this.inventory.setPulse(selection, true); const future = new Future(); - if (this.selections.length > 0) { + const removeSelections = (selection: UnitType) => { const index = this.selections.indexOf(selection); this.selections.splice(index, 1); if (index > -1) { + this.inventory.setPulse(selection, false); future.resolve(); } } - this.inventory.addEventListener('selection', ({ detail }: any) => { - if (selection === detail) { - future.resolve(); - } - }); + console.log(this.selections); + if (this.selections.length > 0) { + removeSelections(selection); + } else { + this.inventory.addEventListener('selection', ({ detail }: any) => { + if (selection === detail) { + removeSelections(detail); + } + }, {once: true}); + } return future.promise; } @@ -188,11 +195,11 @@ export class Tutorial extends Level { future.resolve(); } })) - this.puzzleGrid.events.on('placement', (tile) => { - if (tile.x === x && tile.y === y) { - future.resolve(); - } - }); + this.puzzleGrid.events.on('placement', (tile) => { + if (tile.x === x && tile.y === y) { + future.resolve(); + } + }); return future.promise; } @@ -210,10 +217,11 @@ export class Tutorial extends Level { const waitForPlacement = this.waitForPlacement; const puzzleGrid = this.puzzleGrid; const equation = this.equation; + const inventory = this.inventory; coroutine(function* () { const xPos = 508; - const goblinYPos = 85; - const ratYPos = 68; + const goblinYPos = 90; + const ratYPos = 73; yield 500; yield moveFingerAndRotate(vec(xPos, goblinYPos), 0); yield waitForSelection('goblin');