diff --git a/IPreoject-CLientSide/__pycache__/main.cpython-38.pyc b/IPreoject-CLientSide/__pycache__/main.cpython-38.pyc
index f9dfe77..33f58f9 100644
Binary files a/IPreoject-CLientSide/__pycache__/main.cpython-38.pyc and b/IPreoject-CLientSide/__pycache__/main.cpython-38.pyc differ
diff --git a/IPreoject-CLientSide/card1.jpg b/IPreoject-CLientSide/card1.jpg
new file mode 100644
index 0000000..64f2759
Binary files /dev/null and b/IPreoject-CLientSide/card1.jpg differ
diff --git a/IPreoject-CLientSide/main.py b/IPreoject-CLientSide/main.py
index b0c7036..c048e58 100644
--- a/IPreoject-CLientSide/main.py
+++ b/IPreoject-CLientSide/main.py
@@ -1,7 +1,17 @@
-from flask import Flask, render_template, jsonify, Response, request
+import ast
+from flask import Flask, render_template, jsonify, Response, request, send_file
import time
import requests
import json
+from PIL import Image
+from ast import literal_eval
+import ast
+from io import StringIO, BytesIO
+import numpy as np
+import io
+import cv2
+import base64
+
app = Flask(__name__)
@@ -12,13 +22,7 @@ def index():
@app.route("/choose-game", methods=['POST', 'GET'])
def choose_game():
forward_message = "Moving Forward"
- # Get game's modes ....
- # r = requests.get('//API-TO-GAME-SERVER')
- # json_response = json.dumps(r.json())
- # rspone = Response(json_response, content_type='application/json; charset=utf-8')
- # response.headers.add('content-length', len(json_response))
- # response.status_code = 200
- # TO-DO : somthings with res ...
+
return render_template('menu.html', forward_message=forward_message)
@@ -35,27 +39,56 @@ def rules():
-@app.route("/new-game", methods=['POST', 'GET'])
-def new_game():
- return render_template('new-game.html')
@app.route("/join-game", methods=['POST', 'GET'])
def join_game():
return None
# TO-DO
-API_URL1 = "http://192.168.37.69:50000"
+
-#GET PORTS :------------------------------------------------------
+API_URL1 = "http://192.168.37.69:50000"
API_URL2 = "http://192.168.37.69:50000/port"
-# @app.route("/test", methods=['GET'])
-# def test():
-# res = requests.get(API_URL2)
-# port = res.json()
-# return 'Our port is :' + str(port.get('numport')) # our port
-# # return port
+
+#------------------------------------------ Cards -----------------------------------------
+def serve_pil_image(pil_img):
+ img_io = BytesIO()
+ pil_img.save(img_io, 'JPEG', quality=70)
+ img_io.seek(0)
+ return send_file(img_io, mimetype='image/jpeg')
+
+def stringToRGB(base64_string):
+ imgdata = base64.b64decode(str(base64_string))
+ image = Image.open(io.BytesIO(imgdata))
+ return cv2.cvtColor(np.array(image), cv2.COLOR_BGR2RGB)
+
+
+
+API_CARD = "http://192.168.37.69:50001/cards"
+
+@app.route("/new-game", methods=['POST', 'GET'])
+def getCards():
+ res = requests.get(API_CARD).json()
+ card = res.get('la_carte') # our port
+ cards_array = np.array(json.loads(card))
+ img = Image.fromarray(np.uint8(cards_array))
+ pil_img = serve_pil_image(img)
+ print(type(pil_img))
+ pil_img.direct_passthrough = False
+ print(type(pil_img.data))
+ imageStream = io.BytesIO(pil_img.data)
+ imageFile = Image.open(imageStream)
+ print(type(imageFile))
+ buffer = io.BytesIO()
+ imageFile.save(buffer, format='JPEG')
+ print(type(imageFile))
+ card = imageFile.save("./static/images/temp/card1.jpg")
+ return render_template('new-game.html')
+
+
+
@app.route("/apitest", methods=['POST', 'GET'])
@@ -67,50 +100,12 @@ def apitest():
# log the user out
return render_template('test.html', X = x)
-# port = 0
-# def getPort():
-# res = requests.get(API_URL2)
-# port = res.json()
-# return port.get('numport') # our port
-
-# port = getPort()
-
-# PORT = requests.get(API_URL2)
-
-
-
-
-
-# @app.route("/some-url", methods=['GET'])
-# def get_data():
-# res = requests.get("http://my-api.com")
-# return res.content
-
-
-#TEST Here ...
@app.route("/getPixels", methods=['GET'])
def getPixels():
return render_template('test.html')
-# TODO : Req to Discovery service > CardManager
-# Get All cards > store
-# Send cards to the view
-# Manipulate each card
-# Implement the logic <> IA ):
-
-
-
-#TO-DO :
- # WAIT CARDS
- # SEND UR RESPONSE
- # SCORE ++ OR --
- # IF SCORE
- # Get the timer
- # Show it
- #
-
if __name__ == "__main__":
diff --git a/IPreoject-CLientSide/static/images/temp/card1.jpg b/IPreoject-CLientSide/static/images/temp/card1.jpg
new file mode 100644
index 0000000..80d04bb
Binary files /dev/null and b/IPreoject-CLientSide/static/images/temp/card1.jpg differ
diff --git a/IPreoject-CLientSide/static/js/new-g.js b/IPreoject-CLientSide/static/js/new-g.js
index f8418ff..d28193d 100644
--- a/IPreoject-CLientSide/static/js/new-g.js
+++ b/IPreoject-CLientSide/static/js/new-g.js
@@ -167,13 +167,6 @@ function clickEvent2(e) {
}
}
- // var xhr = new XMLHttpRequest();
- // xhr.open("POST", yourUrl, true);
- // xhr.setRequestHeader('Content-Type', 'application/json');
- // xhr.send(JSON.stringify({
- // x: x,
- // y: y
- // }))
}
diff --git a/IPreoject-CLientSide/static/js/test.js b/IPreoject-CLientSide/static/js/test.js
deleted file mode 100644
index ccf96c0..0000000
--- a/IPreoject-CLientSide/static/js/test.js
+++ /dev/null
@@ -1,4 +0,0 @@
-output = 4;
-function so() {
- return output;
-}
\ No newline at end of file
diff --git a/IPreoject-CLientSide/templates/main.html b/IPreoject-CLientSide/templates/main.html
index bba039c..c8b267c 100644
--- a/IPreoject-CLientSide/templates/main.html
+++ b/IPreoject-CLientSide/templates/main.html
@@ -37,9 +37,9 @@
Choose the time of the part..
Click on the top card to detect the commun object with the bottom card..
+Click on the top card to detect the common object with the bottom card..
------------------
+Accept the challenge to start the game, good luck to Spot it :)
diff --git a/IPreoject-CLientSide/templates/new-game.html b/IPreoject-CLientSide/templates/new-game.html index 4734392..11e9aa4 100644 --- a/IPreoject-CLientSide/templates/new-game.html +++ b/IPreoject-CLientSide/templates/new-game.html @@ -33,7 +33,8 @@Rule 1 : Choose the necessary time to play the part ..
Rule 2 : Click on the top card to detect the common object with the bottom card..
-Rule 3 : Accept the challenge to start the game, the goog luck to Spot it :)
+Rule 3 : Accept the challenge to start the game, good luck to Spot it :)
- ---- POSITION and COLOR ---- -
- - -- {{X}} -
- - - - - - \ No newline at end of file diff --git a/IPreoject-CLientSide/utils/test.py b/IPreoject-CLientSide/utils/test.py deleted file mode 100644 index 9b4eff8..0000000 --- a/IPreoject-CLientSide/utils/test.py +++ /dev/null @@ -1,20 +0,0 @@ -# import js2py - -# js = """../static/js/test.js""" - -# context = js2py.EvalJs() -# context.execute(js) -# print(context.output) -import execjs - - -print(execjs.eval("'red yellow blue'.split(' ')")) - -ctx = execjs.compile(""" - function add(x, y) { - return x + y; - } - -""") - -print(ctx.call("add", 1, 2)) \ No newline at end of file