-
Notifications
You must be signed in to change notification settings - Fork 1
/
Player.js
136 lines (122 loc) · 3.74 KB
/
Player.js
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
"use strict";
/**
* @file Player.js
* @brief Player data
* @author Sarah Rosanna Busch
* @version 0.1
* @date 16 May 2022
* */
var Player = (function(){
var that = {}; //public methods
let data = { //this gets overwritten by data from server
dndNoob: "",
charName: '',
encounter: "",
choices: [], //for the current encounter
diceRolls: [],
race: '',
class: '',
sex: '',
pronouns: "",
height: 0, //inches
weight: 0, //pounds
eyeColour: '',
hairColour: '',
skinColour: ''
};
let username = '';
that.setUser = function(user) {
username = user;
}
that.initData = function(d) {
data = d.userData;
}
that.getData = function(key) {
return data[key];
}
that.setData = function(key, value) {
data[key] = value;
console.log('player data: ' + key + ' = ' + value);
//save to server
let pd = {
'username': username,
'playerData': {}
};
pd.playerData[key] = value;
let str = JSON.stringify(pd);
f.ajax.post('playerData', str, function(ack) {
console.log(ack);
});
}
// track each player choice in an array
that.saveChoice = function(choice) {
data.choices.push(choice); //save locally
console.log('player choices: ' + data.choices);
//save to server
let str = JSON.stringify({
'username': username,
'playerChoices': data.choices
});
f.ajax.post('playerChoices', str, function(ack) {
console.log(ack);
});
}
that.saveDiceRolls = function(results) {
data.diceRolls.push(results);
console.log('dice rolls: ' + JSON.stringify(data.diceRolls));
let str = JSON.stringify({
'username': username,
'diceRolls': data.diceRolls
});
f.ajax.post('diceRolls', str, function(ack) {
console.log(ack);
});
}
that.getSubjectivePronoun = function() {
let pronoun = data.pronouns.split('/')[0];
if(pronoun === 'any') {
let rnd = Math.floor((Math.random() * 3) + 1);
switch(rnd) {
case 1: pronoun = 'he'; break;
case 2: pronoun = 'she'; break;
case 3: pronoun = 'they'; break;
}
}
return pronoun;
}
that.getObjectivePronoun = function() {
let pronoun = data.pronouns.split('/')[1];
if(pronoun === 'all') {
let rnd = Math.floor((Math.random() * 3) + 1);
switch(rnd) {
case 1: pronoun = 'him'; break;
case 2: pronoun = 'her'; break;
case 3: pronoun = 'them'; break;
}
}
return pronoun;
}
that.getPossessivePronoun = function() {
let pronoun = data.pronouns.split('/')[0];
if(pronoun === 'any') {
let rnd = Math.floor((Math.random() * 3) + 1);
switch(rnd) {
case 1: pronoun = 'his'; break;
case 2: pronoun = 'hers'; break;
case 3: pronoun = 'theirs'; break;
}
} else if(pronoun === 'he') {
pronoun = 'his';
} else {
pronoun = 'hers';
}
return pronoun;
}
that.getHeightString = function() {
let height = data.height;
let feet = Math.floor(height / 12);
let inches = height % 12;
return feet + "'" + inches + '"';
}
return that;
}());