Skip to content

Commit

Permalink
Added custom background image/color support
Browse files Browse the repository at this point in the history
  • Loading branch information
ClassicOldSong committed Jan 11, 2017
1 parent 01a444b commit 37ef16b
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 1,060 deletions.
2 changes: 1 addition & 1 deletion dist/main.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "K-Egg",
"version": "0.1.3",
"version": "0.1.4",
"description": "KarasamaEgg dynamic wallpaper for WallpaperEngine",
"main": "dist/main.min.js",
"scripts": {
Expand Down
51 changes: 37 additions & 14 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
'use strict'

import { info } from './debug.js'

import content from './main.html'
import ew from './res/egg-w.svg'
import ey from './res/egg-y.svg'
Expand All @@ -11,28 +10,21 @@ import './style/style.css'
// Set default properties
const props = {
fps: 0,
tg: 0
tg: 0,
color: 'rgb(79, 81, 120)',
img: ''
}

const $ = selector => document.querySelector(selector)

// Handle user properties
window.wallpaperPropertyListener = {
applyGeneralProperties(up) {
if (up.fps) {
props.fps = up.fps
props.tg = 1000 / up.fps
info('FPS limitation updated, current FPS limitation is', props.fps, 'timegap is', props.tg)
}
}
}

const init = () => {
// Remove the init listener
document.removeEventListener('DOMContentLoaded', init, false)

// Prepare the frying pan
$('body').insertAdjacentHTML('afterbegin', content)
const body = $('body')

body.insertAdjacentHTML('afterbegin', content)
const pr = window.devicePixelRatio || 1,
c = $('.egg'),
wW = window.innerWidth,
Expand Down Expand Up @@ -165,10 +157,41 @@ const init = () => {
}
wS = 1 + (lf / gap) / 2
yS = 1 + (hf / gap) / 2

// Start animation
start()
}

// Update background
const updateBg = () => {
body.style.backgroundColor = `rgb(${props.color})`
if (props.img) body.style.backgroundImage = `url(file:///${props.img})`
}
updateBg()

// Handle user properties
window.wallpaperPropertyListener = {
applyGeneralProperties(gp) {
if (gp.fps) {
props.fps = gp.fps
props.tg = 1000 / gp.fps
info('FPS limitation updated, current FPS limitation is', props.fps, 'timegap is', props.tg)
}
},
applyUserProperties(up) {
if (up.schemecolor) {
const colors = up.schemecolor.value.split(' ').map(val => Math.ceil(val * 255))
props.color = colors.join(', ')
info('Schemecolor updated, current value is', props.color)
}
if (up.image) {
props.img = up.image.value
info('Background image updated, current value is', props.img)
}
updateBg()
}
}

// Listen audio updates
window.wallpaperRegisterAudioListener(audioListener)

Expand Down
4 changes: 4 additions & 0 deletions src/style/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ html, body {
width: 100%;
overflow: hidden;
background-color: #4f5178;
background-position: center;
background-size: cover;
pading: 0;
margin: 0;
}

.egg {
Expand Down
2 changes: 1 addition & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>Karasama Egg</title>
<script src="./wpesmu.dev.js"></script>
<script src="./wpesmu.min.js"></script>
<script src="./main.dev.js"></script>
</head>
<body>
Expand Down
54 changes: 41 additions & 13 deletions test/main.dev.js

Large diffs are not rendered by default.

Loading

0 comments on commit 37ef16b

Please sign in to comment.