Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kids mode. #29

Merged
merged 1 commit into from
Dec 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,19 @@ function fillCells(content) {

/**
* Loads content from the specified file to fill the board.
* @param {String} cluefile URL of the JSON clue file.
* @param {String} tropeDefinitions URL of the JSON trope file.
*/
function loadBoard(cluefile) {
function loadBoard(tropeDefinitions) {
req=new XMLHttpRequest();
req.open("GET", cluefile ,true);
req.open("GET", tropeDefinitions, true);
req.overrideMimeType("application/json");
req.send();
req.onload = function onLoad() {
const clues = JSON.parse(req.responseText);
shuffle(clues);
clues[12] = 'FREE';
trackEvent('load', { value: cluefile });
fillCells(clues.map((text) => {
const tropes = JSON.parse(req.responseText);
shuffle(tropes);
tropes[12] = 'FREE';
trackEvent('load', { value: tropeDefinitions });
fillCells(tropes.map((text) => {
return {
t: text,
m: false
Expand All @@ -215,18 +215,18 @@ function loadBoard(cluefile) {

/**
* Pull text into the cells, either from Saved data or from
* a clue file.
* @param {String} cluefile URL JSON file to get new clues.
* a trope file.
* @param {String} tropeDefinitions URL JSON file to get new tropes.
*/
function populateBoard(cluefile) {
function populateBoard(tropeDefinitions) {
let age = 0;
const saved = localStorage.getItem('saved');
if (saved) {
const savedAt = Number(localStorage.getItem('savedAt'));
age = Math.floor((Date.now() - savedAt) / 1000);
}
if (!saved || (age > 7200)) {
loadBoard(cluefile);
loadBoard(tropeDefinitions);
} else {
trackEvent('restore', { value: age });
fillCells(JSON.parse(saved));
Expand All @@ -239,19 +239,19 @@ function populateBoard(cluefile) {
*/
function ready() {
const searchParams = new URLSearchParams(window.location.search);
let cluefile = 'film-tropes.json'
if (searchParams.has('clues')) {
cluefile = searchParams.get('clues');
let tropeDefinitions = 'film-tropes.json'
if (searchParams.has('tropes')) {
tropeDefinitions = searchParams.get('tropes');
}
const board = document.querySelector('.board');
buildEmptyBoard(board);
populateBoard(cluefile);
populateBoard(tropeDefinitions);
buildHeading();
const resetButton = document.querySelector('.controls .reset');
resetButton.addEventListener('click', (event)=> {
trackEvent('reset', { event_category: 'user' });
clearBingos();
loadBoard(cluefile);
loadBoard(tropeDefinitions);
})
window.addEventListener('unload', (event) => {
saveBoard();
Expand Down
4 changes: 2 additions & 2 deletions www/film-tropes.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"Big city ambitions",
"Holiday magic",
"Festival",
"Children's Charity",
"Children's charity",
"Christmas tree lighting",
"Obviously artificial snow",
"Old flame",
Expand Down Expand Up @@ -68,7 +68,7 @@
"Happiness over success",
"Lacey Chabert",
"Danica McKellar",
"Excessive Candles",
"Excessive candles",
"Hospital visit",
"Female lead has more than three coats",
"Outside craft booths",
Expand Down
65 changes: 65 additions & 0 deletions www/kids.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[
"Chopping wood",
"Carriage or sleigh ride",
"Job offer",
"Bad Christmas memory",
"Carousel",
"Two hands on a hot drink",
"Friendly police officer",
"Home town",
"Cute dog",
"The perfect gift",
"Baking",
"Someone plays guitar",
"\"Please stay!\"",
"Traditions",
"Dressing up as Santa",
"Snowfall",
"Interrupted kiss",
"Engagement or wedding",
"Small town vs. big city",
"Matchmaker",
"Deceased parent",
"Drinking coffee",
"Holiday magic",
"Festival",
"Children's charity",
"Christmas tree lighting",
"Old flame",
"An inn",
"Hanging Christmas decorations",
"Carolers",
"Misunderstood royalty",
"Hot chocolate",
"Single parent",
"Boutique",
"Car trouble",
"\"Follow your heart\"",
"\"I got the job\"",
"Mistletoe",
"Snow globe",
"Heartfelt apology",
"Reindeer",
"Santa",
"Excessive decorations",
"Snow",
"Christmas tree farm",
"Overheard conversation",
"Mis\u00adunderstanding",
"Falling in love",
"Snowman",
"Wearing pajamas",
"Excessive candles",
"Hospital visit",
"Outside craft booths",
"Gingerbread house",
"Fireplace or woodstove",
"Seasonal food",
"Ice skating",
"Wrapped Present",
"Cookies",
"Kissing (yuck!)",
"Santa hat",
"Red bow",
"Stockings hung by chimney"
]