Skip to content

Commit

Permalink
Improved village generation. Saves migration. Bump to 0.02a
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidCaos committed Jul 13, 2022
1 parent 8a9e479 commit 7e0197e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 34 deletions.
2 changes: 1 addition & 1 deletion build/build.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@echo off
set NAME=social-emperors_0.01a
set NAME=social-emperors_0.02a
pyinstaller --onefile --add-data "..\..\assets;assets" --add-data "..\..\flash;flash" --add-data "..\..\stub;stub" --add-data "..\..\templates;templates" --paths ..\..\. --workpath .\work --distpath .\dist --specpath .\bundle --noconfirm --name %NAME% ..\server.py
echo Done.
pause>NUL
10 changes: 5 additions & 5 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

print (" [+] Loading players...")
from get_player_info import get_player_info
from sessions import all_saves_userid, all_saves_info, save_info, new_village
from sessions import load_saved_villages, all_saves_userid, all_saves_info, save_info, new_village
load_saved_villages()

print (" [+] Loading server...")
from flask import Flask, render_template, send_from_directory, request, redirect, session
from flask.debughelpers import attach_enctype_error_multidict
from command import command
from engine import timestamp_now

version = "alpha 0.02-rc1"
from version import version_name

host = '127.0.0.1'
port = 5050
Expand All @@ -44,7 +44,7 @@ def login():
# Login page
if request.method == 'GET':
saves_info = all_saves_info()
return render_template("login.html", saves_info=saves_info, version=version)
return render_template("login.html", saves_info=saves_info, version=version_name)

@app.route("/play.html")
def play():
Expand All @@ -56,7 +56,7 @@ def play():

USERID = session['USERID']
print("[PLAY] USERID:", USERID)
return render_template("play.html", save_info=save_info(USERID), serverTime=timestamp_now(), version=version)
return render_template("play.html", save_info=save_info(USERID), serverTime=timestamp_now(), version=version_name)

@app.route("/new.html")
def new():
Expand Down
12 changes: 9 additions & 3 deletions sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
import os
import copy
import uuid
import random
from flask import session
# from flask_session import SqlAlchemySessionInterface, current_app

from version import version_code
from engine import timestamp_now
from version import migrate_loaded_save


__villages_dir = "./villages"
Expand Down Expand Up @@ -63,8 +66,9 @@ def load_saved_villages():
USERID = save["playerInfo"]["pid"]
print("USERID:", USERID)
__saves[str(USERID)] = save

load_saved_villages()
modified = migrate_loaded_save(save) # check save version for migration
if modified:
save_session(USERID)

# New village

Expand All @@ -75,8 +79,10 @@ def new_village() -> str:
# Copy init
village = copy.deepcopy(__initial_village)
# Custom values
village["version"] = version_code
village["playerInfo"]["pid"] = USERID
village["maps"][0]["timestamp"] = timestamp_now()
village["privateState"]["dartsRandomSeed"] = abs(int((2**16 - 1) * random.random()))
# Memory saves
__saves[USERID] = village
# Generate save file
Expand All @@ -91,7 +97,7 @@ def all_saves_userid() -> list:
return list(__saves.keys())

def all_userid() -> list:
"Returns a list of the USERID of every saved village."
"Returns a list of the USERID of every village."
return list(__villages.keys()) + list(__saves.keys())

def save_info(USERID: str) -> dict:
Expand Down
29 changes: 29 additions & 0 deletions version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import random

from engine import timestamp_now

version_name = "alpha 0.02"
version_code = "0.02a"

def migrate_loaded_save(save: dict) -> bool:
# fix 0.01a saves
if "version" not in save:
save["version"] = "0.01a"

if save["version"] == version_code: # save is from the current version
return False

# 0.01a -> 0.02a
if save["version"] == "0.01a":
save["maps"][0]["timestamp"] = timestamp_now()
save["privateState"]["dartsRandomSeed"] = abs(int((2**16 - 1) * random.random()))
save["version"] = "0.02a"

print(" > migrated to 0.02a")

# # 0.02a -> 0.03a
# if save["version"] == "0.02a":
# save["version"] = "0.03a"
# print(" > migrated to 0.03a")

return True
48 changes: 23 additions & 25 deletions villages/initial.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"version": null,
"playerInfo": {
"pid": 1000,
"name": "Emperor",
Expand All @@ -11,13 +12,10 @@
"default_map": 0,
"map_names": ["My Empire"],
"map_sizes": [0],
"__#__stone": 250,
"__#__wood": 850,
"__#__food": 700,
"world_id": null,
"sp_ref_uid": 1000,
"sp_ref_cat_install": "ts",
"last_logged_in": 0
"last_logged_in": -1
},
"maps": [
{
Expand All @@ -36,29 +34,29 @@
"timestampLastTreasure": 0,
"resourcesTraded": {},
"receivedAssists": {},
"increasedPopulation": 1,
"increasedPopulation": 0,
"expirableUnitsTime": {},
"__#__ITEMS_hint": ["item_id", "x", "y", "orientation", "collected_at_timestamp", "level", "units_array []", "attributes_dict {}"],
"items": [
[26, 52, 52, 0, 0, 0, [], {"aux_name": "TownHall"}],
[19, 50, 58, 0, 0, 0, [], {"aux_name": "Tree"}],
[512, 50, 44, 2, 0, 0, [], {"aux_name": "Light Knight"}],
[512, 50, 42, 0, 0, 0, [], {"aux_name": "Light Knight"}],
[516, 51, 44, 1, 0, 0, [], {"aux_name": "Light Archer"}],
[516, 51, 42, 0, 0, 0, [], {"aux_name": "Light Archer"}],
[1, 44, 50, 0, 0, 0, [], {"aux_name": "House I"}],
[1, 44, 52, 0, 0, 0, [], {"aux_name": "House I"}],
[19, 45, 50, 0, 0, 0, [], {"aux_name": "Tree"}],
[19, 45, 51, 0, 0, 0, [], {"aux_name": "Tree"}],
[19, 45, 52, 0, 0, 0, [], {"aux_name": "Tree"}],
[19, 45, 53, 0, 0, 0, [], {"aux_name": "Tree"}],
[19, 45, 54, 0, 0, 0, [], {"aux_name": "Tree"}],
[19, 44, 54, 0, 0, 0, [], {"aux_name": "Tree"}],
[19, 43, 54, 0, 0, 0, [], {"aux_name": "Tree"}],
[29, 51, 47, 0, 0, 0, [], {"aux_name": "Tower I"}],
[29, 59, 49, 0, 0, 0, [], {"aux_name": "Tower I"}],
[525, 40, 40, 0, 0, 0, [], {"aux_name": "Small Troll"}],
[525, 39, 40, 1, 0, 0, [], {"aux_name": "Small Troll"}]
[26, 52, 52, 0, 0, 0, [], {}],
[19, 50, 58, 0, 0, 0, [], {}],
[512, 50, 44, 2, 0, 0, [], {}],
[512, 50, 42, 0, 0, 0, [], {}],
[516, 51, 44, 1, 0, 0, [], {}],
[516, 51, 42, 0, 0, 0, [], {}],
[1, 44, 50, 0, 0, 0, [], {}],
[1, 44, 52, 0, 0, 0, [], {}],
[19, 45, 50, 0, 0, 0, [], {}],
[19, 45, 51, 0, 0, 0, [], {}],
[19, 45, 52, 0, 0, 0, [], {}],
[19, 45, 53, 0, 0, 0, [], {}],
[19, 45, 54, 0, 0, 0, [], {}],
[19, 44, 54, 0, 0, 0, [], {}],
[19, 43, 54, 0, 0, 0, [], {}],
[29, 51, 47, 0, 0, 0, [], {}],
[29, 59, 49, 0, 0, 0, [], {}],
[525, 40, 40, 0, 0, 0, [], {}],
[525, 39, 40, 1, 0, 0, [], {}]
]
}
],
Expand Down Expand Up @@ -100,7 +98,7 @@
"timeStampDartsReset": 0,
"timeStampDartsNewFree": 0,
"dartsBalloonsShot": [],
"dartsRandomSeed": 10000000000001,
"dartsRandomSeed": 0,
"dartsHasFree": true,
"dartsGotExtra": true,
"countTimePacket": [],
Expand Down

0 comments on commit 7e0197e

Please sign in to comment.