Merge branch 'production'

This commit is contained in:
HF 2020-11-29 01:17:46 +01:00
commit a7f356b7bc
10 changed files with 76 additions and 134 deletions

View File

@ -444,10 +444,12 @@ export function preLoadedBigChunk(
export function receiveBigChunk(
center: Cell,
chunk: Uint8Array,
): Action {
return {
type: 'RECEIVE_BIG_CHUNK',
center,
chunk,
};
}

View File

@ -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,

View File

@ -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,

View File

@ -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);
};

View File

@ -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,
),
),

63
src/store/extensions.js Normal file
View File

@ -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;

View File

@ -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();

View File

@ -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.');
}

View File

@ -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);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 43 KiB