UNPKG

raingame

Version:
108 lines (107 loc) 4.59 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Card = void 0; var StandardObject_1 = require("./StandardObject"); var Card = /** @class */ (function (_super) { __extends(Card, _super); function Card(settings) { var _this = _super.call(this, settings) || this; _this.borderColor = "#000"; _this.border = false; _this.borderRadius = settings.borderRadius ? settings.borderRadius : 0; _this.text = settings.text ? settings.text : ""; _this.active = false; if (settings.borderColor) { _this.borderColor = settings.borderColor; } if (settings.border) { _this.border = settings.border; } _this.type = "Card"; return _this; } Card.prototype.render = function (ctx, renderTarget) { var xg = 0, yg = 0; if (renderTarget.type === "SceneGroup") { xg = renderTarget.position.x; yg = renderTarget.position.y; } var x = this.position.x + xg; var y = this.position.y + yg; var borderRadius = this.borderRadius; var h = this.height; var w = this.width; var position = [ [borderRadius + x, y], [w + x - borderRadius, y], [w + x, y + borderRadius], [w + x, y + h - borderRadius], [w + x - borderRadius, y + h], [x + borderRadius, y + h], [x, y + h - borderRadius], [x, y + borderRadius] ]; var point = [ [x + w, y], [x + w, y + h], [x, y + h], [x, y] ]; var textPosition = [x + borderRadius, y + 3 * borderRadius]; if (this.material) { ctx.drawImage(this.material.image, this.material.start, this.material.end, this.material.width, this.material.height, x, y, w, h); } else { ctx.fillStyle = "#fff"; // console.log(position,point,textPosition); ctx.beginPath(); ctx.moveTo(position[0][0], position[0][1]); ctx.lineTo(position[1][0], position[1][1]); ctx.quadraticCurveTo(point[0][0], point[0][1], position[2][0], position[2][1]); ctx.lineTo(position[3][0], position[3][1]); ctx.quadraticCurveTo(point[1][0], point[1][1], position[4][0], position[4][1]); ctx.lineTo(position[5][0], position[5][1]); ctx.quadraticCurveTo(point[2][0], point[2][1], position[6][0], position[6][1]); ctx.lineTo(position[7][0], position[7][1]); ctx.quadraticCurveTo(point[3][0], point[3][1], position[0][0], position[0][1]); ctx.fill(); ctx.closePath(); } if (this.border) { ctx.strokeStyle = this.borderColor; ctx.beginPath(); ctx.moveTo(position[0][0], position[0][1]); ctx.lineTo(position[1][0], position[1][1]); ctx.quadraticCurveTo(point[0][0], point[0][1], position[2][0], position[2][1]); ctx.lineTo(position[3][0], position[3][1]); ctx.quadraticCurveTo(point[1][0], point[1][1], position[4][0], position[4][1]); ctx.lineTo(position[5][0], position[5][1]); ctx.quadraticCurveTo(point[2][0], point[2][1], position[6][0], position[6][1]); ctx.lineTo(position[7][0], position[7][1]); ctx.quadraticCurveTo(point[3][0], point[3][1], position[0][0], position[0][1]); ctx.stroke(); ctx.closePath(); } if (this.text) { ctx.fillStyle = "#000"; ctx.font = "32px bold"; ctx.fillText(this.text, textPosition[0], textPosition[1]); } }; Card.prototype.onClick = function (event) { }; return Card; }(StandardObject_1.StandardObject)); exports.Card = Card;