diff --git a/src/engine/interface/balloons/Balloon.js b/src/engine/interface/balloons/Balloon.js deleted file mode 100644 index 3bc91353..00000000 --- a/src/engine/interface/balloons/Balloon.js +++ /dev/null @@ -1,56 +0,0 @@ -import BaseContainer from '@scenes/base/BaseContainer' - -export default class Balloon extends BaseContainer { - constructor(penguin) { - let offsetY = -95 - - super(penguin.room, penguin.x, penguin.y + offsetY) - - this.penguin = penguin - - this.minWidth = 128 - this.minHeight = 42 - this.offsetY = offsetY - - this.balloon - } - - addBalloon(width, height) { - if (width < this.minWidth) width = this.minWidth - if (height < this.minHeight) height = this.minHeight - - this.balloon = this.scene.add.ninePatchContainer(0, 0, width, height, 'main', 'balloon') - this.balloon.marginTop = 15 - this.balloon.marginBottom = 15 - this.balloon.marginLeft = 15 - this.balloon.marginRight = 15 - - this.balloon.setOrigin(0.5, 1) - - this.add(this.balloon) - } - - addPointer(width, frame) { - if (width < this.minWidth) width = this.minWidth - - let pointer = this.scene.add.ninePatchContainer(0, 0, width, 40, 'main', frame) - - pointer.marginTop = 0 - pointer.marginBottom = 0 - pointer.marginLeft = 15 - pointer.marginRight = 110 - - pointer.setOrigin(0.5, 0) - - this.add(pointer) - } - - resizeBalloon(width, height) { - this.balloon.resize(width, height) - } - - updatePosition() { - this.x = this.penguin.x - this.y = this.penguin.y + this.offsetY - } -} diff --git a/src/engine/interface/balloons/BalloonFactory.js b/src/engine/interface/balloons/BalloonFactory.js deleted file mode 100644 index 8f7f2d08..00000000 --- a/src/engine/interface/balloons/BalloonFactory.js +++ /dev/null @@ -1,115 +0,0 @@ -import EmoteBalloon from './EmoteBalloon' -import TextBalloon from './TextBalloon' - -export default class BalloonFactory { - constructor(main) { - // Main interface - this.main = main - - // Balloon destruction delay - this.delay = 4500 - - this.offsetY = -95 - } - - get penguins() { - return this.main.shell.room.penguins - } - - /** - * Shows an emote balloon. - * - * @param {number} id - Penguin ID - * @param {number} emote - Emote ID - */ - showEmoteBalloon(id, emote) { - if (!emote) { - return - } - - let penguin = this.penguins[id] - if (!penguin || !penguin.visible) { - return - } - - if (!penguin.emoteBalloon) { - penguin.emoteBalloon = new EmoteBalloon(penguin) - penguin.room.add.existing(penguin.emoteBalloon) - } - - if (emote == 19) { - this.main.shell.musicController.addSfx('fart') - } - - this.main.shell.room.triggerEmote(emote) - - penguin.emoteBalloon.setContent(emote) - this.updateBalloon(penguin, penguin.emoteBalloon) - } - - /** - * Shows a text balloon. - * - * @param {number} id - Penguin ID - * @param {string} text - Message to be displayed - */ - showTextBalloon(id, text, filtered = false) { - if (!text) { - return - } - - let penguin = this.penguins[id] - if (!penguin) { - return - } - - this.main.chatLog.addMessage(penguin.id, penguin.username, text, filtered) - - if (!penguin.visible) { - return - } - - if (!penguin.textBalloon) { - penguin.textBalloon = new TextBalloon(penguin) - penguin.room.add.existing(penguin.textBalloon) - } - - penguin.textBalloon.setContent(text, filtered) - this.updateBalloon(penguin, penguin.textBalloon) - } - - updateBalloon(penguin, balloon) { - if (penguin.balloon) { - penguin.balloon.visible = false - } - - // Client balloons sorted higher - balloon.depth = penguin.isClient ? 3001 : 3000 - - balloon.visible = true - penguin.balloon = balloon - - this.addTimer(penguin, balloon) - } - - addTimer(penguin, balloon) { - let config = { - delay: this.delay, - callback: () => this.removeBalloon(penguin, balloon) - } - - if (penguin.balloonTimer) { - penguin.balloonTimer.reset(config) - penguin.room.time.addEvent(penguin.balloonTimer) - - return - } - - penguin.balloonTimer = penguin.room.time.addEvent(config) - } - - removeBalloon(penguin, balloon) { - balloon.visible = false - penguin.balloon = null - } -} diff --git a/src/engine/interface/balloons/EmoteBalloon.js b/src/engine/interface/balloons/EmoteBalloon.js deleted file mode 100644 index 929e3b69..00000000 --- a/src/engine/interface/balloons/EmoteBalloon.js +++ /dev/null @@ -1,35 +0,0 @@ -import Balloon from './Balloon' - -export default class EmoteBalloon extends Balloon { - constructor(penguin) { - super(penguin) - - let width = 128 - let height = 68 - - this.emote = this.addEmote() - - this.addBalloon(width, height) - this.addPointer(width, 'balloon-emote') - this.add(this.emote) - } - - addEmote() { - let emoteSprite = this.scene.add.image(0, -25, 'main', 'emotes/1') - - return emoteSprite - } - - setContent(emote) { - this.updatePosition() - - let frame = `emotes/${emote}` - - // If emote frame doesn't exist, set to 1 - if (!this.shell.textures.get('main').has(frame)) { - frame = 'emotes/1' - } - - this.emote.setFrame(frame) - } -} diff --git a/src/engine/interface/balloons/TextBalloon.js b/src/engine/interface/balloons/TextBalloon.js deleted file mode 100644 index c72bb41b..00000000 --- a/src/engine/interface/balloons/TextBalloon.js +++ /dev/null @@ -1,52 +0,0 @@ -import Balloon from './Balloon' - -export default class TextBalloon extends Balloon { - constructor(penguin) { - super(penguin) - - let width = 256 - let paddingX = 28 - let textWidth = width - paddingX - - this.maxLength = 60 - this.paddingY = 16 - - this.textStyle = { - fontFamily: 'cpBurbankSmall', - fontSize: 24, - color: '#000000', - align: 'center', - fixedWidth: textWidth, - wordWrap: {width: textWidth, useAdvancedWrap: true}, - lineSpacing: -5 - } - - this.text = this.addText() - - this.addBalloon(width, this.text.height + this.paddingY) - this.addPointer(width, 'balloon-text') - this.add(this.text) - } - - addText() { - let textSprite = this.scene.add.text(0, 0, '', this.textStyle) - - textSprite.setOrigin(0.5, 1) - - return textSprite - } - - setContent(text, filtered = false) { - this.updatePosition() - - text = text.substring(0, this.maxLength) - this.text.text = text - if (filtered) { - this.text.setColor('#ff0000') - } else { - this.text.setColor('#000000') - } - - this.resizeBalloon(this.balloon.width, this.text.height + this.paddingY) - } -} diff --git a/src/engine/interface/gridview/GridViewLoader.js b/src/engine/interface/gridview/GridViewLoader.js deleted file mode 100644 index 55a36efe..00000000 --- a/src/engine/interface/gridview/GridViewLoader.js +++ /dev/null @@ -1,91 +0,0 @@ -export default class GridViewLoader { - constructor(gridView) { - this.gridView = gridView - this.scene = gridView.scene - - this.page = null // Current page - this.filter - - this.load = new Phaser.Loader.LoaderPlugin(this.scene) - - this.load.on('filecomplete', this.onFileComplete, this) - this.load.on('loaderror', this.onLoadError, this) - } - - get url() { - return this.filter == 'igloo' ? '/client/media/igloos/buildings/icon' : '/client/media/furniture/icon' - } - - get prefix() { - return this.filter == 'igloo' ? 'igloo/icon' : 'furniture/icon' - } - - get slots() { - return this.gridView.slots - } - - loadPage(filter, page) { - this.filter = filter - this.page = page - - let scale = this.slots.length > 15 ? '@2.5x' : '@5x' - - for (let [index, slot] of this.slots.entries()) { - slot.filter = filter - if (slot.item) slot.item.destroy() - if (slot.quantity) slot.quantity.visible = false - - let item = page[index] - - if (item) { - slot.setInteractive() - slot.visible = true - this.loadItem(item, scale) - } else { - slot.disableInteractive() - slot.visible = false - } - } - - this.load.start() - } - - loadItem(item, scale) { - let key = `${this.prefix}/${scale}/${item}` - - if (this.scene.textures.exists(key)) return this.onFileComplete(key) - - // Ignore scale on igloo icon url - let url = this.filter == 'igloo' ? `${this.url}/${item}.webp` : `${this.url}/${scale}/${item}.webp` - - this.load.image({ - key: key, - url: url - }) - } - - onFileComplete(key) { - if (!this.gridView.visible) return - if (!this.scene.textures.exists(key)) return - - let item = parseInt(key.split('/')[3]) - let index = this.page.indexOf(item) - let slot = this.slots[index] - - if (slot && slot.visible) { - slot.addIcon(key, item) - } - } - - onLoadError(file) { - if (!this.gridView.visible) return - - let item = parseInt(file.key.split('/')[3]) - let index = this.page.indexOf(item) - let slot = this.slots[index] - - if (slot && slot.visible) { - slot.addError(item) - } - } -} diff --git a/src/engine/interface/inventory/InventoryLoader.js b/src/engine/interface/inventory/InventoryLoader.js deleted file mode 100644 index f251d9c4..00000000 --- a/src/engine/interface/inventory/InventoryLoader.js +++ /dev/null @@ -1,105 +0,0 @@ -export default class InventoryLoader { - constructor(inventory, slots) { - this.inventory = inventory // Inventory container object - this.scene = inventory.scene - this.slots = slots // Item slot sprites (inventory grid) - this.page = null // Current page - - this.load = new Phaser.Loader.LoaderPlugin(this.scene) - this.url = '/client/media/clothing/icon' - this.prefix = 'icon' - - this.load.on('filecomplete', this.onFileComplete, this) - this.load.on('loaderror', this.onLoadError, this) - } - - loadPage(page) { - this.page = page - - for (let [index, slot] of this.slots.entries()) { - if (slot.item) slot.item.destroy() - if (slot.spinner) slot.spinner.destroy() - - let item = page[index] - - if (item) { - slot.setInteractive() - slot.setFrame('large-box') - this.addSpinner(slot) - this.loadItem(item) - } else { - slot.disableInteractive() - slot.setFrame('large-box-empty') - } - } - - this.load.start() - } - - addSpinner(slot) { - let spinner = this.scene.add.image(slot.x, slot.y, 'main', 'spinner') - this.inventory.container.add(spinner) - - this.scene.tweens.add({ - targets: spinner, - angle: {from: 0, to: 180}, - duration: 900, - repeat: -1, - ease: 'Cubic' - }) - - slot.spinner = spinner - } - - loadItem(item) { - let key = `${this.prefix}/${item}` - - if (this.scene.textures.exists(key)) return this.onFileComplete(key) - - this.load.image({ - key: key, - url: `${this.url}/${item}.webp` - }) - } - - onFileComplete(key) { - if (!this.inventory.visible) return - if (!this.scene.textures.exists(key)) return - - let item = parseInt(key.split('/')[1]) - let index = this.page.indexOf(item) - let slot = this.slots[index] - - if (!slot) return - - // Do not load into empty slot - if (['large-box', 'large-box-hover'].includes(slot.frame.name)) this.loadIcon(key, slot, item) - } - - onLoadError(file) { - if (!this.inventory.visible) return - - let item = parseInt(file.key.split('/')[1]) - let index = this.page.indexOf(item) - let slot = this.slots[index] - - if (!slot) return - if (slot.spinner) slot.spinner.destroy() - - let errorIcon = this.scene.add.image(slot.x, slot.y, 'main', 'x-icon') - this.inventory.container.add(errorIcon) - - errorIcon.id = item - slot.item = errorIcon - } - - loadIcon(key, slot, item) { - if (slot.spinner) slot.spinner.destroy() - - let icon = this.scene.add.image(slot.x, slot.y, key) - this.inventory.container.add(icon) - - icon.id = item - slot.item = icon - } -}