From 1aff0bfde49ff8e741c6d2f6a895e6092fb693be Mon Sep 17 00:00:00 2001 From: Grzegorz Koperwas Date: Mon, 20 Apr 2020 20:08:52 +0200 Subject: [PATCH 01/12] test --- ...meta~HEAD.meta => RestSharp.106.10.1.meta} | 3 +- Leaderboard/.flaskenv | 1 + Leaderboard/app/static/footer.html | 13 +++++++ Leaderboard/app/templates/index.html | 38 ++++++++++++++++--- 4 files changed, 49 insertions(+), 6 deletions(-) rename Assets/Packages/{RestSharp.106.10.1.meta~HEAD.meta => RestSharp.106.10.1.meta} (67%) create mode 100644 Leaderboard/app/static/footer.html diff --git a/Assets/Packages/RestSharp.106.10.1.meta~HEAD.meta b/Assets/Packages/RestSharp.106.10.1.meta similarity index 67% rename from Assets/Packages/RestSharp.106.10.1.meta~HEAD.meta rename to Assets/Packages/RestSharp.106.10.1.meta index 4b3e0f21..c8171d06 100644 --- a/Assets/Packages/RestSharp.106.10.1.meta~HEAD.meta +++ b/Assets/Packages/RestSharp.106.10.1.meta @@ -1,5 +1,6 @@ fileFormatVersion: 2 -guid: 34c95602c3761856aa40d3c321bda096 +guid: 1f62f437c3b3438f78268032134cf48a +folderAsset: yes DefaultImporter: externalObjects: {} userData: diff --git a/Leaderboard/.flaskenv b/Leaderboard/.flaskenv index 6006c26d..83c378f7 100644 --- a/Leaderboard/.flaskenv +++ b/Leaderboard/.flaskenv @@ -1 +1,2 @@ FLASK_APP=microblog.py +FLASK_ENV=development diff --git a/Leaderboard/app/static/footer.html b/Leaderboard/app/static/footer.html new file mode 100644 index 00000000..30bd212d --- /dev/null +++ b/Leaderboard/app/static/footer.html @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/Leaderboard/app/templates/index.html b/Leaderboard/app/templates/index.html index de8c7b48..4927bd28 100644 --- a/Leaderboard/app/templates/index.html +++ b/Leaderboard/app/templates/index.html @@ -4,6 +4,36 @@ LD46 Leaderboard +

GameName Leaderboard:

Map list:

@@ -13,9 +43,7 @@

Map list:

{% endfor %}
- +
+ +
\ No newline at end of file From 8a6b810e3d96e2cacba7d7e45f8fd3b604952d23 Mon Sep 17 00:00:00 2001 From: Grzegorz Koperwas Date: Mon, 20 Apr 2020 20:50:26 +0200 Subject: [PATCH 02/12] site, now with meme --- Leaderboard/app/static/footer.html | 27 +++++----- Leaderboard/app/static/main.css | 24 ++++++++- Leaderboard/app/templates/board.html | 73 ++++++++++++++++++++-------- Leaderboard/app/templates/index.html | 14 ++++-- 4 files changed, 99 insertions(+), 39 deletions(-) diff --git a/Leaderboard/app/static/footer.html b/Leaderboard/app/static/footer.html index 30bd212d..f01e912f 100644 --- a/Leaderboard/app/static/footer.html +++ b/Leaderboard/app/static/footer.html @@ -1,13 +1,14 @@ - - - - - - -
-
-

Source code available on Github.
- LudumDare link TODO.

-
- - \ No newline at end of file +
+
+ + + + + + + + + +
+

+
\ No newline at end of file diff --git a/Leaderboard/app/static/main.css b/Leaderboard/app/static/main.css index f79c1ae3..0b1d27dd 100644 --- a/Leaderboard/app/static/main.css +++ b/Leaderboard/app/static/main.css @@ -98,14 +98,36 @@ body { bottom: 0; left: 0; width: 100%; - text-align: center; background-color: #848484; } + td.footer { + padding-left: 2cm; + padding-right: 2cm; + } + footer > table { + margin-left: auto; + margin-right: auto; + } + .listContainer { max-width: 18cm; margin-top: 1cm; margin-bottom: 2cm; + margin-left: auto; + margin-right: auto; + } + .smoll { + font-size: 5pt; + } + img { + max-width: 14cm; + margin-left: auto; + margin-right: auto; + } + .forceDown { + position: fixed; + bottom: 0; } \ No newline at end of file diff --git a/Leaderboard/app/templates/board.html b/Leaderboard/app/templates/board.html index 685aeac9..8156e497 100644 --- a/Leaderboard/app/templates/board.html +++ b/Leaderboard/app/templates/board.html @@ -3,26 +3,57 @@ LD46 Leaderboard + -

{{ level }} Leaderboard:

-

Go back

-
- - - - - - {% for player in players %} - - - - - {% endfor %} -
PlayerTime
{{player.name}}{{player.time}}
-
-
-
-

Source code available on Github.
- LudumDare link TODO.

-
+ + +

{{ level }} Leaderboard:

+

Go back

+
+ + + + + + {% for player in players %} + + + + + {% endfor %} +
PlayerTime
{{player.name}}{{player.time}}
+
+
+ + \ No newline at end of file diff --git a/Leaderboard/app/templates/index.html b/Leaderboard/app/templates/index.html index 4927bd28..d7202a37 100644 --- a/Leaderboard/app/templates/index.html +++ b/Leaderboard/app/templates/index.html @@ -3,6 +3,7 @@ LD46 Leaderboard +

GameName Leaderboard:

@@ -42,8 +42,14 @@

Map list:

  • {{map.name}}
  • {% endfor %} +
    +
    +

    This game in a nutshell:

    + Merge error meme +
    -
    - -
    +
    + \ No newline at end of file From 50c2ec08a561dded606a2dcf6f087c70a70694da Mon Sep 17 00:00:00 2001 From: Grzegorz Koperwas Date: Mon, 20 Apr 2020 21:00:23 +0200 Subject: [PATCH 03/12] style improvment --- Leaderboard/app/static/main.css | 8 ++++++-- Leaderboard/app/templates/index.html | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Leaderboard/app/static/main.css b/Leaderboard/app/static/main.css index 0b1d27dd..53aa7570 100644 --- a/Leaderboard/app/static/main.css +++ b/Leaderboard/app/static/main.css @@ -102,8 +102,8 @@ body { } td.footer { - padding-left: 2cm; - padding-right: 2cm; + padding-left: 2ex; + padding-right: 2ex; } footer > table { margin-left: auto; @@ -122,6 +122,7 @@ body { } img { max-width: 14cm; + max-width: 100%; margin-left: auto; margin-right: auto; } @@ -129,5 +130,8 @@ body { position: fixed; bottom: 0; } + body { + max-width: 100%; + } \ No newline at end of file diff --git a/Leaderboard/app/templates/index.html b/Leaderboard/app/templates/index.html index d7202a37..0fe94405 100644 --- a/Leaderboard/app/templates/index.html +++ b/Leaderboard/app/templates/index.html @@ -48,6 +48,7 @@

    This game in a nutshell:

    Merge error meme +

    {{ level }} Leaderboard:

    -

    Go back

    + +
    + Go back +
    +
    diff --git a/Leaderboard/app/templates/downloads.html b/Leaderboard/app/templates/downloads.html new file mode 100644 index 00000000..610636fd --- /dev/null +++ b/Leaderboard/app/templates/downloads.html @@ -0,0 +1,54 @@ + + + + Play the GameName + + + + +

    GameName links

    +
    + +
    + Go back +
    +
    +

    You can download the binaries from here.

    +

    You can play this game in your browser here.

    +
    + It just works meme +
    +
    +
    + + \ No newline at end of file diff --git a/Leaderboard/app/templates/index.html b/Leaderboard/app/templates/index.html index 0fe94405..b52f1fd2 100644 --- a/Leaderboard/app/templates/index.html +++ b/Leaderboard/app/templates/index.html @@ -36,6 +36,11 @@

    GameName Leaderboard:

    + +
    + Play the game! +
    +

    Map list:

      {% for map in maps %} @@ -45,7 +50,7 @@

      Map list:

      This game in a nutshell:

      - Merge error meme + Merge error meme
    From 8216f1a417bde62601808ba37027dc10dab05321 Mon Sep 17 00:00:00 2001 From: Grzegorz Koperwas Date: Mon, 20 Apr 2020 22:42:05 +0200 Subject: [PATCH 05/12] fixed css --- Leaderboard/app/static/main.css | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Leaderboard/app/static/main.css b/Leaderboard/app/static/main.css index 1998e3cb..d141f8ba 100644 --- a/Leaderboard/app/static/main.css +++ b/Leaderboard/app/static/main.css @@ -35,6 +35,9 @@ body { hr { visibility: hidden; } + table.calendar { + margin-top: 2em; + } th.day-header { background-color: #848484; color: white; @@ -156,9 +159,9 @@ body { } table { + margin-top: 0; margin-left: auto; margin-right: auto; - margin-top: 1cm; } li { margin-top: 1em; From 04e4e6d7e5195fa6e22547231f89ecb467f93f1f Mon Sep 17 00:00:00 2001 From: Grzegorz Koperwas Date: Mon, 20 Apr 2020 23:02:54 +0200 Subject: [PATCH 06/12] Downported so server can run on server --- Leaderboard/app/routes.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Leaderboard/app/routes.py b/Leaderboard/app/routes.py index 3e215fd4..6cea3c29 100644 --- a/Leaderboard/app/routes.py +++ b/Leaderboard/app/routes.py @@ -10,6 +10,14 @@ def GenerateMapList(data): maps.append(x['level']) return maps +def timeFromIso(string): + try: + return datetime.time.fromisoformat(string) + except AttributeError: + h, m, s = [int(x) for x in str(string).split(':')] + return datetime.time(h, m, s) + + debug = True if debug: database = TinyDB('test.json') @@ -32,7 +40,7 @@ def Downloads(): def board(level): entry = Query() entries = database.search(entry.level == level) - entries.sort(key = lambda item: datetime.time.fromisoformat(item['time'])) + entries.sort(key = lambda item: timeFromIso(item['time'])) return render_template('board.html', players = entries, level = level) @app.route('/api/postTime', methods=['POST']) @@ -41,7 +49,7 @@ def addTime(): try: nick = request.form['nick'] level = str(request.form['level']) - iso_time = datetime.time.fromisoformat(request.form['time']) + iso_time = timeFromIso(request.form['time']) time = request.form['time'] if len(nick) > 64: nick = nick[:63] @@ -54,7 +62,7 @@ def addTime(): return {'success': False, 'reason': 'TimeNotISO'} # get Place in leaderboard entry = Query() - is_greater = lambda item: datetime.time.fromisoformat(item) < iso_time + is_greater = lambda item: timeFromIso(item) < iso_time res = database.count((entry.time.test(is_greater)) & (entry.level == level)) database.insert({'name': nick, 'time': time, 'level': level}) return {'place': res + 1, 'success': True} @@ -67,7 +75,7 @@ def getTimes(level, name = None): times = database.search(entry.level == level) else: times = database.search((entry.name == name) & (entry.level == level)) - times.sort(key = lambda item: datetime.time.fromisoformat(item['time'])) + times.sort(key = lambda item: timeFromIso(item['time'])) if times == None: return {'success': True, 'times': list()} if len(times) == 0: From 1c06c94a1aa66851da00576f1f9811d11cb34c6a Mon Sep 17 00:00:00 2001 From: Grzegorz Koperwas Date: Mon, 20 Apr 2020 23:25:14 +0200 Subject: [PATCH 07/12] improved start.sh so server can run without console --- Leaderboard/.flaskenv | 1 - Leaderboard/app/routes.py | 1 - Leaderboard/start.sh | 3 ++- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Leaderboard/.flaskenv b/Leaderboard/.flaskenv index 83c378f7..6006c26d 100644 --- a/Leaderboard/.flaskenv +++ b/Leaderboard/.flaskenv @@ -1,2 +1 @@ FLASK_APP=microblog.py -FLASK_ENV=development diff --git a/Leaderboard/app/routes.py b/Leaderboard/app/routes.py index 6cea3c29..d937efdb 100644 --- a/Leaderboard/app/routes.py +++ b/Leaderboard/app/routes.py @@ -53,7 +53,6 @@ def addTime(): time = request.form['time'] if len(nick) > 64: nick = nick[:63] - print(nick, level, time) if level not in maps: maps.append(level) except KeyError: diff --git a/Leaderboard/start.sh b/Leaderboard/start.sh index f4708ce9..7fca5d31 100755 --- a/Leaderboard/start.sh +++ b/Leaderboard/start.sh @@ -1,2 +1,3 @@ #! /bin/bash -flask run --host=0.0.0.0 +echo "Press c-z and disown" +flask run --host=0.0.0.0 > log.log From 4ecea7fe4afe3e09b1f02ee50c079e2f2f63cf60 Mon Sep 17 00:00:00 2001 From: Grzegorz Koperwas Date: Mon, 20 Apr 2020 23:51:43 +0200 Subject: [PATCH 08/12] fixed titles --- Leaderboard/app/static/main.css | 5 +++++ Leaderboard/app/templates/board.html | 2 +- Leaderboard/app/templates/downloads.html | 2 +- Leaderboard/app/templates/index.html | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Leaderboard/app/static/main.css b/Leaderboard/app/static/main.css index d141f8ba..bf22e59e 100644 --- a/Leaderboard/app/static/main.css +++ b/Leaderboard/app/static/main.css @@ -13,6 +13,11 @@ body { h1, h2, h3, h4 { margin: 5px; } + + h1 { + margin-top: 1em; + margin-bottom: 1em; + } div.interface { max-width: 15cm; diff --git a/Leaderboard/app/templates/board.html b/Leaderboard/app/templates/board.html index d2c6374e..c89bfbb2 100644 --- a/Leaderboard/app/templates/board.html +++ b/Leaderboard/app/templates/board.html @@ -35,8 +35,8 @@ } } -

    {{ level }} Leaderboard:

    +

    {{ level }} Leaderboard:

    Go back diff --git a/Leaderboard/app/templates/downloads.html b/Leaderboard/app/templates/downloads.html index 610636fd..00ee0e78 100644 --- a/Leaderboard/app/templates/downloads.html +++ b/Leaderboard/app/templates/downloads.html @@ -34,8 +34,8 @@ } } -

    GameName links

    +

    GameName links

    Go back diff --git a/Leaderboard/app/templates/index.html b/Leaderboard/app/templates/index.html index b52f1fd2..36f71692 100644 --- a/Leaderboard/app/templates/index.html +++ b/Leaderboard/app/templates/index.html @@ -34,8 +34,8 @@ } } -

    GameName Leaderboard:

    +

    GameName Leaderboard:

    Play the game! From def11c0910bf6fdaa8677f6aec1019f1f7d0eeda Mon Sep 17 00:00:00 2001 From: Grzegorz Koperwas Date: Tue, 21 Apr 2020 02:42:00 +0200 Subject: [PATCH 09/12] added title --- Leaderboard/app/templates/downloads.html | 2 +- Leaderboard/app/templates/index.html | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Leaderboard/app/templates/downloads.html b/Leaderboard/app/templates/downloads.html index 00ee0e78..9d6c56c6 100644 --- a/Leaderboard/app/templates/downloads.html +++ b/Leaderboard/app/templates/downloads.html @@ -35,7 +35,7 @@ }
    -

    GameName links

    +

    Baby: Don't Hurt Me links

    Go back diff --git a/Leaderboard/app/templates/index.html b/Leaderboard/app/templates/index.html index 36f71692..38d9c62f 100644 --- a/Leaderboard/app/templates/index.html +++ b/Leaderboard/app/templates/index.html @@ -35,7 +35,7 @@ }
    -

    GameName Leaderboard:

    +

    Baby: Don't Hurt Me Leaderboard:

    Play the game! @@ -46,6 +46,7 @@

    Map list:

    {% for map in maps %}
  • {{map.name}}
  • {% endfor %} +
  • Per map support is coming soon!
  • From edc22cfd60e31eadbf43b2e1277a37fde28fa1c3 Mon Sep 17 00:00:00 2001 From: Grzegorz Koperwas Date: Tue, 21 Apr 2020 02:57:38 +0200 Subject: [PATCH 10/12] tests --- Leaderboard/app/routes.py | 3 ++- Leaderboard/app/static/footer.html | 2 +- Leaderboard/leaderBoard.json | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 Leaderboard/leaderBoard.json diff --git a/Leaderboard/app/routes.py b/Leaderboard/app/routes.py index d937efdb..f46b4437 100644 --- a/Leaderboard/app/routes.py +++ b/Leaderboard/app/routes.py @@ -18,10 +18,11 @@ def timeFromIso(string): return datetime.time(h, m, s) -debug = True +debug = False if debug: database = TinyDB('test.json') else: + print('Running in production') database = TinyDB('leaderBoard.json') maps = GenerateMapList(database) diff --git a/Leaderboard/app/static/footer.html b/Leaderboard/app/static/footer.html index f01e912f..db43bff2 100644 --- a/Leaderboard/app/static/footer.html +++ b/Leaderboard/app/static/footer.html @@ -3,7 +3,7 @@
    Player
    - + diff --git a/Leaderboard/leaderBoard.json b/Leaderboard/leaderBoard.json new file mode 100644 index 00000000..e9b18176 --- /dev/null +++ b/Leaderboard/leaderBoard.json @@ -0,0 +1 @@ +{"_default": {}} \ No newline at end of file From 044f9621283c319d7b3cf20876b972ca130914fb Mon Sep 17 00:00:00 2001 From: Grzegorz Koperwas Date: Tue, 21 Apr 2020 04:06:33 +0200 Subject: [PATCH 11/12] updated links --- Leaderboard/app/static/footer.html | 2 +- Leaderboard/app/templates/downloads.html | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Leaderboard/app/static/footer.html b/Leaderboard/app/static/footer.html index db43bff2..8ee5e2f1 100644 --- a/Leaderboard/app/static/footer.html +++ b/Leaderboard/app/static/footer.html @@ -3,7 +3,7 @@
    - + diff --git a/Leaderboard/app/templates/downloads.html b/Leaderboard/app/templates/downloads.html index 9d6c56c6..f37e73f3 100644 --- a/Leaderboard/app/templates/downloads.html +++ b/Leaderboard/app/templates/downloads.html @@ -42,7 +42,8 @@

    Baby: Don't Hurt Me links

    You can download the binaries from here.

    -

    You can play this game in your browser here.

    +

    You can play this game in your browser here.

    +

    More info and feedback at Ludum-Dare page.

    It just works meme From 286aa9b5b54013c24ae9f0441ca83e8634c3a89a Mon Sep 17 00:00:00 2001 From: Grzegorz Koperwas Date: Tue, 21 Apr 2020 20:46:20 +0200 Subject: [PATCH 12/12] fuck restSharp --- Assets/Scripts/LeaderBoardHandler.cs | 57 ++++++++++++++++++---------- Leaderboard/app/routes.py | 2 +- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/Assets/Scripts/LeaderBoardHandler.cs b/Assets/Scripts/LeaderBoardHandler.cs index c85d20cf..6310a76d 100644 --- a/Assets/Scripts/LeaderBoardHandler.cs +++ b/Assets/Scripts/LeaderBoardHandler.cs @@ -15,8 +15,9 @@ i zwraca miejsce w rankingu (UploadTime_and_get_place(username)) using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.Networking; using System.Net; -using RestSharp; +using System.Text; public class LeaderBoardHandler : MonoBehaviour { @@ -25,13 +26,22 @@ public class LeaderBoardHandler : MonoBehaviour public string LevelName; private System.DateTime startTime; private System.DateTime stopTime; - private RestClient client = new RestClient("http://grzegorzkoperwas.site:5000"); + [SerializeField] + private bool debug_server; + private string url; public void Awake() { + if (debug_server) { + url = "http://localhost:5000"; + Debug.LogWarning("Running leaderboard in debug mode"); + } + else { + url = "http://grzegorzkoperwas.site:5000"; + } StartTimer(); } @@ -62,29 +72,34 @@ public string GetCurrentTime() { // Uploads time to server under (username) and returns place in ranking public int UploadTime_and_get_place(string username = "testUsername") { - var request = new RestRequest("/api/postTime", Method.POST); - request.AddParameter("nick", username); - request.AddParameter("time", GetFinalTimeISO()); - request.AddParameter("level", LevelName); - try + var args = new List(); + args.Add(new MultipartFormDataSection("nick", Encoding.UTF8.GetBytes(username))); + args.Add(new MultipartFormDataSection("time", Encoding.UTF8.GetBytes(GetFinalTimeISO()))); + args.Add(new MultipartFormDataSection("level", Encoding.UTF8.GetBytes(LevelName))); + var addres = url + "/api/postTime"; + Debug.Log("Connecting…"); + var response = UnityWebRequest.Post(addres, args); + response.SendWebRequest(); + while (!response.isDone) { - var response = client.Execute(request); - if (response.StatusCode == HttpStatusCode.OK && response.Data.success) { - return response.Data.place; + + } + if (response.isNetworkError || response.isHttpError) { + Debug.LogWarning("http or network error"); + return -1; + } + else { + try + { + var val = response.downloadHandler.text; + return int.Parse(val); } - else { + catch (System.Exception e) + { + Debug.Log("Failed decoding response"); + Debug.Log(e); return -1; } } - catch (System.Exception) - { - throw; - } - } - - // class for RestRequest returns - public class PostResponse { - public bool success { get; set; } - public int place { get; set; } } } diff --git a/Leaderboard/app/routes.py b/Leaderboard/app/routes.py index f46b4437..6291cf07 100644 --- a/Leaderboard/app/routes.py +++ b/Leaderboard/app/routes.py @@ -65,7 +65,7 @@ def addTime(): is_greater = lambda item: timeFromIso(item) < iso_time res = database.count((entry.time.test(is_greater)) & (entry.level == level)) database.insert({'name': nick, 'time': time, 'level': level}) - return {'place': res + 1, 'success': True} + return str(res + 1) @app.route('/api/getTimes/') @app.route('/api/getTimes//')