summaryrefslogtreecommitdiff
path: root/play.js
blob: 42c5d40eb76ac521e98fbc640bfdab4f9964758c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
const seed = 'none'
const scenario = 'standard'
const options = 'none'
//const rules = require("./rules")

const dem_infl_markers = []

const stability=0
const US_tiananmen=0
const USSR_tiananmen=0
const toolbar = document.getElementById('toolbar')
const vpMarker = document.getElementById('vp')
const mapContainer = document.querySelector('.map')
let handActive=0
let doInfl=0
let doSupportCheck=0
let demTSTPos=0
let comTSTPos=0
let demTSTPrev=0
let comTSTPrev=0
let turn=1
let actionRound=1
let supportCheckTargetName=''
let supportCheckTargetCountry=0
let vp = 0
let germanyRevolution=0
let polandRevolution=0
let czechRevolution=0
let hungaryRevolution=0
let romaniaRevolution=0
let buglariaRevolution=0
let germanyHeld=0
let polandHeld=0
let czechHeld=0
let hungaryHeld=0
let romaniaHeld=0
let bulgariaHeld=0


const countryNames= [
	null,
	"East Germany",
	"Poland",
	"Czechoslovakia",
	"Hungary",
	"Romania",
	"Bulgaria"
]


const overlay = document.getElementById('overlay');
const spaceNameElement = document.getElementById('space-name');
const spaceCharacteristicsElement = document.getElementById('space-characteristics');


// Event listener to track mouse movement over the map
        document.querySelector('.map').addEventListener('mousemove', function(event) {
            const x = event.offsetX; // X-coordinate of mouse relative to container
            const y = event.offsetY; // Y-coordinate of mouse relative to container
	spaceCharacteristicsElement.innerText = `X: ${x}, Y: ${y}`;
	})


 // Create map areas dynamically based on coordinates

 function create_map() {

	spaces.forEach((space) => {
		if (space && space.box) {
                const { x, y, h, w } = space.box;
                const spaceArea = document.createElement('div');
                spaceArea.classList.add('space-area', space.country)
				spaceArea.id=space.name_unique;
                spaceArea.style.left = x + 'px';
                spaceArea.style.top = y + 'px';
                spaceArea.style.width = w + 'px';
                spaceArea.style.height = h + 'px';
				spaceArea.style.zIndex = 2;
				spaceArea.my_space = space.name_unique;  
        		spaceArea.addEventListener('mousedown', on_click_space);
				//spaceArea.addEventListener('click', finishSupportCheck)

			/*if (space.demInfl > 0 && space.demInfl - space.comInfl >= space.stability) {
				const img = document.createElement('img')
				img.classList.add('demInfl', space.country)
				img.id=space.name
				img.src = `images/US_${space.demInfl}.gif`
				spaceArea.appendChild(img)
			} else if (space.demInfl > 0) {*/
				const dem_img = document.createElement('img')
				dem_img.classList.add('demInfl', space.country)
				dem_img.style.display = 'none'
				dem_img.id=`${space.name_unique}_demInfl`
				dem_img.src = `images/USd_blank.gif`
				dem_img.style.zIndex = 1
				spaceArea.appendChild(dem_img)

				const demInflValue = document.createElement('p')
				demInflValue.className='demInflValue'
				demInflValue.style.display = 'none'
				demInflValue.id=`${space.name_unique}_demInflValue`
				demInflValue.innerText=space.demInfl
				demInflValue.style.zIndex = 1
				spaceArea.appendChild(demInflValue)
			//}

			/*} else if (space.comInfl > 0 && space.comInfl - space.demInfl >= space.stability) {
				const img = document.createElement('img')
				img.className='comInfl'
				img.id=space.name
				img.src = `images/SV_${space.comInfl}.gif`
				spaceArea.appendChild(img)		
			} else if (space.comInfl > 0) {*/
				const com_img = document.createElement('img')
				com_img.className='comInfl'
				com_img.style.display='none'
				com_img.id=`${space.name_unique}_comInfl`
				com_img.src = `images/SVd_blank.gif`
				com_img.style.zIndex = 1
				spaceArea.appendChild(com_img)

				const comInflValue = document.createElement('p')
				comInflValue.className='comInflValue'
				comInflValue.style.display='none'
				comInflValue.id=`${space.name_unique}_comInflValue`
				comInflValue.innerText=space.comInfl
				comInflValue.style.zIndex = 1
				spaceArea.appendChild(comInflValue)
			//} 
		
		mapContainer.appendChild(spaceArea);
		}
	});

}

create_map()

//setup()

console.log('Hello')

//function changeInfl() {}
//function finishSupportCheck() {}

function on_click_space(evt) {
    if (evt.button === 0) {
        const space = evt.target.my_space;
        console.log('on_click_space_called with space:', space);
        if (send_action('infl', space)) {
            evt.stopPropagation();
        } else {
            console.log('send_action failed for space:', space);
        }
    }
    //hide_popup_menu();
}

function is_action(action) {
	console.log('is_action called with: ', action)
	if (view.actions && view.actions[action])
		return true
	return false
}



let ui = {
	favicon: document.getElementById('favicon'),
	player: [
		document.getElementById("role_Democrat"),
		document.getElementById("role_Communist"),
	],
	cards: [ null ],
	events_panel: document.getElementById("events_panel"),
	hand_panel: document.getElementById("hand_panel"),

}

function on_update() {
	console.log('on_update called')
	console.log('view.actions: ', view.actions)

	//Check influence values
	const pieces = view.pieces
	pieces.forEach(piece => {
		const dem_marker = document.getElementById(`${piece.name_unique}_demInfl`);
		const dem_number = document.getElementById(`${piece.name_unique}_demInflValue`);
		const com_marker = document.getElementById(`${piece.name_unique}_comInfl`);
		const com_number = document.getElementById(`${piece.name_unique}_comInflValue`);
		
		dem_number.innerText=piece.demInfl
		if (piece.demInfl > 0) {
			dem_marker.style.display = 'block';
			dem_number.style.display = 'block';
		} else {
			dem_marker.style.display = 'none';
			dem_number.style.display = 'none';
		}
		com_number.innerText=piece.comInfl
		if (piece.comInfl > 0) {
			com_marker.style.display = 'block';
			com_number.style.display = 'block';
			} else {
			com_marker.style.display = 'none';
			com_number.style.display = 'none';
			}
		
	});


	action_button("done", "Done")
	action_button("undo", "Undo")
}