-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add some stuff but it's not a game yet
- Loading branch information
1 parent
e97af60
commit eddaea0
Showing
10 changed files
with
174 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,37 @@ | ||
import { createMap } from './map/createMap.js' | ||
import { getRandomPart } from './map/getRandomPart.js'; | ||
import { districtSource } from './map/districts.js'; | ||
|
||
createMap() | ||
const map = createMap() | ||
|
||
const headerbox = document.getElementById('headerbox') | ||
const infobox = document.getElementById('infobox') | ||
const modalbox = document.getElementById('modalbox') | ||
|
||
const playerFaction = getRandomPart(districtSource.getFeatures()) | ||
window.goto = (duration = 2000) => map.getView().fit(playerFaction.getGeometry(), { duration }) | ||
|
||
const updateHeader = (emoji) => headerbox.innerHTML = ` | ||
<span>Your Faction</span> | ||
<h1>${emoji} ${playerFaction.properties.factionName}</h1> | ||
` | ||
updateHeader('🐀') | ||
goto(5000) | ||
|
||
const infodefault = 'Hover any region to display information.' | ||
infobox.innerHTML = infodefault | ||
map.on('pointermove', function (e) { | ||
infobox.innerHTML = infodefault | ||
map.forEachFeatureAtPixel(e.pixel, function (feature) { | ||
infobox.innerHTML = ` | ||
Faction: ${feature.properties.factionName}<br /> | ||
Rats: ${feature.properties.rats}<br /> | ||
Food: ${feature.properties.food} | ||
` | ||
return true | ||
}) | ||
}) | ||
|
||
modalbox.innerHTML = ` | ||
OH MAN I FORGOT TO IMPLEMENT GAMEPLAY | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,49 @@ | ||
// Knowing that one day JSON can be loaded fills you with determination. | ||
// import districts from './districts.json' assert {type: 'json'} | ||
import { districts } from './districtsjson.js' | ||
import { enrat } from './enrat/index.js' | ||
|
||
const VectorLayer = ol.layer.Vector | ||
const VectorSource = ol.source.Vector | ||
const { Select } = ol.interaction | ||
const { GeoJSON } = ol.format | ||
const { pointerMove } = ol.events.condition | ||
const { Stroke, Style, Fill } = ol.style | ||
const { Stroke, Style, Fill, Text } = ol.style | ||
|
||
const style = new Style({ | ||
stroke: new Stroke({ color: '#333', width: 1 }), | ||
fill: new Fill({ color: 'rgba(255,255,255,0)' }) | ||
const text = (feature) => new Text({ | ||
font: '22px sans-serif', | ||
overflow: true, | ||
text: feature.properties.factionName, | ||
fill: new Fill({color: feature.properties.hex}), | ||
stroke: new Stroke({color: '#16161D', width: '2'}), | ||
textAlign: 'center' | ||
}) | ||
|
||
const hoverStyle = new Style({ | ||
stroke: new Stroke({ color: '#000', width: 3 }), | ||
fill: new Fill({ color: 'rgba(255,255,255,0.0)' }) | ||
const style = (feature) => new Style({ | ||
stroke: new Stroke({ color: '#333', width: 2 }), | ||
fill: new Fill({ color: feature.properties.hex + '66' }), | ||
text: text(feature) | ||
}) | ||
|
||
const hoverStyle = (feature) => new Style({ | ||
stroke: new Stroke({ color: '#16161D', width: 4 }), | ||
fill: new Fill({ color: feature.properties.hex + 'CC' }), | ||
text: text(feature) | ||
}) | ||
|
||
export const districtSource = new VectorSource({ | ||
features: (new GeoJSON({ featureProjection: 'EPSG:3857' })).readFeatures(districts) | ||
features: | ||
new GeoJSON({ featureProjection: 'EPSG:3857' }) | ||
.readFeatures(districts) | ||
.map(enrat) | ||
}) | ||
|
||
export const districtVector = new VectorLayer({ | ||
source: districtSource, | ||
style | ||
}) | ||
|
||
export const select = new Select({ | ||
export const hover = new Select({ | ||
condition: pointerMove, | ||
style: hoverStyle | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { getRandomPart } from '../getRandomPart.js' | ||
|
||
const hadThat = [''] | ||
|
||
const starts = [ | ||
'Red', 'Orange', 'Blue', 'Yellow', | ||
'Green', 'Black', 'White', 'Ultraviolet', | ||
'Deadly', 'Amazing', 'Dangerous', 'Astonishing', | ||
'Töfte', 'Knorke', 'Schnieke', | ||
'Sewer', 'Underground', | ||
'Tunnel', | ||
'' | ||
] | ||
|
||
const mids = [ | ||
'Rodent', 'Rat', 'Critter', 'Creature', 'Vermin', | ||
'Tea', 'Sausage', 'Schinken', 'Cheese', | ||
'Nager', | ||
'Snake', | ||
'' | ||
] | ||
|
||
const ends = [ | ||
'Killers', 'Sacks', 'Boys', 'Dimwits', | ||
'Masters', 'Heroes', 'Team', 'Force', | ||
'Pack', 'Horde', 'Flut', | ||
'Rules', | ||
'' | ||
] | ||
|
||
/** | ||
* @returns {string} randomized faction name | ||
*/ | ||
export const getFactionName = () => { | ||
let name = '' | ||
// reroll until unique - need lots of source names | ||
while (hadThat.includes(name)) { | ||
name = [ | ||
getRandomPart(starts), | ||
getRandomPart(mids), | ||
getRandomPart(ends) | ||
].join(' ').trim() | ||
} | ||
hadThat.push(name) | ||
return name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const getRandomHex = () => | ||
'#' + | ||
Math.round(Math.random() * 0xffffff) | ||
.toString(16) | ||
.padStart(6, '0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { getFactionName } from "./getFactionName.js" | ||
import { getRandomHex } from "./getRandomHex.js" | ||
|
||
const makeFeatureProperties = () => ({ | ||
factionName: getFactionName(), | ||
hex: getRandomHex(), | ||
rats: Math.floor(Math.random() * 900) + 101, | ||
food: Math.floor(Math.random() * 900) + 101, | ||
}) | ||
|
||
export const enrat = feature => { | ||
feature.properties = makeFeatureProperties() | ||
return feature | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* @param {*[]} a array of something | ||
* @returns {*} random value from array | ||
*/ | ||
export const getRandomPart = a => a[Math.floor(Math.random() * a.length)] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters