use ImageBitmap
This commit is contained in:
parent
581ffc886a
commit
fcadfcdbd3
4 changed files with 68 additions and 60 deletions
|
|
@ -9,36 +9,34 @@
|
|||
* *
|
||||
***************************************************************************/
|
||||
|
||||
import { RenderingContext2D } from "util/Types";
|
||||
import { Entity } from "./Entity";
|
||||
import { Paths } from "../data/Paths";
|
||||
import { singletons } from "../SingletonRepo";
|
||||
|
||||
import { marauroa } from "marauroa"
|
||||
import { ImageSprite } from "sprite/image/ImageSprite";
|
||||
import { images } from "sprite/image/ImageManager";
|
||||
|
||||
|
||||
export class Food extends Entity {
|
||||
|
||||
override zIndex = 5000;
|
||||
|
||||
override init() {
|
||||
this.imageSprite = new ImageSprite(
|
||||
images.load(Paths.sprites + "/food.png"),
|
||||
0, this["amount"] * 32, 32, 32);
|
||||
}
|
||||
|
||||
override set(key: string, value: any) {
|
||||
super.set(key, value);
|
||||
if (key === "amount") {
|
||||
this._amount = parseInt(value, 10);
|
||||
if (this.imageSprite) {
|
||||
this.imageSprite.offsetY = this["amount"] * 32;
|
||||
}
|
||||
}
|
||||
// TODO: play sound effect
|
||||
}
|
||||
|
||||
override draw(ctx: RenderingContext2D) {
|
||||
var image = singletons.getSpriteStore().get(Paths.sprites + "/food.png");
|
||||
if (image.height) {
|
||||
var localX = this["x"] * 32;
|
||||
var localY = this["y"] * 32;
|
||||
var offset = this._amount * 32;
|
||||
ctx.drawImage(image, 0, offset, 32, 32, localX, localY, 32, 32);
|
||||
}
|
||||
}
|
||||
|
||||
override onclick(_x: number, _y: number) {
|
||||
var action = {
|
||||
"type": "look",
|
||||
|
|
|
|||
|
|
@ -13,25 +13,20 @@ import { Paths } from "../data/Paths";
|
|||
import { Entity } from "./Entity";
|
||||
|
||||
import { stendhal } from "../stendhal";
|
||||
import { ImageSprite } from "sprite/image/ImageSprite";
|
||||
import { images } from "sprite/image/ImageManager";
|
||||
|
||||
export class GameBoard extends Entity {
|
||||
|
||||
override minimapShow = false;
|
||||
override zIndex = 100;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.sprite = {
|
||||
height: 32 * 3,
|
||||
width: 32 * 3
|
||||
};
|
||||
}
|
||||
|
||||
override set(key: string, value: any) {
|
||||
super.set(key, value);
|
||||
if (key === "class") {
|
||||
this.sprite.filename = Paths.sprites + "/gameboard/"
|
||||
+ this["class"] + ".png";
|
||||
let filename = Paths.sprites + "/gameboard/" + this["class"] + ".png";
|
||||
this.imageSprite?.free();
|
||||
this.imageSprite = new ImageSprite(images.load(filename), 0, 0, 3*32, 3*32);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,28 +13,41 @@ import { RenderingContext2D } from "util/Types";
|
|||
import { MenuItem } from "../action/MenuItem";
|
||||
import { Entity } from "./Entity";
|
||||
import { Paths } from "../data/Paths";
|
||||
import { singletons } from "../SingletonRepo";
|
||||
|
||||
import { marauroa } from "marauroa"
|
||||
import { images } from "sprite/image/ImageManager";
|
||||
import { ImageSprite } from "sprite/image/ImageSprite";
|
||||
|
||||
export class Gate extends Entity {
|
||||
|
||||
override zIndex = 5000;
|
||||
private locked = false;
|
||||
|
||||
override init() {
|
||||
this.imageSprite?.free();
|
||||
this.imageSprite = new ImageSprite(
|
||||
images.load(Paths.sprites + "/doors/" + this["image"] + "_" + this["orientation"] + ".png"),
|
||||
0, 0, 0, 0);
|
||||
}
|
||||
|
||||
override set(key: string, value: any) {
|
||||
super.set(key, value);
|
||||
if (key === "resistance") {
|
||||
this["locked"] = parseInt(value, 10) !== 0;
|
||||
this.locked = parseInt(value, 10) !== 0;
|
||||
} else if (key === "image" || key === "orientation") {
|
||||
// Force re-evaluation of the sprite
|
||||
delete this["_image"];
|
||||
if (this.imageSprite) {
|
||||
this.imageSprite?.free();
|
||||
this.imageSprite = new ImageSprite(
|
||||
images.load(Paths.sprites + "/doors/" + this["image"] + "_" + this["orientation"] + ".png"),
|
||||
0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override buildActions(list: MenuItem[]) {
|
||||
var id = this["id"];
|
||||
list.push({
|
||||
title: (this["locked"]) ? "Open" : "Close",
|
||||
title: (this.locked) ? "Open" : "Close",
|
||||
action: function(_entity: Entity) {
|
||||
var action = {
|
||||
"type": "use",
|
||||
|
|
@ -47,19 +60,17 @@ export class Gate extends Entity {
|
|||
}
|
||||
|
||||
override draw(ctx: RenderingContext2D) {
|
||||
if (this._image == undefined) {
|
||||
var filename = Paths.sprites + "/doors/" + this["image"] + "_" + this["orientation"] + ".png";
|
||||
this._image = singletons.getSpriteStore().get(filename);
|
||||
}
|
||||
if (this._image.height) {
|
||||
var xOffset = -32 * Math.floor(this._image.width / 32 / 2);
|
||||
var height = this._image.height / 2;
|
||||
var yOffset = -32 * Math.floor(height / 32 / 2);
|
||||
var localX = this["_x"] * 32 + xOffset;
|
||||
var localY = this["_y"] * 32 + yOffset;
|
||||
var yStart = (this["locked"]) ? height : 0;
|
||||
ctx.drawImage(this._image, 0, yStart, this._image.width, height, localX, localY, this._image.width, height);
|
||||
let image = this.imageSprite?.imageRef?.image;
|
||||
if (!image) {
|
||||
return;
|
||||
}
|
||||
let xOffset = -32 * Math.floor(image.width / 32 / 2);
|
||||
let height = image.height / 2;
|
||||
let yOffset = -32 * Math.floor(height / 32 / 2);
|
||||
let localX = this["_x"] * 32 + xOffset;
|
||||
let localY = this["_y"] * 32 + yOffset;
|
||||
let yStart = (this.locked) ? height : 0;
|
||||
ctx.drawImage(image, 0, yStart, image.width, height, localX, localY, image.width, height);
|
||||
}
|
||||
|
||||
override isVisibleToAction(_filter: boolean) {
|
||||
|
|
|
|||
|
|
@ -16,11 +16,26 @@ import { Paths } from "../data/Paths";
|
|||
import { singletons } from "../SingletonRepo";
|
||||
|
||||
import { marauroa } from "marauroa"
|
||||
import { ImageSprite } from "sprite/image/ImageSprite";
|
||||
import { images } from "sprite/image/ImageManager";
|
||||
|
||||
|
||||
export class GrowingEntitySpawner extends Entity {
|
||||
override zIndex = 3000;
|
||||
|
||||
|
||||
override set(key: string, value: any) {
|
||||
super.set(key, value);
|
||||
if (key === "class") {
|
||||
this.imageSprite?.free();
|
||||
let className = value.replace(" ", "_");
|
||||
this.imageSprite = new ImageSprite(
|
||||
images.load(Paths.sprites + "/" + className + ".png"),
|
||||
0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* is this entity visible to a specific action
|
||||
*
|
||||
|
|
@ -50,30 +65,19 @@ export class GrowingEntitySpawner extends Entity {
|
|||
marauroa.clientFramework.sendAction(action);
|
||||
}
|
||||
|
||||
/**
|
||||
* draw RPEntities
|
||||
*/
|
||||
override draw(ctx: RenderingContext2D) {
|
||||
var localX = this["x"] * 32;
|
||||
var localY = this["y"] * 32;
|
||||
|
||||
// FIXME:
|
||||
// temporary fix, problem lies higher up
|
||||
// appears to only affect button_mushroom_grower
|
||||
// could be issue in marauroa
|
||||
let class_name = this["class"];
|
||||
if (class_name.includes(" ")) {
|
||||
class_name = class_name.replace(" ", "_");
|
||||
let localX = this["x"] * 32;
|
||||
let localY = this["y"] * 32;
|
||||
let image = this.imageSprite?.imageRef?.image;
|
||||
if (!image) {
|
||||
return;
|
||||
}
|
||||
|
||||
var image = singletons.getSpriteStore().get(Paths.sprites + "/" + class_name + ".png");
|
||||
if (image.height) { // image.complete is true on missing image files
|
||||
var count = parseInt(this["max_ripeness"], 10) + 1;
|
||||
var drawHeight = image.height / count;
|
||||
var yRow = this["ripeness"];
|
||||
ctx.drawImage(image, 0, yRow * drawHeight, image.width, drawHeight,
|
||||
let count = parseInt(this["max_ripeness"], 10) + 1;
|
||||
let drawHeight = image.height / count;
|
||||
let yRow = this["ripeness"];
|
||||
ctx.drawImage(image, 0, yRow * drawHeight, image.width, drawHeight,
|
||||
localX, localY - drawHeight + 32, image.width, drawHeight);
|
||||
}
|
||||
}
|
||||
|
||||
override getCursor(_x: number, _y: number) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue