diff --git a/src/actions/index.js b/src/actions/index.js index 9605af2..ed8e68b 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -444,10 +444,12 @@ export function preLoadedBigChunk( export function receiveBigChunk( center: Cell, + chunk: Uint8Array, ): Action { return { type: 'RECEIVE_BIG_CHUNK', center, + chunk, }; } diff --git a/src/actions/types.js b/src/actions/types.js index 88c37f8..bbd96e4 100644 --- a/src/actions/types.js +++ b/src/actions/types.js @@ -51,7 +51,7 @@ export type Action = | { type: 'SET_SCALE', scale: number, zoompoint: Cell } | { type: 'REQUEST_BIG_CHUNK', center: Cell } | { type: 'PRE_LOADED_BIG_CHUNK', center: Cell } - | { type: 'RECEIVE_BIG_CHUNK', center: Cell } + | { type: 'RECEIVE_BIG_CHUNK', center: Cell, chunk: Uint8Array } | { type: 'RECEIVE_BIG_CHUNK_FAILURE', center: Cell, error: Error } | { type: 'RECEIVE_PIXEL_UPDATE', i: number, diff --git a/src/client.js b/src/client.js index 8238e77..f0dde8d 100644 --- a/src/client.js +++ b/src/client.js @@ -5,7 +5,6 @@ import fetch from 'isomorphic-fetch'; // TODO put in the beggining with webpack! import './styles/font.css'; -// import initAds, { requestAds } from './ui/ads'; import onKeyPress from './controls/keypress'; import { receivePixelUpdate, diff --git a/src/store/ads.js b/src/store/ads.js deleted file mode 100644 index 5dfe9b1..0000000 --- a/src/store/ads.js +++ /dev/null @@ -1,27 +0,0 @@ -/** - * - * Copyright 2017 Google Inc. All Rights Reserved. - * You may study, modify, and use this example for any purpose. - * Note that this example is provided "as is", WITHOUT WARRANTY - * of any kind either expressed or implied. - * - * @flow - */ - -import { playAd } from '../ui/ads'; - - -export default () => (next) => (action) => { - switch (action.type) { - case 'PLACE_PIXEL': { - // wait 1 second - setTimeout(playAd, 300); - break; - } - - default: - // nothing - } - - return next(action); -}; diff --git a/src/store/configureStore.js b/src/store/configureStore.js index 1ac4f8c..df4691e 100644 --- a/src/store/configureStore.js +++ b/src/store/configureStore.js @@ -14,6 +14,7 @@ import array from './array'; import promise from './promise'; import notifications from './notifications'; import title from './title'; +import extensions from './extensions'; import reducers from '../reducers'; @@ -39,7 +40,7 @@ const store = createStore( title, protocolClientHook, rendererHook, - // ads, + extensions, logger, ), ), diff --git a/src/store/extensions.js b/src/store/extensions.js new file mode 100644 index 0000000..83d83ab --- /dev/null +++ b/src/store/extensions.js @@ -0,0 +1,63 @@ +/* + * sends events via window.pixelPlanetEvents to potential + * Extensions and Userscripts + * + * @flow + */ + +import EventEmitter from 'events'; + +const pixelPlanetEvents = new EventEmitter(); + +export default () => (next) => (action) => { + switch (action.type) { + case 'SELECT_CANVAS': { + pixelPlanetEvents.emit('selectcanvas', action.canvasId); + break; + } + + case 'SET_VIEW_COORDINATES': { + /* + * view: [x, y] float canvas coordinates of the center of the screen, + */ + pixelPlanetEvents.emit('setviewcoordinates', action.view); + break; + } + + case 'SET_HOVER': { + /* + * hover: [x, y] integer canvas coordinates of cursor + * just used on 2D canvas + */ + pixelPlanetEvents.emit('sethover', action.hover); + break; + } + + case 'SET_SCALE': { + /* + * scale: float of canvas scale aka zoom + * (not logarithmic, doesn't clamp to 1.0) + * zoompoint: center of scaling + */ + const { scale, zoompoint } = action; + pixelPlanetEvents.emit('setscale', scale, zoompoint); + break; + } + + case 'RECEIVE_BIG_CHUNK': { + /* + * chunk: ChunkRGB or ChunkRGB3D object, + * see ui/ChunkRGB.js and ui/ChunkRGB3D.js + */ + pixelPlanetEvents.emit('receivechunk', action.chunk); + break; + } + + default: + // nothing + } + + return next(action); +}; + +window.pixelPlanetEvents = pixelPlanetEvents; diff --git a/src/ui/ChunkLoader2D.js b/src/ui/ChunkLoader2D.js index a0e195e..d0cabfe 100644 --- a/src/ui/ChunkLoader2D.js +++ b/src/ui/ChunkLoader2D.js @@ -194,7 +194,8 @@ class ChunkLoader { historicalTime: string, chunkRGB, ) { - const { canvasId } = this; + const { canvasId, canvasMaxTiledZoom } = this; + const center = [canvasMaxTiledZoom, cx, cy]; let url = `${window.backupurl}/${historicalDate}/`; if (historicalTime) { // incremential tiles @@ -203,13 +204,13 @@ class ChunkLoader { // full tiles url += `${canvasId}/tiles/${cx}/${cy}.png`; } - this.store.dispatch(requestBigChunk(null)); + this.store.dispatch(requestBigChunk(center)); try { const img = await loadImage(url); chunkRGB.fromImage(img); - this.store.dispatch(receiveBigChunk(null)); + this.store.dispatch(receiveBigChunk(center, chunkRGB)); } catch (error) { - this.store.dispatch(receiveBigChunkFailure(null, error)); + this.store.dispatch(receiveBigChunkFailure(center, error)); if (historicalTime) { chunkRGB.empty(true); } else { @@ -233,7 +234,7 @@ class ChunkLoader { } else { throw new Error('Chunk response was invalid'); } - this.store.dispatch(receiveBigChunk(center)); + this.store.dispatch(receiveBigChunk(center, chunkRGB)); } else { throw new Error('Network response was not ok.'); } @@ -250,7 +251,7 @@ class ChunkLoader { const url = `tiles/${this.canvasId}/${zoom}/${cx}/${cy}.png`; const img = await loadImage(url); chunkRGB.fromImage(img); - this.store.dispatch(receiveBigChunk(center)); + this.store.dispatch(receiveBigChunk(center, chunkRGB)); } catch (error) { this.store.dispatch(receiveBigChunkFailure(center, error)); chunkRGB.empty(); diff --git a/src/ui/ChunkLoader3D.js b/src/ui/ChunkLoader3D.js index a8a0c8e..b7bd6dd 100644 --- a/src/ui/ChunkLoader3D.js +++ b/src/ui/ChunkLoader3D.js @@ -109,7 +109,7 @@ class ChunkLoader { } else { throw new Error('Chunk response was invalid'); } - this.store.dispatch(receiveBigChunk(center)); + this.store.dispatch(receiveBigChunk(center, chunk)); } else { throw new Error('Network response was not ok.'); } diff --git a/src/ui/ads.js b/src/ui/ads.js deleted file mode 100644 index 1870e9a..0000000 --- a/src/ui/ads.js +++ /dev/null @@ -1,97 +0,0 @@ -/** - * - * Copyright 2017 Google Inc. All Rights Reserved. - * You may study, modify, and use this example for any purpose. - * Note that this example is provided "as is", WITHOUT WARRANTY - * of any kind either expressed or implied. - * - * @flow - */ - -import 'url-search-params-polyfill'; - -let adsController; -let available = false; -let fetching = false; -let play = false; -let outstreamContainer; - -const adTagParams = new URLSearchParams(); -adTagParams.set('ad_type', 'video_image_text'); -adTagParams.set('client', 'ca-games-pub-4111661129974554'); -adTagParams.set('videoad_start_delay', 0); -adTagParams.set('description_url', 'http://pixelplanet.fun/'); -adTagParams.set('max_ad_duration', 20000); -if (__DEV__) adTagParams.set('adtest', 'on'); -// eslint-disable-next-line max-len -const adTagUrl = `https://googleads.g.doubleclick.net/pagead/ads?${adTagParams.toString()}`; - -/** - * Request ad. Must be invoked by a user action for mobile devices. - */ -export function requestAds() { - if (!adsController) return; - if (available || fetching) return; - - fetching = true; - - adsController.initialize(); - - // Request ads - adsController.requestAds(adTagUrl); -} - -/** - * Allow resizing of the current ad. - */ -function resize() { - if (adsController) { - const width = window.innerWidth; - const height = window.innerHeight; - adsController.resize(width, height); - } -} - -export function playAd() { - if (available) { - play = false; - available = false; - outstreamContainer.style.display = 'block'; - adsController.showAd(); - } else { - play = true; - } -} - -/** - * Callback for when ad has completed loading. - */ -function onAdLoaded() { - // Play ad - available = true; - fetching = false; - if (play) playAd(); -} - -/** - * Callback for when ad has completed playback. - */ -function onDone() { - // Show content - outstreamContainer.style.display = 'none'; -} - -function init() { - if (typeof google === 'undefined') return; - outstreamContainer = document.getElementById('outstreamContainer'); - - adsController = new window.google.outstream.AdsController( - outstreamContainer, - onAdLoaded, - onDone, - ); -} - -export default init; - -window.addEventListener('resize', resize); diff --git a/utils/pp-center-331-337-link.png b/utils/pp-center-331-337-link.png index acb8905..88beccc 100644 Binary files a/utils/pp-center-331-337-link.png and b/utils/pp-center-331-337-link.png differ