Comparing version 1.0.2 to 1.0.3
@@ -38,2 +38,3 @@ import * as utils from './utils' | ||
this.instancesObj[this.defaultLayer] = [] | ||
this.instancesReactionArr = [] | ||
this.utils = utils | ||
@@ -121,2 +122,16 @@ this.customVariable = {} | ||
triggerReaction(x, y) { | ||
let calX = x | ||
let calY = y | ||
if (this.highResolution) { | ||
calX *= 2 | ||
calY *= 2 | ||
} | ||
this.instancesReactionArr.forEach((i) => { | ||
if (!i.visible) return | ||
if (calX >= i.x && calX<= i.x + i.width && calY >= i.y && calY<= i.y + i.height) { | ||
i.trigger(i, this) | ||
} | ||
}) | ||
} | ||
@@ -278,2 +293,9 @@ addAudio(name, src, retry = 0) { | ||
}) | ||
this.instancesReactionArr.forEach((i) => { | ||
if (!i.visible) return | ||
this.ctx.strokeStyle = 'red' | ||
this.ctx.beginPath() | ||
this.ctx.rect(i.x, i.y, i.width, i.height) | ||
this.ctx.stroke() | ||
}) | ||
} | ||
@@ -414,2 +436,3 @@ | ||
this.instancesObj[layer].push(instance) | ||
if (instance.trigger) this.instancesReactionArr.push(instance) | ||
} | ||
@@ -422,4 +445,8 @@ | ||
removeInstance(name, layer = this.defaultLayer) { | ||
if (this.getInstance(name, layer)) { | ||
const instance = this.getInstance(name, layer) | ||
if (instance) { | ||
this.instancesObj[layer] = this.instancesObj[layer].filter(i => i.name !== name) | ||
if (instance.trigger) { | ||
this.instancesReactionArr = this.instancesReactionArr.filter(i => i.name !== name) | ||
} | ||
} | ||
@@ -426,0 +453,0 @@ } |
export default class Instance { | ||
constructor(option = {}) { | ||
const { name, painter, action } = option | ||
const { name, painter, action, trigger } = option | ||
this.name = name | ||
@@ -16,2 +16,3 @@ this.x = 0 | ||
this.action = action || null | ||
this.trigger = trigger || null | ||
this.ready = false | ||
@@ -18,0 +19,0 @@ } |
{ | ||
"name": "cooljs", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "cooljs", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "echo ok" | ||
}, | ||
@@ -9,0 +9,0 @@ "repository": { |
@@ -1,1 +0,2 @@ | ||
# cool javascript | ||
# cool javascript | ||
@@ -1,2 +0,2 @@ | ||
export const getCurrentTime = () => (+new Date()) | ||
export const getCurrentTime = () => (performance.now() * 1000) | ||
@@ -3,0 +3,0 @@ export const random = (min, max) => (Math.random() * (max - min)) + min |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
17089
610
0
3