Skip to content

Commit

Permalink
theme backend complete, add theme q param in /battleground/theme
Browse files Browse the repository at this point in the history
  • Loading branch information
STG284 committed Jun 22, 2021
1 parent ee71d7d commit eed43d6
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 50 deletions.
30 changes: 15 additions & 15 deletions battleground/problemData.csv
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
id,words,desc,imageUrl,moreInfoLink
1,lord ganesha,"Ganesha, also known as Ganapati and Vinayaka, is one of the best-known and most worshipped deities in the Hindu pantheon. Hindu denominations worship him regardless of affiliations. Devotion to Ganesha is widely diffused and extends to Jains and Buddhists.",https://imgur.com/Rjw6dXW.png ,https://en.wikipedia.org/wiki/Ganesha
2,India gate,"The India Gate is a war memorial located astride the Rajpath, New Delhi. It stands as a memorial to 70,000 soldiers of the British Indian Army who died in between 1914 and 1921 in the First World War. 13,300 servicemen's names, including some soldiers and officers from the United Kingdom, are inscribed on the gate. Designed by Sir Edwin Lutyens, the gate evokes the architectural style of the triumphal arch.",https://imgur.com/7V8Y08P.png ,https://en.wikipedia.org/wiki/India_Gate
3,bharatnatyam,Bharatanatyam is a major form of Indian classical dance that originated in Tamil Nadu. It has flourished in the temples and courts of southern India since ancient times.,https://imgur.com/6385E5S.png,https://en.wikipedia.org/wiki/Bharatanatyam
4,statue of unity,"The Statue of Unity is a colossal statue of Indian statesman and independence activist Vallabhbhai Patel, who was the first Deputy Prime Minister and Home Minister of independent India and an adherent of Mahatma Gandhi during the nonviolent Indian Independence movement. ",https://imgur.com/PntCGF6.png ,https://statueofunity.in/
5,Swastik,"The word swastika is derived from the Sanskrit swasti(good/auspicious). The swastika symbol, 卐 , is an ancient religious icon in the cultures of Eurasia. It is used as a symbol of divinity and spirituality in Indian religions, including Hinduism, Buddhism and Jainism. The word swastik is prevelent in indian culture since 500 BCE.",https://imgur.com/kdnbLwx.png ,https://en.wikipedia.org/wiki/Swastika
6,Gautam Buddha,"Gautama Buddha, popularly known as the Buddha, was a Śramaṇa who lived in ancient India. He is regarded as the founder of the world religion of Buddhism. He lived during the 5th century B.C. Gautama was born into a wealthy family as a prince in present-day Nepal. Although he had an easy life, Gautama was moved by suffering in the world",https://imgur.com/tr8boPk.png ,https://en.wikipedia.org/wiki/Gautama_Buddha
7,Terracota,"Terracotta-""baked earth"", a type of earthenware, is a clay-based ceramic, where the fired body is porous. Terracotta is the term normally used for sculpture made in earthenware. In India, traditional terracotta sculptures, mainly religious, are made. The demand for this craft is seasonal, mostly when new pottery and votive idols are required during harvest festival.",https://imgur.com/52tMtMB.png ,https://en.wikipedia.org/wiki/Terracotta
8,Indian Railways,"Indian Railways (IR) is a governmental entity under the Ministry of Railways that operates India's national railway system. It is run by the government as a public good and manages the fourth-largest railway network in the world by size, with a route length of 68,155 km as of March 2019. 40,576 km or 64% of all the broad-gauge routes are electrified with 25 kV 50 Hz AC electric traction as of August 2020. ",https://imgur.com/oQq4BTB.png,https://en.wikipedia.org/wiki/Indian_Railways
9,Sitar,"The sitar is a plucked stringed instrument, originating from the Indian subcontinent, used in Hindustani classical music. The instrument was invented in medieval India and flourished in the 16th and 17th centuries and arrived at its present form in 18th-century India. ",https://imgur.com/CxspjKI.png ,https://en.wikipedia.org/wiki/Sitar
10,Taj mahal,"The Taj Mahal is an ivory-white marble mausoleum on the southern bank of the river Yamuna in the Indian city of Agra. It was commissioned in 1632 by the Mughal emperor Shah Jahan to house the tomb of his favourite wife, Mumtaz Mahal; it also houses the tomb of Shah Jahan himself. ",https://imgur.com/tcNuq8D.png ,https://en.wikipedia.org/wiki/Taj_Mahal
11,Mahatma gandhi ,"Mohandas Karamchand Gandhi also known as ""The Father of the Nation(India)""(October 1869 – 30 January 1948) was an Indian lawyer, anti-colonial nationalist, and political ethicist, who employed nonviolent resistance to lead the successful campaign for India's independence from British rule. ",https://i.imgur.com/BZ2Pwlg.jpg,https://en.wikipedia.org/wiki/Mahatma_Gandhi
12,Bhagat Singh ,Bhagat Singh was an Indian socialist revolutionary whose two acts of dramatic violence against the British in India and execution at age 23 made him a folk hero of the Indian independence movement.,https://imgur.com/lC65ynO.png,https://en.wikipedia.org/wiki/Bhagat_Singh
13,Mother Teresa,"Mother Mary Teresa Bojaxhiu, honoured in the Catholic Church as Saint Teresa of Calcutta, was an Albanian-Indian Roman Catholic nun and missionary. She was born in Skopje (now the capital of North Macedonia).After living in Skopje for eighteen years, she moved to Ireland and then to India, where she lived for most of her life.
id,theme,words,desc,imageUrl,moreInfoLink
1,Mythology,lord ganesha,"Ganesha, also known as Ganapati and Vinayaka, is one of the best-known and most worshipped deities in the Hindu pantheon. Hindu denominations worship him regardless of affiliations. Devotion to Ganesha is widely diffused and extends to Jains and Buddhists.",https://imgur.com/Rjw6dXW.png ,https://en.wikipedia.org/wiki/Ganesha
2,Historical monuments,India gate,"The India Gate is a war memorial located astride the Rajpath, New Delhi. It stands as a memorial to 70,000 soldiers of the British Indian Army who died in between 1914 and 1921 in the First World War. 13,300 servicemen's names, including some soldiers and officers from the United Kingdom, are inscribed on the gate. Designed by Sir Edwin Lutyens, the gate evokes the architectural style of the triumphal arch.",https://imgur.com/7V8Y08P.png ,https://en.wikipedia.org/wiki/India_Gate
3,Indian Culture,bharatnatyam,Bharatanatyam is a major form of Indian classical dance that originated in Tamil Nadu. It has flourished in the temples and courts of southern India since ancient times.,https://imgur.com/6385E5S.png,https://en.wikipedia.org/wiki/Bharatanatyam
4,Historical monuments,statue of unity,"The Statue of Unity is a colossal statue of Indian statesman and independence activist Vallabhbhai Patel, who was the first Deputy Prime Minister and Home Minister of independent India and an adherent of Mahatma Gandhi during the nonviolent Indian Independence movement. ",https://imgur.com/PntCGF6.png ,https://statueofunity.in/
5,Mythology,Swastik,"The word swastika is derived from the Sanskrit swasti(good/auspicious). The swastika symbol, 卐 , is an ancient religious icon in the cultures of Eurasia. It is used as a symbol of divinity and spirituality in Indian religions, including Hinduism, Buddhism and Jainism. The word swastik is prevelent in indian culture since 500 BCE.",https://imgur.com/kdnbLwx.png ,https://en.wikipedia.org/wiki/Swastika
6,Personalities,Gautam Buddha,"Gautama Buddha, popularly known as the Buddha, was a Śramaṇa who lived in ancient India. He is regarded as the founder of the world religion of Buddhism. He lived during the 5th century B.C. Gautama was born into a wealthy family as a prince in present-day Nepal. Although he had an easy life, Gautama was moved by suffering in the world",https://imgur.com/tr8boPk.png ,https://en.wikipedia.org/wiki/Gautama_Buddha
7,History,Terracota,"Terracotta-""baked earth"", a type of earthenware, is a clay-based ceramic, where the fired body is porous. Terracotta is the term normally used for sculpture made in earthenware. In India, traditional terracotta sculptures, mainly religious, are made. The demand for this craft is seasonal, mostly when new pottery and votive idols are required during harvest festival.",https://imgur.com/52tMtMB.png ,https://en.wikipedia.org/wiki/Terracotta
8,Indian Culture,Indian Railways,"Indian Railways (IR) is a governmental entity under the Ministry of Railways that operates India's national railway system. It is run by the government as a public good and manages the fourth-largest railway network in the world by size, with a route length of 68,155 km as of March 2019. 40,576 km or 64% of all the broad-gauge routes are electrified with 25 kV 50 Hz AC electric traction as of August 2020. ",https://imgur.com/oQq4BTB.png,https://en.wikipedia.org/wiki/Indian_Railways
9,History,Sitar,"The sitar is a plucked stringed instrument, originating from the Indian subcontinent, used in Hindustani classical music. The instrument was invented in medieval India and flourished in the 16th and 17th centuries and arrived at its present form in 18th-century India. ",https://imgur.com/CxspjKI.png ,https://en.wikipedia.org/wiki/Sitar
10,Historical Monuments,Taj mahal,"The Taj Mahal is an ivory-white marble mausoleum on the southern bank of the river Yamuna in the Indian city of Agra. It was commissioned in 1632 by the Mughal emperor Shah Jahan to house the tomb of his favourite wife, Mumtaz Mahal; it also houses the tomb of Shah Jahan himself. ",https://imgur.com/tcNuq8D.png ,https://en.wikipedia.org/wiki/Taj_Mahal
11,Personalities,Mahatma gandhi ,"Mohandas Karamchand Gandhi also known as ""The Father of the Nation(India)""(October 1869 – 30 January 1948) was an Indian lawyer, anti-colonial nationalist, and political ethicist, who employed nonviolent resistance to lead the successful campaign for India's independence from British rule. ",https://i.imgur.com/BZ2Pwlg.jpg,https://en.wikipedia.org/wiki/Mahatma_Gandhi
12,Personalities,Bhagat Singh ,Bhagat Singh was an Indian socialist revolutionary whose two acts of dramatic violence against the British in India and execution at age 23 made him a folk hero of the Indian independence movement.,https://imgur.com/lC65ynO.png,https://en.wikipedia.org/wiki/Bhagat_Singh
13,Personalities,Mother Teresa,"Mother Mary Teresa Bojaxhiu, honoured in the Catholic Church as Saint Teresa of Calcutta, was an Albanian-Indian Roman Catholic nun and missionary. She was born in Skopje (now the capital of North Macedonia).After living in Skopje for eighteen years, she moved to Ireland and then to India, where she lived for most of her life.
In 1950, Teresa founded the Missionaries of Charity, a Roman Catholic religious congregation that had over 4,500 nuns and was active in 133 countries in 2012",https://imgur.com/zheYwG5.png,https://en.wikipedia.org/wiki/Mother_Teresa
14,Goddess Saraswati,"Saraswati is the Hindu goddess of knowledge, music, art, speech, wisdom, and learning. She is a part of the trinity (Tridevi) of Saraswati, Lakshmi, and Parvati. All the three equal forms unite with the trinity of Brahma, Vishnu, and Shiva to create, maintain, and regenerate the Universe, respectively.",https://imgur.com/fQqXx5i.png,https://en.wikipedia.org/wiki/Saraswati
14,Mythology,Goddess Saraswati,"Saraswati is the Hindu goddess of knowledge, music, art, speech, wisdom, and learning. She is a part of the trinity (Tridevi) of Saraswati, Lakshmi, and Parvati. All the three equal forms unite with the trinity of Brahma, Vishnu, and Shiva to create, maintain, and regenerate the Universe, respectively.",https://imgur.com/fQqXx5i.png,https://en.wikipedia.org/wiki/Saraswati
36 changes: 25 additions & 11 deletions battleground/problemProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fs.createReadStream('battleground/problemData.csv') // path should be relative t
// console.log(data)

let id = data['id'];
let theme = data['theme']
let words = data['words'];
let desc = data['desc'];
let imageUrl = data['imageUrl'];
Expand All @@ -24,6 +25,7 @@ fs.createReadStream('battleground/problemData.csv') // path should be relative t
allWordProblems.push(new ProblemStatement(
ProblemStatement.WORD_TYPE,
id,
theme,
wordTitle,
words,
desc,
Expand All @@ -33,6 +35,7 @@ fs.createReadStream('battleground/problemData.csv') // path should be relative t
allPictureProblems.push(new ProblemStatement(
ProblemStatement.PICTURE_TYPE,
id,
theme,
pictureTitle,
words,
desc,
Expand All @@ -41,23 +44,34 @@ fs.createReadStream('battleground/problemData.csv') // path should be relative t
})


function getRandomWordProblem() {
let high = allWordProblems.length;
let low = 0;
let randI = Math.floor(Math.random() * (high - low) + low);
return allWordProblems[randI];
}
function getRandomProblem(targetTheme, gameType) {
let shortlistedProblems = [];
let baseProblems;
switch (gameType) {
case "word":
baseProblems = allWordProblems;
break;

case "picture":
baseProblems = allPictureProblems;
break;

default:
throw new Error("unknown gameType: " + gameType);
}
baseProblems.forEach(aProblem => {
if (aProblem.theme === targetTheme)
shortlistedProblems.push(aProblem)
});

function getRandomPictureProblem() {
let high = allPictureProblems.length;
let high = shortlistedProblems.length;
let low = 0;
let randI = Math.floor(Math.random() * (high - low) + low);
return allPictureProblems[randI];
return shortlistedProblems[randI];
}

module.exports = Object.freeze({
ProblemProvider: {
getRandomWordProblem: getRandomWordProblem,
getRandomPictureProblem: getRandomPictureProblem
getRandomProblem: getRandomProblem,
}
})
27 changes: 10 additions & 17 deletions battleground/socketEventSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ function initSocketIoCallbacks(_io) {
});
}

function getDefaultInitialisedRoom(gameType) {
function getDefaultInitialisedRoom(gameType, theme) {
return {
data: {
boardData: [],
messages: []
},
gameType: gameType,
theme: theme,
members: [],
allPlayersReadyMap: new Map(),
solutions: new Map(),
Expand All @@ -86,8 +87,9 @@ function onConnection(socket) {
let roomname = data.roomname;
let username = data.username;
let gameType = data.gameType;
let theme = data.theme;

if(!roomname || !username || !gameType){
if(!roomname || !username || !gameType || !theme){
console.log(ColoredLog.red("Rejected socket.on SOCKET_EVENT_COMING ", true));
return;
}
Expand All @@ -100,7 +102,7 @@ function onConnection(socket) {
}
} else {

rooms[roomname] = getDefaultInitialisedRoom(gameType);
rooms[roomname] = getDefaultInitialisedRoom(gameType, theme);
rooms[roomname].members.push(username) // adding current member
console.log("Created new room " + roomname);
}
Expand Down Expand Up @@ -260,20 +262,11 @@ function onConnection(socket) {
if (secBeforeRoundStart == 0) {
clearInterval(socket.roundStartInterval);
let gameType = rooms[socket.roomname].gameType;
let problemStatement;
switch (gameType) {
case ProblemStatement.WORD_TYPE:
problemStatement = ProblemProvider.getRandomWordProblem();
break;

case ProblemStatement.PICTURE_TYPE:
problemStatement = ProblemProvider.getRandomPictureProblem();
break;

default:
throw new Error("Unknown Problem type: " + gameType)
}
console.log("Emiting: problemStatement = " + problemStatement + "] "+gameType);
let theme = rooms[socket.roomname].theme;
let problemStatement = ProblemProvider.getRandomProblem(theme, gameType);

console.log("Emiting: problemStatement = " + JSON.stringify(problemStatement) + ", " + gameType + ", " + theme);

io.in(socket.roomname).emit("startRound", {
problemStatement: problemStatement,
round: 1,
Expand Down
3 changes: 2 additions & 1 deletion models/battleground/problem.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

class ProblemStatement {

constructor(type, id, title, words, desc, imageUrl, moreInfoLink) {
constructor(type, id, theme, title, words, desc, imageUrl, moreInfoLink) {
this.type = type;
this.id = id;
this.theme = theme;
this.title = title;
this.words = words;
this.desc = desc;
Expand Down
1 change: 1 addition & 0 deletions public/js/battleground.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
rtMan.username = window.roomData.username
rtMan.roomname = window.roomData.roomname
rtMan.gameType = window.roomData.gameType
rtMan.theme = window.roomData.theme

rtMan.socket.on('drawing', function (data) {

Expand Down
3 changes: 2 additions & 1 deletion public/js/whiteboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,8 @@
rtMan.socket.emit('coming', {
roomname: rtMan.roomname,
username: rtMan.username,
gameType: rtMan.gameType
gameType: rtMan.gameType,
theme: rtMan.theme
});
});
board.makeReady();
Expand Down
16 changes: 12 additions & 4 deletions routes/battleground.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ router.get('/enter', function (req, res) {

router.post('/enter', function (req, res) {

var roomname = req.body.roomname;
var username = req.body.username;
let roomname = req.body.roomname;
let username = req.body.username;
let theme = req.body.theme;

const joinedRoomname = RoomStaticUtils.getJoinedRoomname(username);
console.log(ColoredLog.red("joinedRoomname: " + joinedRoomname + " by username: " + username, true))
console.log(ColoredLog.red("joinedRoomname: " + joinedRoomname + " by username: " + username + " with theme: " + theme, true))

if (!roomname || roomname.indexOf(' ') > -1 || roomname.length === 0) {
res.send({
Expand All @@ -35,6 +37,12 @@ router.post('/enter', function (req, res) {
msg: 'Invalid Username'
});

} else if (!theme || theme.length === 0) {
res.send({
visibility: 'visible',
msg: 'Invalid theme'
});

} else if (joinedRoomname) {
let msg2ndLine = "Cannot join 2 rooms at once!"

Expand All @@ -52,7 +60,7 @@ router.post('/enter', function (req, res) {

// check if the room alreaddy has a gameType

let roomGameType = RoomStaticUtils.getRoomGameType(roomname); // todo: replace by some util to find the type of room, should return null if room doesn't exists!
let roomGameType = RoomStaticUtils.getRoomGameType(roomname); // returns null if room doesn't exists!
if (!roomGameType) {
// redirect to the same url without gameType
// this will show UI to ask for `gametype`
Expand Down
4 changes: 3 additions & 1 deletion views/battleground.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
const roomname = getQueryVariable("roomname");
const username = getQueryVariable("username");
const gameType = getQueryVariable("gameType");
const theme = getQueryVariable("theme");
// inserting query params into window object ot make it accessible globally
window.roomData = {
roomname: roomname,
username: username,
gameType: gameType
gameType: gameType,
theme: theme
}
</script>

Expand Down

0 comments on commit eed43d6

Please sign in to comment.