Skip to content

Commit

Permalink
This is nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Nov 30, 2013
0 parents commit bb1985e
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
__pycache__/*
googleinfo.txt
cards/*
*.csv
Binary file added bunny.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions etg.js
@@ -0,0 +1,18 @@
function loadcards(){
var Cards = {}
var names = ["pillar", "weapon", "shield", "permanent", "spell", "creature"]
var xhr = new XMLHttpRequest();
for(var i=0; i<names.length; i++){
xhr.open("GET",names[i] + ".csv",false);
xhr.send();
var csv = xhr.responseText.split("\n");
var keys = csv[0].split(",")
for(var j=1; j<csv.length; j++){
var card = {type: i};
var carddata = csv[j].split(",");
for(var k=0; k<carddata.length; k++)card[keys[k].toLowerCase()] = carddata[k];
Cards[carddata[1] in Cards?carddata[1]+"Up":carddata[1]] = Cards[carddata[2]] = card;
}
}
return Cards;
}
93 changes: 93 additions & 0 deletions pixi.htm
@@ -0,0 +1,93 @@
<html>
<head>
<title>openEtG</title>
<style>
body {
background-color: #000000;
}
</style>
<script src="pixi.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="etg.js"></script>
</head>
<body>
<script>
var m_w = 0;
var m_z = 987654321;
function seed(i) {
m_w = i;
}
function random()
{
var mask = 0xffffffff;
m_z = (36969 * (m_z & 65535) + (m_z >> 16)) & mask;
m_w = (18000 * (m_w & 65535) + (m_w >> 16)) & mask;
var result = ((m_z << 16) + m_w) & mask;
result /= 4294967296;
return result + 0.5;
}
function shuffle(array) {
var counter = array.length, temp, index;
while (counter--) {
index = (Math.random() * counter) | 0;
temp = array[counter];
array[counter] = array[index];
array[index] = temp;
}
return array;
}
var Cards = loadcards();
var renderer = PIXI.autoDetectRenderer(920, 540);
document.body.appendChild(renderer.view);
var id = null;
var menuui = new PIXI.Stage(0x336699, true);
var gameui = new PIXI.Stage(0x336699, true);
var mainStage = menuui;

var nopic = PIXI.Texture.fromImage("bunny.png");
function getCardImage(code){
return PIXI.Texture.fromImage("cards/"+code+".png");
}
var deck = ['4vc', '4vc', '4vc', '4vc', '4vc', '4vc', '4vc', '4vc', '4vc', '4vc', '4vc', '4vc', '4vc', '4vc', '4vc', '4vc', '4vc', '4vc', '4vc', '4vc', '4ve', '4ve', '4ve', '4ve', '4ve', '4vf', '4vf', '4vf', '4vf', '4vf'];
var gameDeck;

var bpvp = new PIXI.Sprite(nopic);
bpvp.position.x = 200;
bpvp.position.y = 200;
bpvp.setInteractive(true);
menuui.addChild(bpvp);
bpvp.click = function(x) {
if (id != null){
socket.emit("pvpwant", {id: id});
}
}
hand = new Array(8);
for (var i=0; i<8; i++){
hand[i] = new PIXI.Sprite(nopic);
hand[i].position.x=600;
hand[i].position.y=200+20*i;
hand[i].setInteractive(true);
gameui.addChild(hand[i]);
}
var socket = io.connect('http://localhost');
socket.on("idgive", function(data) {
id = data.id;
});
socket.on("pvpgive", function(data) {
foeId = data.foeId;
gameDeck = shuffle(deck).slice(0);
for(var i=0;i<7;i++){
hand[i].setTexture(getCardImage(gameDeck.pop()));
}
seed(data.seed)
mainStage = gameui;
});

function animate() {
renderer.render(mainStage);
requestAnimFrame(animate);
}
requestAnimFrame(animate);
</script>
</body>
</html>
15 changes: 15 additions & 0 deletions pixi.js

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions server.js
@@ -0,0 +1,58 @@
var http = require('http');
var app = http.createServer(handler);
var io = require('socket.io').listen(app);
var fs = require('fs');
app.listen(80);

function handler (req, res) {
if (req.url.indexOf("..") != -1)
return;
if (req.url.indexOf("/cards/") == 0){
var request=http.get("http://dek.im/resources/card_images/"+req.url.substring(7), function (getres) {
getres.on("data", function(data){
res.write(data);
});
getres.on("end", function(){
res.end();
});
});
}else{
var url = req.url == "/"?"/pixi.htm":req.url;
fs.readFile(__dirname + url, function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading '+url);
}
res.writeHead(200);
res.end(data);
});
}
}

var pendinggame = null;
var socktoid = {};
var idtosock = {};

io.sockets.on('connection', function (socket) {
var sockId = Math.random();
idtosock[sockId] = socket;
socktoid[socket] = sockId;
socket.emit('idgive', {id: sockId});
socket.on('disconnect', function(data) {
delete idtosock[socktoid[socket]];
delete socktoid[socket];
});
socket.on('pvpwant', function (data) {
console.log(data);
if (pendinggame != null){
var ownId = socktoid[socket];
var seed = Math.random()*4294967296;
var first = seed<(4294967296/2)?pendinggame:ownId;
socket.emit("pvpgive", {foeId: pendinggame, first:first, seed:seed});
idtosock[pendinggame].emit("pvpgive", {foeId: ownId, first:first, seed:seed});
pendinggame = null;
}else{
pendinggame = data.id;
}
});
});
31 changes: 31 additions & 0 deletions updatedb.py
@@ -0,0 +1,31 @@
#!/usr/bin/python
import re
from urllib.request import Request, urlopen
from urllib.parse import urlencode
def get_auth_token():
url = "https://www.google.com/accounts/ClientLogin"
params = {
"Email": email, "Passwd": password,
"service": "wise",
"accountType": "HOSTED_OR_GOOGLE",
"source": "etgai"
}
req = Request(url, bytes(urlencode(params), "utf8"))
return re.findall(r"Auth=(.*)", str(urlopen(req).read(), "utf8"))[0]
def download(gid):
return urlopen(Request("https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=0Ao07Zx9C3FLcdFdXV0tpOWhKeDExNmhTdHgwVkg0NFE&exportFormat=csv&gid=%i"%gid, headers={
"Authorization": "GoogleLogin auth=" + get_auth_token(),
"GData-Version": "3.0"
}))
try:
info=open("googleinfo.txt")
email = info.readline().strip()
password = info.readline().strip()
except:
from getpass import getpass
email = input("gmail: ")
password = getpass("Password: ")
# Request a file-like object containing the spreadsheet's contents
for gid, db in enumerate(("creature", "pillar", "weapon", "shield", "permanent", "spell"), 6):
print(db)
open(db+".csv", "wb").write(download(gid).read())

0 comments on commit bb1985e

Please sign in to comment.