Clock improvements
- Use SVGs for sun/moon/weather - Respect configuration for showing time of day - Improve styling for digital clock on its own - Remove old clock images
@ -147,11 +147,13 @@ function buildComponents(response: any): DynmapComponentConfig {
|
|||||||
components.clockControl = {
|
components.clockControl = {
|
||||||
showDigitalClock: true,
|
showDigitalClock: true,
|
||||||
showWeather: false,
|
showWeather: false,
|
||||||
|
showTimeOfDay: false,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "timeofdayclock":
|
case "timeofdayclock":
|
||||||
components.clockControl = {
|
components.clockControl = {
|
||||||
|
showTimeOfDay: true,
|
||||||
showDigitalClock: component.showdigitalclock || false,
|
showDigitalClock: component.showdigitalclock || false,
|
||||||
showWeather: component.showweather || false,
|
showWeather: component.showweather || false,
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 5.0 KiB |
Before Width: | Height: | Size: 4.9 KiB |
Before Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 905 B |
Before Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 627 B |
Before Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 2.8 KiB |
@ -2,7 +2,15 @@ import {ControlOptions, DomUtil, Util, Map, Control} from 'leaflet';
|
|||||||
import Utils from '@/util';
|
import Utils from '@/util';
|
||||||
import {DynmapWorldState} from "@/dynmap";
|
import {DynmapWorldState} from "@/dynmap";
|
||||||
|
|
||||||
|
import sun from '@/assets/icons/clock_sun.svg';
|
||||||
|
import sunRain from '@/assets/icons/clock_sun_rain.svg';
|
||||||
|
import sunStorm from '@/assets/icons/clock_sun_storm.svg';
|
||||||
|
import moon from '@/assets/icons/clock_moon.svg';
|
||||||
|
import moonRain from '@/assets/icons/clock_moon_rain.svg';
|
||||||
|
import moonStorm from '@/assets/icons/clock_moon_storm.svg';
|
||||||
|
|
||||||
export interface ClockControlOptions extends ControlOptions {
|
export interface ClockControlOptions extends ControlOptions {
|
||||||
|
showTimeOfDay: boolean;
|
||||||
showDigitalClock: boolean;
|
showDigitalClock: boolean;
|
||||||
showWeather: boolean;
|
showWeather: boolean;
|
||||||
}
|
}
|
||||||
@ -15,7 +23,6 @@ export class ClockControl extends Control {
|
|||||||
private _sun?: HTMLElement;
|
private _sun?: HTMLElement;
|
||||||
private _moon?: HTMLElement;
|
private _moon?: HTMLElement;
|
||||||
private _clock?: HTMLElement;
|
private _clock?: HTMLElement;
|
||||||
private _weather?: HTMLElement;
|
|
||||||
|
|
||||||
constructor(options: ClockControlOptions) {
|
constructor(options: ClockControlOptions) {
|
||||||
super(Object.assign(options, {position: 'topcenter'}));
|
super(Object.assign(options, {position: 'topcenter'}));
|
||||||
@ -24,19 +31,28 @@ export class ClockControl extends Control {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onAdd(map: Map) {
|
onAdd(map: Map) {
|
||||||
this._container = DomUtil.create('div', 'largeclock timeofday');
|
const digital = !this.options.showTimeOfDay && !this.options.showWeather && this.options.showDigitalClock;
|
||||||
this._sun = DomUtil.create('div', 'timeofday sun', this._container);
|
|
||||||
this._moon = DomUtil.create('div', 'timeofday moon', this._sun);
|
|
||||||
|
|
||||||
this._sun.style.backgroundPosition = (-150) + 'px ' + (-150) + 'px';
|
this._container = DomUtil.create('div', 'clock' + (digital ? ' clock--digital' : ''));
|
||||||
this._moon.style.backgroundPosition = (-150) + 'px ' + (-150) + 'px';
|
this._sun = DomUtil.create('div', 'clock__sun', this._container);
|
||||||
|
this._moon = DomUtil.create('div', 'clock__moon', this._container);
|
||||||
|
|
||||||
|
this._sun.style.transform = 'translate(-150px, -150px)';
|
||||||
|
this._moon.style.transform = 'translate(-150px, -150px)';
|
||||||
|
|
||||||
|
console.log(sun);
|
||||||
|
|
||||||
|
this._sun!.innerHTML = `
|
||||||
|
<svg class="svg-icon" viewBox="${sun.viewBox}">
|
||||||
|
<use xlink:href="${sun.url}" />
|
||||||
|
</svg>`;
|
||||||
|
this._moon!.innerHTML = `
|
||||||
|
<svg class="svg-icon" viewBox="${moon.viewBox}">
|
||||||
|
<use xlink:href="${moon.url}" />
|
||||||
|
</svg>`;
|
||||||
|
|
||||||
if (this.options.showDigitalClock) {
|
if (this.options.showDigitalClock) {
|
||||||
this._clock = DomUtil.create('div', 'timeofday digitalclock', this._container)
|
this._clock = DomUtil.create('div', 'clock__time', this._container)
|
||||||
}
|
|
||||||
|
|
||||||
if (this.options.showWeather) {
|
|
||||||
this._weather = DomUtil.create('div', 'weather', this._container)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._container;
|
return this._container;
|
||||||
@ -64,11 +80,11 @@ export class ClockControl extends Control {
|
|||||||
const moonAngle = sunAngle + Math.PI;
|
const moonAngle = sunAngle + Math.PI;
|
||||||
|
|
||||||
if (timeOfDay >= 0) {
|
if (timeOfDay >= 0) {
|
||||||
this._sun!.style.backgroundPosition = (-50 * Math.cos(sunAngle)) + 'px ' + (-50 * Math.sin(sunAngle)) + 'px';
|
this._sun!.style.transform = 'translate(' + Math.round(-50 * Math.cos(sunAngle)) + 'px, ' + Math.round(-50 * Math.sin(sunAngle)) + 'px)';
|
||||||
this._moon!.style.backgroundPosition = (-50 * Math.cos(moonAngle)) + 'px ' + (-50 * Math.sin(moonAngle)) + 'px';
|
this._moon!.style.transform = 'translate(' + Math.round(-50 * Math.cos(moonAngle)) + 'px, ' + Math.round(-50 * Math.sin(moonAngle)) + 'px)';
|
||||||
} else {
|
} else {
|
||||||
this._sun!.style.backgroundPosition = '-150px -150px';
|
this._sun!.style.transform = 'translate(-150px, -150px)';
|
||||||
this._moon!.style.backgroundPosition = '-150px -150px';
|
this._moon!.style.transform = 'translate(-150px, -150px)';
|
||||||
}
|
}
|
||||||
|
|
||||||
const minecraftTime = Utils.getMinecraftTime(timeOfDay);
|
const minecraftTime = Utils.getMinecraftTime(timeOfDay);
|
||||||
@ -85,20 +101,35 @@ export class ClockControl extends Control {
|
|||||||
this._clock!.textContent = '';
|
this._clock!.textContent = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.options.showWeather) {
|
if (this.options.showWeather) {
|
||||||
const dayNight = (timeOfDay > 23100 || timeOfDay < 12900) ? "day" : "night";
|
if (worldState.thundering) {
|
||||||
let className = 'sunny';
|
this._sun!.innerHTML = `
|
||||||
|
<svg class="svg-icon" viewBox="${sunStorm.viewBox}">
|
||||||
if (worldState.raining) {
|
<use xlink:href="${sunStorm.url}" />
|
||||||
className = 'stormy';
|
</svg>`;
|
||||||
|
this._moon!.innerHTML = `
|
||||||
if (worldState.thundering) {
|
<svg class="svg-icon" viewBox="${moonStorm.viewBox}">
|
||||||
className = 'thunder';
|
<use xlink:href="${moonStorm.url}" />
|
||||||
}
|
</svg>`;
|
||||||
|
} else if (worldState.raining) {
|
||||||
|
this._sun!.innerHTML = `
|
||||||
|
<svg class="svg-icon" viewBox="${sunRain.viewBox}">
|
||||||
|
<use xlink:href="${sunRain.url}" />
|
||||||
|
</svg>`;
|
||||||
|
this._moon!.innerHTML = `
|
||||||
|
<svg class="svg-icon" viewBox="${moonRain.viewBox}">
|
||||||
|
<use xlink:href="${moonRain.url}" />
|
||||||
|
</svg>`;
|
||||||
|
} else {
|
||||||
|
this._sun!.innerHTML = `
|
||||||
|
<svg class="svg-icon" viewBox="${sun.viewBox}">
|
||||||
|
<use xlink:href="${sun.url}" />
|
||||||
|
</svg>`;
|
||||||
|
this._moon!.innerHTML = `
|
||||||
|
<svg class="svg-icon" viewBox="${moon.viewBox}">
|
||||||
|
<use xlink:href="${moon.url}" />
|
||||||
|
</svg>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._weather?.classList.remove('stormy_day', 'stormy_night', 'sunny_day', 'sunny_night', 'thunder_day', 'thunder_night');
|
|
||||||
this._weather?.classList.add(`${className}_${dayNight}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -122,25 +122,34 @@ button {
|
|||||||
border-radius: 0 0 3px 3px;
|
border-radius: 0 0 3px 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.largeclock {
|
.clock {
|
||||||
@extend %panel;
|
@extend %panel;
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 15rem;
|
width: 15rem;
|
||||||
height: 6rem;
|
height: 6rem;
|
||||||
z-index: 50;
|
z-index: 50;
|
||||||
|
font-family: monospace;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0.5rem 2rem;
|
||||||
|
|
||||||
.digitalclock {
|
.clock__time {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
line-height: 2rem;
|
line-height: 2rem;
|
||||||
font-weight: bold;
|
margin-top: auto;
|
||||||
|
background-color: #222;
|
||||||
|
z-index: 1;
|
||||||
|
padding: 0.1rem 0.1rem 0;
|
||||||
|
border-radius: 0.3rem;
|
||||||
|
|
||||||
&.night {
|
&.night {
|
||||||
color: #dff;
|
color: #ddffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.day {
|
&.day {
|
||||||
color: #fd3;
|
color: #ffdd33;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.night, &.day {
|
&.night, &.day {
|
||||||
@ -148,59 +157,33 @@ button {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.timeofday {
|
.clock__sun,
|
||||||
background-repeat: no-repeat;
|
.clock__moon {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
|
|
||||||
&.digitalclock {
|
svg {
|
||||||
top: auto;
|
width: 15rem;
|
||||||
bottom: 0.5rem;
|
height: 12rem;
|
||||||
}
|
|
||||||
|
|
||||||
&.sun {
|
|
||||||
background-image: url(../assets/images/sun.png);
|
|
||||||
}
|
|
||||||
|
|
||||||
&.moon {
|
|
||||||
background-image: url(../assets/images/moon.png);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.weather {
|
&.clock--digital {
|
||||||
position: absolute;
|
justify-content: center;
|
||||||
top: 5px;
|
height: 5rem;
|
||||||
right: 0;
|
width: auto;
|
||||||
width: 32px;
|
|
||||||
height: 32px;
|
|
||||||
display: block;
|
|
||||||
background-repeat: no-repeat;
|
|
||||||
|
|
||||||
&.sunny_day {
|
.clock__sun,
|
||||||
background-image: url(../assets/images/weather_sunny_day.png);
|
.clock__moon {
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.stormy_day {
|
.clock__time {
|
||||||
background-image: url(../assets/images/weather_stormy_day.png);
|
margin: 0;
|
||||||
}
|
font-size: 3rem;
|
||||||
|
|
||||||
&.thunder_day {
|
|
||||||
background-image: url(../assets/images/weather_thunder_day.png);
|
|
||||||
}
|
|
||||||
|
|
||||||
&.sunny_night {
|
|
||||||
background-image: url(../assets/images/weather_sunny_night.png);
|
|
||||||
}
|
|
||||||
|
|
||||||
&.stormy_night {
|
|
||||||
background-image: url(../assets/images/weather_stormy_night.png);
|
|
||||||
}
|
|
||||||
|
|
||||||
&.thunder_night {
|
|
||||||
background-image: url(../assets/images/weather_thunder_night.png);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|