Commit 85dd5d76 authored by Grant's avatar Grant
Browse files

Merge branch 'improve_stack_gain' into 'main'

Improve handling of the user pixel stack

See merge request sc07/canvas!8
parents c2fba721 5a444461
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ const getTimeLeft = (pixels: { available: number }, config: ClientConfig) => {
  const cooldown = CanvasLib.getPixelCooldown(pixels.available + 1, config);
  const pixelExpiresAt =
    Canvas.instance?.lastPlace && Canvas.instance.lastPlace + cooldown * 1000;
  
  const pixelCooldown = pixelExpiresAt && (Date.now() - pixelExpiresAt) / 1000;

  if (!pixelCooldown) return undefined;
@@ -43,7 +44,7 @@ const PlaceCountdown = () => {
  return (
    <>
      {timeLeft
        ? pixels.available + 1 < config.canvas.pixel.maxStack && timeLeft + "s"
        ? pixels.available < config.canvas.pixel.maxStack && timeLeft + "s"
        : ""}
    </>
  );
+6 −4
Original line number Diff line number Diff line
@@ -53,11 +53,9 @@ export class Canvas extends EventEmitter<CanvasEvents> {
    this.PanZoom.addListener("click", this.handleMouseDown.bind(this));
    this.PanZoom.addListener("longPress", this.handleLongPress);

    Network.waitForState("pixelLastPlaced").then(
      ([time]) => (this.lastPlace = time)
    );
    Network.on("pixel", this.handlePixel);
    Network.on("square", this.handleSquare);
    Network.on("pixelLastPlaced", this.handlePixelLastPlaced);
  }

  destroy() {
@@ -70,6 +68,7 @@ export class Canvas extends EventEmitter<CanvasEvents> {

    Network.off("pixel", this.handlePixel);
    Network.off("square", this.handleSquare);
    Network.off("pixelLastPlaced", this.handlePixelLastPlaced);
  }

  /**
@@ -309,6 +308,10 @@ export class Canvas extends EventEmitter<CanvasEvents> {
    getRenderer().usePixel({ x, y, hex: palette?.hex || "null" });
  };

  handlePixelLastPlaced = (time: number) => {
    this.lastPlace = time;
  };

  Pallete = {
    getColor: (colorId: number) => {
      return this.config.pallete.colors.find((c) => c.id === colorId);
@@ -358,7 +361,6 @@ export class Canvas extends EventEmitter<CanvasEvents> {
      )
      .then((ack) => {
        if (ack.success) {
          this.lastPlace = Date.now();
          this.handlePixel(ack.data);
        } else {
          console.warn(
+1 −1
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ Table User {
  display_name String
  picture_url String
  profile_url String
  lastPixelTime DateTime [default: `now()`, not null]
  lastTimeGainStarted DateTime [default: `now()`, not null]
  pixelStack Int [not null, default: 0]
  undoExpires DateTime
  isAdmin Boolean [not null, default: false]
+1 −0
Original line number Diff line number Diff line
ALTER TABLE "User" RENAME COLUMN "lastPixelTime" TO "lastTimeGainStarted";
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ model User {
  picture_url  String?
  profile_url  String?

  lastPixelTime DateTime  @default(now()) // the time the last pixel was placed at
  lastTimeGainStarted DateTime  @default(now()) // the time base used to determine the amount of stack the user should gain
  pixelStack    Int       @default(0) // amount of pixels stacked for this user
  undoExpires   DateTime? // when the undo for the most recent pixel expires at

Loading