Skip to content

Commit 5980edf

Browse files
committed
chore: release v2.0.0-beta.36
1 parent dd7b104 commit 5980edf

File tree

8 files changed

+87
-42
lines changed

8 files changed

+87
-42
lines changed

packages/compiler/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@canvasengine/compiler",
3-
"version": "2.0.0-beta.35",
3+
"version": "2.0.0-beta.36",
44
"description": "",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "canvasengine",
3-
"version": "2.0.0-beta.35",
3+
"version": "2.0.0-beta.36",
44
"type": "module",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

packages/core/src/directives/Flash.ts

Lines changed: 74 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,20 @@ export class Flash extends Directive {
120120
return;
121121
}
122122

123-
// Store original values
124-
this.originalAlpha = flashProps.originalAlpha ?? instance.alpha ?? 1;
123+
// Store original values once at mount time
124+
// Only set if not already stored (to preserve values from first mount)
125+
if (this.originalAlpha === 1 && !flashProps.originalAlpha) {
126+
this.originalAlpha = instance.alpha ?? 1;
127+
} else if (flashProps.originalAlpha !== undefined) {
128+
this.originalAlpha = flashProps.originalAlpha;
129+
}
130+
125131
const currentTint = (instance as any).tint;
126-
this.originalTint = flashProps.originalTint ?? (isSignal(currentTint) ? currentTint() : currentTint) ?? 0xffffff;
132+
if (this.originalTint === 0xffffff && !flashProps.originalTint) {
133+
this.originalTint = (isSignal(currentTint) ? currentTint() : currentTint) ?? 0xffffff;
134+
} else if (flashProps.originalTint !== undefined) {
135+
this.originalTint = flashProps.originalTint;
136+
}
127137

128138
// Listen to trigger activation
129139
this.flashSubscription = on(flashProps.trigger, async (data) => {
@@ -157,18 +167,20 @@ export class Flash extends Directive {
157167
const flashProps = this.flashProps;
158168

159169
// Use data from trigger to override defaults if provided
160-
const type = data?.type ?? flashProps.type();
161-
const duration = data?.duration ?? flashProps.duration();
162-
const cycles = data?.cycles ?? flashProps.cycles();
163-
const flashAlpha = data?.alpha ?? flashProps.alpha();
164-
const flashTint = data?.tint ?? flashProps.tint();
170+
const type = data?.type ?? (typeof flashProps.type === 'function' ? flashProps.type() : flashProps.type);
171+
const duration = data?.duration ?? (typeof flashProps.duration === 'function' ? flashProps.duration() : flashProps.duration);
172+
const cycles = data?.cycles ?? (typeof flashProps.cycles === 'function' ? flashProps.cycles() : flashProps.cycles);
173+
const flashAlpha = data?.alpha ?? (typeof flashProps.alpha === 'function' ? flashProps.alpha() : flashProps.alpha);
174+
const flashTint = data?.tint ?? (typeof flashProps.tint === 'function' ? flashProps.tint() : flashProps.tint);
165175

166-
// Store original values if not already stored
167-
this.originalAlpha = flashProps.originalAlpha ?? instance.alpha ?? 1;
168-
const currentTint = (instance as any).tint;
169-
this.originalTint = flashProps.originalTint ?? (isSignal(currentTint) ? currentTint() : currentTint) ?? 0xffffff;
176+
// Stop any existing animation first
177+
if (this.progressSignal) {
178+
// Stop the animation immediately
179+
this.progressSignal.set(0, { duration: 0 });
180+
}
170181

171-
// Stop any existing animation and clean up
182+
// Clean up effects BEFORE restoring values
183+
// This prevents effects from continuing to update values after we restore
172184
if (this.alphaEffect) {
173185
this.alphaEffect.unsubscribe();
174186
this.alphaEffect = null;
@@ -178,12 +190,20 @@ export class Flash extends Directive {
178190
this.tintEffect = null;
179191
}
180192

181-
// Restore original values before starting new flash
193+
// Always restore to original values immediately after stopping effects
194+
// This ensures that if a new flash starts before the previous one completes,
195+
// we restore to the true original values, not the intermediate animation values
182196
instance.alpha = this.originalAlpha;
183-
if ((instance as any).tint !== undefined) {
197+
const currentTint = (instance as any).tint;
198+
if (currentTint !== undefined) {
184199
// Ensure originalTint is a primitive value, not a signal
185200
const tintValue = typeof this.originalTint === 'number' ? this.originalTint : 0xffffff;
186-
(instance as any).tint = tintValue;
201+
// Handle both signal and primitive tint
202+
if (isSignal(currentTint)) {
203+
currentTint.set(tintValue);
204+
} else {
205+
(instance as any).tint = tintValue;
206+
}
187207
}
188208

189209
// Call onStart callback
@@ -199,17 +219,17 @@ export class Flash extends Directive {
199219
};
200220

201221
// Create or recreate progress signal for flash animation
202-
if (this.progressSignal) {
203-
// Reset to 0 immediately without animation
204-
this.progressSignal.set(0, { duration: 0 });
205-
// Wait a bit to ensure the reset is complete
206-
await new Promise(resolve => setTimeout(resolve, 0));
207-
} else {
222+
// Note: We already stopped the previous animation above, so we can reuse the signal
223+
if (!this.progressSignal) {
208224
this.progressSignal = animatedSignal(0, {
209225
duration: duration,
210226
ease: (t) => t, // Linear ease
211227
});
212228
}
229+
// Reset to 0 immediately without animation to start fresh
230+
this.progressSignal.set(0, { duration: 0 });
231+
// Wait a bit to ensure the reset is complete before starting new animation
232+
await new Promise(resolve => setTimeout(resolve, 0));
213233

214234
// Create effect to update alpha based on progress
215235
if (type === 'alpha' || type === 'both') {
@@ -239,8 +259,14 @@ export class Flash extends Directive {
239259
if (type === 'tint' || type === 'both') {
240260
this.tintEffect = effect(() => {
241261
if (!instance || !this.progressSignal || !this.currentFlashConfig) return;
242-
if ((instance as any).tint === undefined) return;
243-
262+
263+
// Get current tint value - handle both signal and primitive
264+
const currentTint = (instance as any).tint;
265+
if (currentTint === undefined) return;
266+
267+
// Check if tint is a signal
268+
const tintIsSignal = isSignal(currentTint);
269+
244270
const progress = this.progressSignal();
245271
const config = this.currentFlashConfig;
246272

@@ -266,7 +292,14 @@ export class Flash extends Directive {
266292
const g = Math.round(g1 + (g2 - g1) * flashPhase);
267293
const b = Math.round(b1 + (b2 - b1) * flashPhase);
268294

269-
(instance as any).tint = (r << 16) | (g << 8) | b;
295+
const newTintValue = (r << 16) | (g << 8) | b;
296+
297+
// Handle both signal and primitive tint
298+
if (tintIsSignal) {
299+
currentTint.set(newTintValue);
300+
} else {
301+
(instance as any).tint = newTintValue;
302+
}
270303
}).subscription;
271304
}
272305

@@ -279,10 +312,16 @@ export class Flash extends Directive {
279312
// Restore original values
280313
if (instance) {
281314
instance.alpha = this.originalAlpha;
282-
if ((instance as any).tint !== undefined) {
315+
const currentTint = (instance as any).tint;
316+
if (currentTint !== undefined) {
283317
// Ensure originalTint is a primitive value, not a signal
284318
const tintValue = typeof this.originalTint === 'number' ? this.originalTint : 0xffffff;
285-
(instance as any).tint = tintValue;
319+
// Handle both signal and primitive tint
320+
if (isSignal(currentTint)) {
321+
currentTint.set(tintValue);
322+
} else {
323+
(instance as any).tint = tintValue;
324+
}
286325
}
287326
}
288327

@@ -344,10 +383,16 @@ export class Flash extends Directive {
344383
if (this.elementRef?.componentInstance) {
345384
const instance = this.elementRef.componentInstance;
346385
instance.alpha = this.originalAlpha;
347-
if ((instance as any).tint !== undefined) {
386+
const currentTint = (instance as any).tint;
387+
if (currentTint !== undefined) {
348388
// Ensure originalTint is a primitive value, not a signal
349389
const tintValue = typeof this.originalTint === 'number' ? this.originalTint : 0xffffff;
350-
(instance as any).tint = tintValue;
390+
// Handle both signal and primitive tint
391+
if (isSignal(currentTint)) {
392+
currentTint.set(tintValue);
393+
} else {
394+
(instance as any).tint = tintValue;
395+
}
351396
}
352397
}
353398

packages/core/src/engine/trigger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { effect, signal } from "@signe/reactive";
22

3-
interface Listen<T = any> {
3+
export interface Listen<T = any> {
44
config: T | undefined;
55
seed: {
66
config: T | undefined;
@@ -9,7 +9,7 @@ interface Listen<T = any> {
99
};
1010
}
1111

12-
interface Trigger<T = any> {
12+
export interface Trigger<T = any> {
1313
start: () => Promise<void>;
1414
listen: () => Listen<T> | undefined;
1515
}

packages/presets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@canvasengine/presets",
3-
"version": "2.0.0-beta.35",
3+
"version": "2.0.0-beta.36",
44
"type": "module",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

packages/tiled/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@canvasengine/tiled",
3-
"version": "2.0.0-beta.35",
3+
"version": "2.0.0-beta.36",
44
"description": "",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

sample/src/flash.ce

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@
7676
<Text text="Sprite Flash" x={0} y={-30} color="#ecf0f1" size="14" fontFamily="Arial" />
7777
<Sprite
7878
image="exp.png"
79-
width={80}
80-
height={80}
79+
width={800}
80+
height={800}
8181
flash={spriteFlashConfig}
8282
click={() => spriteFlashTrigger.start()}
8383
/>
@@ -180,7 +180,7 @@
180180
const spriteFlashConfig = {
181181
trigger: spriteFlashTrigger,
182182
type: 'tint',
183-
tint: 0xffff00, // Yellow flash
183+
tint: 0xff0000, // Yellow flash
184184
duration: 250
185185
};
186186

sample/src/shake.ce

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
<!-- Basic shake example -->
99
<Container x={100} y={100}>
1010
<Text text="Basic Shake" x={0} y={-30} color="#ecf0f1" size="14" fontFamily="Arial" />
11-
<Rect
12-
color="#e74c3c"
13-
width={80}
14-
height={80}
11+
<Sprite
12+
image="exp.png"
13+
width={200}
14+
height={200}
1515
borderRadius={8}
1616
shake={shakeConfig}
1717
click={() => shakeTrigger.start()}

0 commit comments

Comments
 (0)