-
Notifications
You must be signed in to change notification settings - Fork 662
Night Mode #2364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kkissdev
wants to merge
20
commits into
openfrontio:main
Choose a base branch
from
kkissdev:flashlight-mode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Night Mode #2364
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
9eee198
Implemented usersettings; Partially Implemented GameRenderer.ts; Star…
kkissdev 1159b47
First finish
kkissdev 8a0d5c7
Fixed flashlight mode; Added to settings
kkissdev 927a76f
Added user text
kkissdev fb0bdd6
Fixed flashlight performance issues
kkissdev dfb8d17
Fixed directory confusion
kkissdev b48a247
Fixed Canvas Alignment issue
kkissdev ee8bb56
Fixed event payload
kkissdev d39731f
Added Night Mode Logo
kkissdev 02d27cf
Added All Tests
kkissdev 45437d2
Changed coderabbitais profile
kkissdev b081f3b
Changed coderabbitais profile
kkissdev d688bb0
Merge branch 'main' into flashlight-mode
kkissdev 195ad4d
Fixed testing issues
sysrex c0b6d30
Fixed naming issue
kkissdev f2d3bac
City glow
kkissdev 3e635d1
.
kkissdev 3ce8b77
.
kkissdev 0ca18d1
.
kkissdev 865a64a
Merge branch 'main' into flashlight-mode
kkissdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| reviews: | ||
| profile: assertive |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| //import { GameView } from "../../../core/game/GameView"; | ||
| import { UserSettings } from "../../../core/game/UserSettings"; | ||
| import { TransformHandler } from "../TransformHandler"; | ||
| import { Layer } from "./Layer"; | ||
|
|
||
| export class NightModeLayer implements Layer { | ||
| private darkenColor: [number, number, number] = [0, 0, 0]; | ||
| private darkenAlpha: number = 0.8; // separated from darkenColor for more readable code | ||
|
|
||
| private flashlightRadius: number = 50; // in-game tiles | ||
|
|
||
| private userSettingsInstance = new UserSettings(); | ||
|
|
||
| private mouseX: number = 0; | ||
| private mouseY: number = 0; | ||
| private handleMouseMove(event: MouseEvent) { | ||
| const rect = this.transformHandler.boundingRect(); | ||
| this.mouseX = event.clientX - rect.left; | ||
| this.mouseY = event.clientY - rect.top; | ||
| } | ||
|
|
||
| init(): void {} | ||
| tick(): void {} | ||
| redraw(): void {} | ||
|
|
||
| constructor(private transformHandler: TransformHandler) { | ||
| if (this.userSettingsInstance.nightMode()) { | ||
| document.documentElement.classList.add("night"); | ||
| } else { | ||
| document.documentElement.classList.remove("night"); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| document.addEventListener("mousemove", (e) => this.handleMouseMove(e)); | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| renderLayer(context: CanvasRenderingContext2D): void { | ||
| if (!this.userSettingsInstance.nightMode()) return; | ||
|
|
||
| const width = this.transformHandler.width(); | ||
| const height = this.transformHandler.boundingRect().height; | ||
| const cellSize = this.transformHandler.scale; | ||
|
|
||
| // Fill the entire screen with dark | ||
| context.fillStyle = `rgba(${this.darkenColor[0]}, ${this.darkenColor[1]}, ${this.darkenColor[2]}, ${this.darkenAlpha})`; | ||
| context.fillRect(0, 0, width, height); | ||
|
|
||
| const startX = | ||
| Math.floor( | ||
| Math.max(this.mouseX - this.flashlightRadius * cellSize, 0) / cellSize, | ||
| ) * cellSize; | ||
| const endX = | ||
| Math.ceil( | ||
| Math.min(this.mouseX + this.flashlightRadius * cellSize, width) / | ||
| cellSize, | ||
| ) * cellSize; | ||
|
|
||
| const startY = | ||
| Math.floor( | ||
| Math.max(this.mouseY - this.flashlightRadius * cellSize, 0) / cellSize, | ||
| ) * cellSize; | ||
| const endY = | ||
| Math.ceil( | ||
| Math.min(this.mouseY + this.flashlightRadius * cellSize, height) / | ||
| cellSize, | ||
| ) * cellSize; | ||
|
|
||
| for (let y = startY; y < endY; y += cellSize) { | ||
| for (let x = startX; x < endX; x += cellSize) { | ||
| // distance from mouse in tile units | ||
| const dist = Math.hypot( | ||
| (this.mouseX - (x + cellSize / 2)) / cellSize, | ||
| (this.mouseY - (y + cellSize / 2)) / cellSize, | ||
| ); | ||
|
|
||
| // Determine brightness factor (adjust 3 for flashlight size) | ||
| const brightness = Math.max(0, 1 - dist / this.flashlightRadius); | ||
|
|
||
| if (brightness > 0) { | ||
| context.fillStyle = `rgba(200,200,130,${(this.darkenAlpha / 2) * brightness})`; | ||
| context.fillRect(x, y, cellSize, cellSize); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.