import { create_svg_element } from "./svg.js";
import { card_href, FIFTY_TWO_CARD_DECK } from "./card.js";
-import { random_int } from "./random.js";
+import { random_float, random_bool, random_sign } from "./random.js";
+
+class CardWave {
+ constructor(svg, speed, height, slope, card_backs, initial_time) {
+ this.svg = svg;
+ this.timestep = 10;
+ this.speed = speed;
+ this.height = height;
+ this.slope = slope;
+ this.completed = false;
+
+ if (card_backs) {
+ this.cards = [...FIFTY_TWO_CARD_DECK].map(card => this.card_image(null));
+ } else {
+ this.cards = [...FIFTY_TWO_CARD_DECK].map(card => this.card_image(card));
+ }
+
+ this.schedule_frame(initial_time);
+ }
+
+ card_image(card) {
+ return create_svg_element(this.svg, card === null ? "image" : "use", [], [["width", "45"], ["height", "70"], ["x", "-100"], ["y", "215"], ["href", card_href(card)]]);
+ }
+
+ schedule_frame(time) {
+ this.render(time);
+ if (!this.completed) {
+ setTimeout(() => this.schedule_frame(time + this.timestep), this.timestep);
+ }
+ }
+
+ render(time) {
+ let x = time;
+ const initial_offset = this.speed > 0 ? -100 : 2100;
+ for (const card of this.cards) {
+ card.setAttribute("x", x * this.speed + initial_offset);
+ card.setAttribute("y", Math.sin(x * this.speed / this.slope) * this.height + 215);
+ x -= 40;
+ }
+ if (x > 2200 / Math.abs(this.speed)) {
+ this.completed = true;
+ for (const card of this.cards) {
+ this.svg.removeChild(card);
+ }
+ }
+ }
+}
export class SplashScreen {
constructor(container) {
this.svg = create_svg_element(container, "svg", ["splash-screen"], [["viewBox", "0 0 2000 500"]]);
this.hidden = false;
- this.upper_bar = create_svg_element(this.svg, "rect", ["splash-upper-bar"], [["x", "0"], ["y", "0"], ["width", "2000"], ["height", "100"], ["fill", "blue"]]);
- this.banner = create_svg_element(this.svg, "rect", [], [["x", "0"], ["y", "100"], ["width", "2000"], ["height", "300"], ["fill", "skyblue"]]);
- this.lower_bar = create_svg_element(this.svg, "rect", ["splash-lower-bar"], [["x", "0"], ["y", "400"], ["width", "2000"], ["height", "100"], ["fill", "blue"]]);
+ this.upper_bar = create_svg_element(this.svg, "rect", ["splash-upper-bar"], [["x", "0"], ["y", "-10"], ["width", "2000"], ["height", "105"], ["fill", "#000064"], ["stroke", "skyblue"], ["stroke-width", "4px"]]);
+ this.banner = create_svg_element(this.svg, "rect", [], [["x", "0"], ["y", "90"], ["width", "2000"], ["height", "320"], ["fill", "skyblue"]]);
+ this.lower_bar = create_svg_element(this.svg, "rect", ["splash-lower-bar"], [["x", "0"], ["y", "405"], ["width", "2000"], ["height", "105"], ["fill", "#000064"], ["stroke", "skyblue"], ["stroke-width", "4px"]]);
+
+ this.wave_group = create_svg_element(this.svg, "g", [], []);
this.logo = create_svg_element(this.svg, "text", ["splash-logo"], [["x", "1000"], ["y", "250"]]);
this.logo_text = document.createTextNode("POKERWAVE");
this.logo.append(this.logo_text);
this.svg.onclick = () => this.hide();
+ this.waves = [];
+ this.card_wave(2000);
+ this.schedule_card_wave(2000);
+ }
+
+ card_wave(time) {
+ this.waves = this.waves.filter(wave => !wave.completed);
+ this.waves.push(new CardWave(this.wave_group, random_float(0.4, 0.7) * random_sign(), random_float(50, 200), random_float(50, 200), random_bool(0.3), time));
+ }
+
+ schedule_card_wave(time) {
+ if (!this.hidden) {
+ this.card_wave(time);
+ setTimeout(() => this.schedule_card_wave(0), 1500);
+ }
}
hide() {