diff options
-rw-r--r-- | data.js | 2 | ||||
-rw-r--r-- | play.html | 5 | ||||
-rw-r--r-- | play.js | 93 | ||||
-rw-r--r-- | rules.js | 22 | ||||
-rw-r--r-- | tools/gendata.js | 87 |
5 files changed, 192 insertions, 17 deletions
@@ -0,0 +1,2 @@ +const US_STATES = [null,{"code":"AZ","name":"Arizona","region":1},{"code":"CA","name":"California","region":1},{"code":"ID","name":"Idaho","region":1},{"code":"NM","name":"New Mexico","region":1},{"code":"NV","name":"Nevada","region":1},{"code":"OR","name":"Oregon","region":1},{"code":"UT","name":"Utah","region":1},{"code":"WA","name":"Washington","region":1},{"code":"CO","name":"Colorado","region":2},{"code":"KS","name":"Kansas","region":2},{"code":"MT","name":"Montana","region":2},{"code":"ND","name":"North Dakota","region":2},{"code":"NE","name":"Nebraska","region":2},{"code":"OK","name":"Oklahoma","region":2},{"code":"SD","name":"South Dakota","region":2},{"code":"WY","name":"Wyoming","region":2},{"code":"AL","name":"Alabama","region":3},{"code":"AR","name":"Arkansas","region":3},{"code":"FL","name":"Florida","region":3},{"code":"GA","name":"Georgia","region":3},{"code":"LA","name":"Louisiana","region":3},{"code":"MS","name":"Mississippi","region":3},{"code":"SC","name":"South Carolina","region":3},{"code":"TX","name":"Texas","region":3},{"code":"IA","name":"Iowa","region":4},{"code":"IL","name":"Illinois","region":4},{"code":"IN","name":"Indiana","region":4},{"code":"MI","name":"Michigan","region":4},{"code":"MN","name":"Minnesota","region":4},{"code":"MO","name":"Missouri","region":4},{"code":"OH","name":"Ohio","region":4},{"code":"WI","name":"Wisconsin","region":4},{"code":"DE","name":"Delaware","region":5},{"code":"KY","name":"Kentucky","region":5},{"code":"MD","name":"Maryland","region":5},{"code":"NC","name":"North Carolina","region":5},{"code":"PA","name":"Pennsylvania","region":5},{"code":"TN","name":"Tennessee","region":5},{"code":"VA","name":"Virginia","region":5},{"code":"WV","name":"West Virginia","region":5},{"code":"CT","name":"Connecticut","region":6},{"code":"MA","name":"Massachusetts","region":6},{"code":"ME","name":"Maine","region":6},{"code":"NH","name":"New Hampshire","region":6},{"code":"NJ","name":"New Jersey","region":6},{"code":"NY","name":"New York","region":6},{"code":"RI","name":"Rhode Island","region":6},{"code":"VT","name":"Vermont","region":6}] +if (typeof module !== 'undefined') module.exports = { US_STATES } @@ -11,6 +11,7 @@ <link rel="stylesheet" href="/common/client.css"> <script defer src="/common/client.js"></script> <script defer src="cards.js"></script> +<script defer src="data.js"></script> <script defer src="play.js"></script> <style> @@ -889,9 +890,9 @@ c5 3 13 7 17 8 8 2 9 3 11 12 1 5 5 12 8 16 5 8 5 8 3 22 l-3 14 -30 -1 c-35 <div id="West" class="region" style="top:273px;left:99px;width:55px;height:55px;"></div> <div id="Plains" class="region" style="top:203px;left:374px;"></div> <div id="South" class="region" style="top:473px;left:541px;"></div> - <div id="MidWest" class="region" style="top:266px;left:579px;"></div> + <div id="Midwest" class="region" style="top:266px;left:579px;"></div> <div id="AtlanticAppalachia" class="region" style="top:333px;left:764px;"></div> - <div id="NorthEast" class="region" style="top:158px;left:881px;"></div> + <div id="Northeast" class="region" style="top:158px;left:881px;"></div> <div id="turn" class="piece turn" style="left:800px;top:765px;"></div> <div class="piece congress" style="left:500px;top:765px;"></div> @@ -1,12 +1,33 @@ "use strict" -/* global action_button, send_action, view */ +/* global CARDS, US_STATES, action_button, send_action, view */ const SUF = 0 const OPP = 1 const SUF_NAME = "Suffragist" const OPP_NAME = "Opposition" +const WEST = 1 +const PLAINS = 2 +const SOUTH = 3 +const MIDWEST = 4 +const ATLANTIC_APPALACHIA = 5 +const NORTHEAST = 6 + +const REGION_NAMES = [ + null, + "West", + "Plains", + "South", + "Midwest", + "Atlantic & Appalachia", + "Northeast" +] + +const region_count = 6 +const us_states_count = region_count * 8 +const card_count = 128 + let ui = { status: document.getElementById("status"), player: [ @@ -14,13 +35,15 @@ let ui = { document.getElementById("role_Opposition"), ], cards: [ null ], + us_states: [ null ], + regions: [ null ], } // :r !python3 tools/genlayout.py const LAYOUT = { - "NorthEast": [914, 190], + "Northeast": [914, 190], "AtlanticAppalachia": [797, 366], - "MidWest": [612, 298], + "Midwest": [612, 298], "South": [574, 505], "Plains": [406, 236], "West": [127, 300], @@ -168,6 +191,18 @@ function is_piece_action(i) { return false } +function is_region_action(i) { + if (view.actions && view.actions.region && view.actions.region.includes(i)) + return true + return false +} + +function is_us_state_action(i) { + if (view.actions && view.actions.us_state && view.actions.us_state.includes(i)) + return true + return false +} + function is_space_action(i) { if (view.actions && view.actions.space && view.actions.space.includes(i)) return true @@ -178,6 +213,14 @@ function on_blur(_evt) { document.getElementById("status").textContent = "" } +function on_focus_region(evt) { + document.getElementById("status").textContent = REGION_NAMES[evt.target.my_region] +} + +function on_focus_us_state(evt) { + document.getElementById("status").textContent = US_STATES[evt.target.my_us_state].name +} + function on_focus_space(evt) { document.getElementById("status").textContent = evt.target.my_name } @@ -187,16 +230,8 @@ function on_focus_piece(evt) { document.getElementById("status").textContent = evt.target.my_name } -// function on_click_card(evt) { -// if (evt.button === 0) { -// if (send_action('card', evt.target.my_card)) -// evt.stopPropagation() -// } -// } - function on_click_card(evt) { let card = evt.target.my_card - console.log("CLICK", card) if (is_action('card', card)) { send_action('card', card) } else { @@ -204,6 +239,22 @@ function on_click_card(evt) { } } +function on_click_region(evt) { + if (evt.button === 0) { + if (send_action('region', evt.target.my_region)) + evt.stopPropagation() + } + hide_popup_menu() +} + +function on_click_us_state(evt) { + if (evt.button === 0) { + if (send_action('us_state', evt.target.my_us_state)) + evt.stopPropagation() + } + hide_popup_menu() +} + function on_click_space(evt) { if (evt.button === 0) { if (send_action('space', evt.target.my_space)) @@ -214,6 +265,7 @@ function on_click_space(evt) { function on_click_cube(evt) { if (evt.button === 0) { + console.log("piece", evt.target.my_cube) if (send_action('piece', evt.target.my_cube)) evt.stopPropagation() } @@ -230,7 +282,7 @@ function create(t, p, ...c) { function build_user_interface() { let elt - for (let c = 1; c <= 128; ++c) { + for (let c = 1; c <= card_count; ++c) { elt = ui.cards[c] = create("div", { className: `card card_${c}`, my_card: c, @@ -238,6 +290,23 @@ function build_user_interface() { }) } + for (let r = 1; r <= region_count; ++r) { + let region_name_css = REGION_NAMES[r].replaceAll(' & ', '') + elt = ui.regions[r] = document.querySelector(`#map #${region_name_css}`) + elt.my_region = r + elt.addEventListener("mousedown", on_click_region) + elt.addEventListener("mouseenter", on_focus_region) + elt.addEventListener("mouseleave", on_blur) + } + + for (let s = 1; s <= us_states_count; ++s) { + let us_state_css = US_STATES[s].code + elt = ui.regions[s] = document.querySelector(`#map #${us_state_css}`) + elt.my_us_state = s + elt.addEventListener("mousedown", on_click_us_state) + elt.addEventListener("mouseenter", on_focus_us_state) + elt.addEventListener("mouseleave", on_blur) + } } function on_focus_card_tip(card_number) { // eslint-disable-line no-unused-vars @@ -18,9 +18,25 @@ const last_strategy_card = 116 const first_states_card = 117 const last_states_card = 128 -const { - CARDS -} = require("./cards.js") +const WEST = 1 +const PLAINS = 2 +const SOUTH = 3 +const MIDWEST = 4 +const ATLANTIC_APPALACHIA = 5 +const NORTHEAST = 6 + +const REGION_NAMES = [ + null, + "West", + "Plains", + "South", + "Midwest", + "Atlantic & Appalachia", + "Northeast" +] + +const { CARDS } = require("./cards.js") +const { US_STATES } = require("./data.js") // #region CARD & HAND FUNCTIONS diff --git a/tools/gendata.js b/tools/gendata.js new file mode 100644 index 0000000..f08614f --- /dev/null +++ b/tools/gendata.js @@ -0,0 +1,87 @@ +"use strict" + +const fs = require("fs") + +let data = {} + +const US_STATES = [null] + +const WEST = 1 +const PLAINS = 2 +const SOUTH = 3 +const MIDWEST = 4 +const ATLANTIC_APPALACHIA = 5 +const NORTHEAST = 6 + +const REGION_NAMES = [ + null, + "West", + "Plains", + "South", + "Midwest", + "Atlantic & Appalachia", + "Northeast" +] + + +function def_us_state(code, name, region) { + US_STATES.push({code, name, region}) +} + +def_us_state("AZ", "Arizona", WEST) +def_us_state("CA", "California", WEST) +def_us_state("ID", "Idaho", WEST) +def_us_state("NM", "New Mexico", WEST) +def_us_state("NV", "Nevada", WEST) +def_us_state("OR", "Oregon", WEST) +def_us_state("UT", "Utah", WEST) +def_us_state("WA", "Washington", WEST) + +def_us_state("CO", "Colorado", PLAINS) +def_us_state("KS", "Kansas", PLAINS) +def_us_state("MT", "Montana", PLAINS) +def_us_state("ND", "North Dakota", PLAINS) +def_us_state("NE", "Nebraska", PLAINS) +def_us_state("OK", "Oklahoma", PLAINS) +def_us_state("SD", "South Dakota", PLAINS) +def_us_state("WY", "Wyoming", PLAINS) + +def_us_state("AL", "Alabama", SOUTH) +def_us_state("AR", "Arkansas", SOUTH) +def_us_state("FL", "Florida", SOUTH) +def_us_state("GA", "Georgia", SOUTH) +def_us_state("LA", "Louisiana", SOUTH) +def_us_state("MS", "Mississippi", SOUTH) +def_us_state("SC", "South Carolina", SOUTH) +def_us_state("TX", "Texas", SOUTH) + +def_us_state("IA", "Iowa", MIDWEST) +def_us_state("IL", "Illinois", MIDWEST) +def_us_state("IN", "Indiana", MIDWEST) +def_us_state("MI", "Michigan", MIDWEST) +def_us_state("MN", "Minnesota", MIDWEST) +def_us_state("MO", "Missouri", MIDWEST) +def_us_state("OH", "Ohio", MIDWEST) +def_us_state("WI", "Wisconsin", MIDWEST) + +def_us_state("DE", "Delaware", ATLANTIC_APPALACHIA) +def_us_state("KY", "Kentucky", ATLANTIC_APPALACHIA) +def_us_state("MD", "Maryland", ATLANTIC_APPALACHIA) +def_us_state("NC", "North Carolina", ATLANTIC_APPALACHIA) +def_us_state("PA", "Pennsylvania", ATLANTIC_APPALACHIA) +def_us_state("TN", "Tennessee", ATLANTIC_APPALACHIA) +def_us_state("VA", "Virginia", ATLANTIC_APPALACHIA) +def_us_state("WV", "West Virginia", ATLANTIC_APPALACHIA) + +def_us_state("CT", "Connecticut", NORTHEAST) +def_us_state("MA", "Massachusetts", NORTHEAST) +def_us_state("ME", "Maine", NORTHEAST) +def_us_state("NH", "New Hampshire", NORTHEAST) +def_us_state("NJ", "New Jersey", NORTHEAST) +def_us_state("NY", "New York", NORTHEAST) +def_us_state("RI", "Rhode Island", NORTHEAST) +def_us_state("VT", "Vermont", NORTHEAST) + +console.log("const us_state_count =", US_STATES.length) + +fs.writeFileSync("data.js", "const US_STATES = " + JSON.stringify(US_STATES, 0, 0) + "\nif (typeof module !== 'undefined') module.exports = { US_STATES }\n") |