Skip to content

Commit

Permalink
Merge pull request #1191 from streetmix/louh/sky-button
Browse files Browse the repository at this point in the history
Jury-rig a button to make the supermoon optional
  • Loading branch information
louh committed Jan 21, 2019
2 parents b9d3ba2 + b1daf6c commit 555c606
Show file tree
Hide file tree
Showing 14 changed files with 329 additions and 35 deletions.
2 changes: 1 addition & 1 deletion app/models/street_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { getVariantString, getVariantArray } = require('../../lib/variant')

const LATEST_SCHEMA_VERSION = 19

const DEFAULT_ENVIRONS = 'default'
const DEFAULT_ENVIRONS = 'supermoon'
const DEFAULT_BUILDING_HEIGHT_LEFT = 4
const DEFAULT_BUILDING_HEIGHT_RIGHT = 3
const DEFAULT_BUILDING_VARIANT_LEFT = 'narrow'
Expand Down
29 changes: 28 additions & 1 deletion assets/css/_palette.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@
height: $palette-height - 26px;
bottom: 0;
background: $palette-background;
border-top: 3px solid darken($bottom-background, 5%);
// border-top: 3px solid darken($bottom-background, 5%);
text-align: center;
z-index: $z-02-palette;
user-select: none;
touch-action: none;

// New style!
border-top-left-radius: 6px;
border-top-right-radius: 6px;
// border-left: 3px solid darken($bottom-background, 5%);
// border-right: 3px solid darken($bottom-background, 5%);
}

body.read-only .palette-container {
Expand All @@ -30,6 +36,19 @@ body.read-only .palette-container {
button.scrollable {
margin-top: 10px;
z-index: $z-04-palette-scroll;

// New style!
width: 40px;
border: $button-border;
border-radius: 50%;

&.scroll-right {
right: -20px !important;
}

&.scroll-left {
left: -20px !important;
}
}
}

Expand All @@ -56,6 +75,14 @@ body.read-only .palette-container {
button {
height: $palette-height - 50px;
width: $palette-height - 50px;

// New style!
border: $button-border;
border-radius: 50%;

&[disabled] {
border-color: desaturate($ui-colour, 100%);
}
}

// Spacing between buttons
Expand Down
2 changes: 2 additions & 0 deletions assets/scripts/app/Palette.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Scrollable from '../ui/Scrollable'
import SegmentForPalette from '../segments/SegmentForPalette'
import UndoRedo from './UndoRedo'
import PaletteTooltips from '../palette/PaletteTooltips'
import PaletteCommandsLeft from '../palette/PaletteCommandsLeft'
import { getAllSegmentInfoArray } from '../segments/info'

class Palette extends React.Component {
Expand Down Expand Up @@ -148,6 +149,7 @@ class Palette extends React.Component {

return (
<div className="palette-container">
<PaletteCommandsLeft />
<div className={'palette-trashcan' + (draggingState && draggingState.draggedSegment !== undefined ? ' visible' : '')}>
<FormattedMessage id="palette.remove" defaultMessage="Drag here to remove" />
</div>
Expand Down
2 changes: 1 addition & 1 deletion assets/scripts/app/SkyBackground.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class SkyBackground extends React.PureComponent {
}

return (
<section className="street-section-sky" style={skyStyle}>
<section className={`street-section-sky sky-${environs.id}`} style={skyStyle}>
<div className="sky-background" ref={this.backgroundEl}>
<div className="sky-background-default" />
</div>
Expand Down
9 changes: 8 additions & 1 deletion assets/scripts/app/SkyBackground.scss
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ body.environment-animations {
// rendered pixellated for some reason.
position: absolute;
left: 0;
right: 0;
width: 100vw;
height: 100%;
}
Expand Down Expand Up @@ -137,4 +136,12 @@ body.environment-animations {
top: 20%;
right: 30%;
background-size: contain;
opacity: 0;
transform: translateY(-14px);
transition: opacity $environment-transition, transform $environment-transition;
}

.sky-supermoon .sky-superbloodwolfmoon {
transform: translateY(0);
opacity: 1;
}
21 changes: 21 additions & 0 deletions assets/scripts/gallery/thumbnail.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ export function drawStreetThumbnail (ctx, street, thumbnailWidth, thumbnailHeigh
ctx.fillRect(0, 0, thumbnailWidth * dpi, horizonLine)
}

// Background image fill
if (env.backgroundImage) {
const STARS_WIDTH = 2000
const STARS_HEIGHT = 1333
for (let i = 0; i < Math.floor(thumbnailHeight / STARS_HEIGHT) + 1; i++) {
for (let j = 0; j < Math.floor(thumbnailWidth / STARS_WIDTH) + 1; j++) {
ctx.drawImage(images.get('/images/stars.svg').img,
0, 0, STARS_WIDTH * 2, STARS_HEIGHT * 2,
j * SKY_WIDTH * dpi, i * STARS_HEIGHT * dpi, SKY_WIDTH * dpi, STARS_HEIGHT * dpi)
console.log('drawing', images.get('/images/stars.svg').img, i, j)
}
}
}

// Gradient fill
if (env.backgroundGradient) {
const gradient = ctx.createLinearGradient(0, 0, 0, horizonLine)
Expand All @@ -75,6 +89,13 @@ export function drawStreetThumbnail (ctx, street, thumbnailWidth, thumbnailHeigh
ctx.fillRect(0, 0, thumbnailWidth * dpi, horizonLine)
}

const SUPERMOON = true
if (SUPERMOON) {
console.log(images.get('/images/super-blood-wolf-moon.png').img)
ctx.drawImage(images.get('/images/super-blood-wolf-moon.png').img,
0.2 * thumbnailWidth, 0.33 * thumbnailHeight, 128 * dpi, 128 * dpi)
}

const SKY_FRONT_HEIGHT = 280
const SKY_REAR_HEIGHT = 250

Expand Down
106 changes: 106 additions & 0 deletions assets/scripts/palette/PaletteCommandsLeft.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import CloseButton from '../ui/CloseButton'
import { SUN_ICON, MOON_ICON } from '../ui/icons'
import { setEnvironment } from '../store/actions/street'
import './PaletteCommandsLeft.scss'

class PaletteCommandsLeft extends Component {
static propTypes = {
env: PropTypes.string,
setEnvironment: PropTypes.func.isRequired
}

constructor (props) {
super(props)

let tooltipDismissed
try {
tooltipDismissed = window.localStorage.getItem('supermoon-tooltip-dismissed')
} catch (e) {
console.log('Could not access localstorage')
}

this.state = {
tooltip: tooltipDismissed !== 'true'
}
}

setToDay = () => {
this.dismissTooltip()
this.props.setEnvironment('day')
}

setToMoon = () => {
this.dismissTooltip()
this.props.setEnvironment('supermoon')
}

dismissTooltip = () => {
this.setState({
tooltip: false
})

try {
window.localStorage.setItem('supermoon-tooltip-dismissed', 'true')
} catch (e) {
console.log('Could not access localstorage')
}
}

render () {
let Button
if (this.props.env === 'supermoon') {
Button = (
<button
onClick={this.setToDay}
title={'Toggle supermoon'}
>
<FontAwesomeIcon icon={SUN_ICON} />
</button>
)
} else {
Button = (
<button
onClick={this.setToMoon}
title={'Toggle supermoon'}
>
<FontAwesomeIcon icon={MOON_ICON} />
</button>

)
}

let Tooltip = (this.state.tooltip) ? (
<div className="supermoon-tooltip">
<CloseButton onClick={this.dismissTooltip} />
<p>
<strong><a href="https://www.nationalgeographic.com/science/2019/01/how-to-watch-super-blood-wolf-moon-lunar-eclipse/" target="_blank" rel="noopener noreferrer">The “super blood wolf moon” lunar eclipse</a></strong> (external link) is visible in the Americas,
western Europe and in most of Africa from January 20-21, 2019. You can return to daytime sky with this button below.&lrm;
</p>
<div className="palette-tooltip-pointer-container">
<div className="palette-tooltip-pointer" />
</div>
</div>
) : null

return (
<div className="palette-commands-left">
{Button}
{Tooltip}
</div>
)
}
}

const mapStateToProps = (state) => ({
env: state.street.environment
})

const mapDispatchToProps = {
setEnvironment
}

export default connect(mapStateToProps, mapDispatchToProps)(PaletteCommandsLeft)
124 changes: 124 additions & 0 deletions assets/scripts/palette/PaletteCommandsLeft.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
@import '../../css/variables.scss';

.palette-commands-left {
position: absolute;
left: 10px;
top: 10px;
height: $palette-height - 50px;
vertical-align: top;
text-align: left;
z-index: $z-04-command-menu;

button {
height: $palette-height - 50px;
width: $palette-height - 50px;

// New style!
border: $button-border;
border-radius: 50%;

// Icon style
font-size: 1em;

&[disabled] {
border-color: desaturate($ui-colour, 100%);
}
}
}

[dir="rtl"] {
.palette-commands-left {
right: 10px;
left: auto;
}
}

.supermoon-tooltip {
padding: 1.25em;
position: fixed;
bottom: 70px;
background-color: white;
border-radius: 6px;
font-size: 12px;
line-height: 1.4;
width: 230px;
left: 50px;
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.2);
animation-duration: 1200ms;
animation-fill-mode: both;
animation-name: bounce;

[dir="rtl"] & {
left: auto;
right: 50px;
text-align: right;
}

p {
margin: 0;
}

.close {
border: 0;
height: 16px;
width: 16px;
position: absolute;
right: 6px;
top: 5px;
padding: 0;
line-height: 16px;

[dir="rtl"] & {
right: auto;
left: 6px;
}
}

.palette-tooltip-pointer-container {
width: 40px;
position: absolute;
left: 33px;
margin-left: -20px;
overflow: hidden;
pointer-events: none;
bottom: -33px;
height: 33px;

[dir="rtl"] & {
left: auto;
right: 7px;
}
}

.palette-tooltip-pointer {
position: absolute;
height: 30px;
width: 30px;
left: 50%;
bottom: 22px;
margin-left: -18px;
border: 0;
transform: rotate(45deg);
background: #fff;
box-shadow: none;
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.2);
}
}

@keyframes bounce {
0%,
20%,
50%,
80%,
100% {
transform: translateY(0);
}

40% {
transform: translateY(-20px);
}

60% {
transform: translateY(-10px);
}
}
3 changes: 2 additions & 1 deletion assets/scripts/store/reducers/__tests__/street.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* eslint-env jest */
import reducer from '../street'
import * as actions from '../../actions/street'
import { DEFAULT_ENVIRONS } from '../../../streets/constants'

describe('street reducer', () => {
it('should return the initial state', () => {
expect(reducer(undefined, {})).toEqual({
immediateRemoval: true,
segments: [],
environment: 'default'
environment: DEFAULT_ENVIRONS
})
})

Expand Down
1 change: 1 addition & 0 deletions assets/scripts/streets/__tests__/environs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import MOCK_ENVIRONS from '../__mocks__/environs.json'

jest.mock('../environs.json', () => require('../__mocks__/environs.json'))
jest.mock('../constants', () => ({ DEFAULT_ENVIRONS: 'default' }))

describe('environs helpers', () => {
describe('makeCSSGradientDeclaration', () => {
Expand Down

0 comments on commit 555c606

Please sign in to comment.