Skip to content

Commit c893b9a

Browse files
committed
Long-overdue updates to 4.2 and cleanup. breaking changes.
1 parent f4ffb77 commit c893b9a

26 files changed

+324
-341
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Normalize EOL for all files that Git considers text files.
2+
* text=auto eol=lf

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Godot 4+ specific ignores
2+
.godot/
3+
android/build

PraxisMapper/APICalls/PraxisAPICall.gd

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ func _init():
2525
var err = 0
2626
http = HTTPClient.new() # Create the Client.
2727

28-
var split = PraxisMapper.serverURL.split(":")
28+
var split = PraxisServer.serverURL.split(":")
2929
if (split.size() == 3): #http:\\url:port
3030
err = http.connect_to_host(split[0] + ":" + split[1], int(split[2])) # Connect to host/port.
3131
elif (split.size() == 2 and !split[0].begins_with("http")): #url:port
3232
err = http.connect_to_host(split[0], int(split[1])) # Connect to host/port.
3333
else: # url
34-
err = http.connect_to_host(PraxisMapper.serverURL)
34+
err = http.connect_to_host(PraxisServer.serverURL)
3535

3636
assert(err == OK) # Make sure connection is OK.
3737

@@ -51,8 +51,8 @@ func call_url(endpoint, method = HTTPClient.METHOD_GET, body = ''):
5151
lastResponseCode = 0
5252
# Some headers
5353
var headers = [
54-
"AuthKey: " + PraxisMapper.authKey,
55-
"PraxisAuthKey: " + PraxisMapper.headerKey,
54+
"AuthKey: " + PraxisServer.authKey,
55+
"PraxisAuthKey: " + PraxisServer.headerKey,
5656
"User-Agent: Pirulo/1.0 (Godot)",
5757
"Accept: */*"
5858
]
@@ -92,7 +92,7 @@ func call_url(endpoint, method = HTTPClient.METHOD_GET, body = ''):
9292
OS.delay_msec(25)
9393
else:
9494
_isReauthing = true
95-
await self.Login(PraxisMapper.username, PraxisMapper.password)
95+
await self.Login(PraxisServer.username, PraxisServer.password)
9696
_isReauthing = false
9797
return await call_url(endpoint, method, body)
9898
elif(statusCode != 200 and statusCode != 204):
@@ -319,7 +319,7 @@ func ExpireTiles(place, styleSet): #expires all map tiles in styleSet that conta
319319
await call_url(url)
320320

321321
func GetTileGenerationID(plusCode, styleSet): #Gets the current generation ID (creation count) for a tile. -1 is "expired"
322-
var url = "/MapTile/Generation/" + plusCode + "/" + styleSet
322+
var url = "/MapTile/Generatiion/" + plusCode + "/" + styleSet
323323
await call_url(url)
324324

325325
#Demo endpoint API calls, so this can server immediately as a test client.

PraxisMapper/APICalls/PraxisEndpoints.gd

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ func response_received(result, responseCode, headers, body):
1919

2020
func callEndpoint(url, method = null, body = null):
2121
var headers = [
22-
"AuthKey: " + PraxisMapper.authKey,
23-
"PraxisAuthKey: " + PraxisMapper.headerKey,
22+
"AuthKey: " + PraxisServer.authKey,
23+
"PraxisAuthKey: " + PraxisServer.headerKey,
2424
"User-Agent: Pirulo/1.0 (Godot)",
2525
"Accept: */*"
2626
]
@@ -34,10 +34,10 @@ func callEndpoint(url, method = null, body = null):
3434
request.request_completed.connect(response_received)
3535
var ok
3636
if (body != null):
37-
ok = request.request(PraxisMapper.serverURL + url, headers, method, body)
37+
ok = request.request(PraxisServer.serverURL + url, headers, method, body)
3838
else:
39-
ok = request.request(PraxisMapper.serverURL + url, headers, method)
40-
print(PraxisMapper.serverURL + url)
39+
ok = request.request(PraxisServer.serverURL + url, headers, method)
40+
print(PraxisServer.serverURL + url)
4141
print('request called')
4242

4343
#TODO: check if OK isn't OK and handle pre-call errors.
@@ -198,7 +198,7 @@ func ExpireTiles(place, styleSet): #expires all map tiles in styleSet that conta
198198
callEndpoint("/MapTile/Expire/" + place + "/" + styleSet)
199199

200200
func GetTileGenerationID(plusCode, styleSet): #Gets the current generation ID (creation count) for a tile. -1 is "expired"
201-
callEndpoint("/MapTile/Generation/" + plusCode + "/" + styleSet)
201+
callEndpoint("/MapTile/Generatiion/" + plusCode + "/" + styleSet)
202202

203203
#Demo endpoint API calls, so this can server immediately as a test client.
204204
func DemoSplatterEnter(plusCode): #Grants the player 1 splat point when walking into a Cell10 the first time in 24 hours
+14-13
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
extends Node2D
22

3-
#this control should show up when no GPS is available.
3+
#this control should show up when no GPS is available. Can use PC Keyboard to navigate faster.
44
@onready var label : Label = $CanvasLayer/ColorRect/Label
55

66
func GoNorth():
7-
PraxisMapper.forceChange(PlusCodes.ShiftCode(PraxisMapper.currentPlusCode, 0, 1))
7+
PraxisCore.forceChange(PlusCodes.ShiftCode(PraxisCore.currentPlusCode, 0, 1))
88

99
func GoSouth():
10-
PraxisMapper.forceChange(PlusCodes.ShiftCode(PraxisMapper.currentPlusCode, 0, -1))
10+
PraxisCore.forceChange(PlusCodes.ShiftCode(PraxisCore.currentPlusCode, 0, -1))
1111

1212
func GoEast():
13-
PraxisMapper.forceChange(PlusCodes.ShiftCode(PraxisMapper.currentPlusCode, 1, 0))
13+
PraxisCore.forceChange(PlusCodes.ShiftCode(PraxisCore.currentPlusCode, 1, 0))
1414

1515
func GoWest():
16-
PraxisMapper.forceChange(PlusCodes.ShiftCode(PraxisMapper.currentPlusCode, -1, 0))
16+
PraxisCore.forceChange(PlusCodes.ShiftCode(PraxisCore.currentPlusCode, -1, 0))
1717

18-
# Called when the node enters the scene tree for the first time.
19-
func _ready():
20-
pass # Replace with function body.
21-
22-
23-
# Called every frame. 'delta' is the elapsed time since the previous frame.
2418
func _process(delta):
25-
label.text = PraxisMapper.currentPlusCode
26-
pass
19+
label.text = PraxisCore.currentPlusCode
20+
if (Input.is_key_pressed(KEY_UP)):
21+
GoNorth()
22+
if (Input.is_key_pressed(KEY_DOWN)):
23+
GoSouth()
24+
if (Input.is_key_pressed(KEY_LEFT)):
25+
GoWest()
26+
if (Input.is_key_pressed(KEY_RIGHT)):
27+
GoEast()

PraxisMapper/Controls/DebugMovement.tscn

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
script = ExtResource("1_1g2xv")
88

99
[node name="CanvasLayer" type="CanvasLayer" parent="."]
10+
layer = 128
1011

1112
[node name="ColorRect" type="ColorRect" parent="CanvasLayer"]
1213
offset_right = 75.0

PraxisMapper/Controls/MapTile.gd

+6-8
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ var noiseTex : NoiseTexture2D
2020
signal user_tapped(plusCode)
2121

2222
func getTappedCode(x, y):
23-
var cellsX = PraxisMapper.mapTileWidth / 20
24-
var cellsY = PraxisMapper.mapTileHeight / 20
23+
var cellsX = PraxisCore.mapTileWidth / 20
24+
var cellsY = PraxisCore.mapTileHeight / 20
2525
#TODO: this needs adjusted to match the screen being centered?
2626
var tappedCell = PlusCodes.ShiftCode(currentTile + "22", x / cellsX, (400 - y) / cellsY )
2727
return tappedCell
@@ -68,11 +68,11 @@ func LoadTile(plusCode):
6868
else:
6969
request.response_data.connect(tile_called)
7070

71-
print("getting " + PraxisMapper.serverURL + "/MapTile/Area/" + plusCode + "/" + styleSet)
71+
print("getting " + PraxisServer.serverURL + "/MapTile/Area/" + plusCode + "/" + styleSet)
7272
request.DrawMapTile(plusCode, styleSet)
7373

7474
func GetTile(plusCode):
75-
if PraxisMapper.currentPlusCode.substr(0,8) == PraxisMapper.lastPlusCode.substr(0,8):
75+
if PraxisCore.currentPlusCode.substr(0,8) == PraxisCore.lastPlusCode.substr(0,8):
7676
return
7777

7878
currentTile = plusCode.substr(0,8)
@@ -87,15 +87,13 @@ func OnPlusCodeChanged(current, previous):
8787

8888
# Called when the node enters the scene tree for the first time.
8989
func _ready():
90-
#TODO: make NoiseTexture a proper node to reference multiple times?
9190
noiseTex = NoiseTexture2D.new()
92-
noiseTex.width = PraxisMapper.mapTileWidth
93-
noiseTex.height = PraxisMapper.mapTileHeight
91+
noiseTex.width = PraxisCore.mapTileWidth
92+
noiseTex.height = PraxisCore.mapTileHeight
9493
noiseTex.noise = FastNoiseLite.new()
9594
texRect.texture = noiseTex
9695

9796
if (autoRefresh == true):
9897
timer.one_shot = false
9998
timer.autostart = true
100-
timer.wait_time = autoRefreshSeconds
10199
timer.start()

PraxisMapper/Scenes/LoadingModal.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extends Node2D
22

3-
#A default input-blocking
3+
#A default input-blocking modal.
44

55
@onready var spinner: Sprite2D = $ColorRect/Spinner
66

PraxisMapper/Scenes/LoginScene.gd

+9-10
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ extends Node2D
77
@onready var request: HTTPRequest = $HTTPRequest
88
@onready var timer: Timer = $Timer
99
@onready var api2: PraxisEndpoints = $PraxisEndpoints
10-
#TODO: move passkey to a variable and change it.
10+
var passkey = "UniquePasskeyGoesHere"
1111

1212
# Called when the node enters the scene tree for the first time.
1313
func _ready():
14-
#TODO: check for saved credentials, set into textboxes if found.
15-
var lastData = FileAccess.open_encrypted_with_pass("user://savedData.access", FileAccess.READ, "passkeyGoesHere")
14+
var lastData = FileAccess.open_encrypted_with_pass("user://savedData.access", FileAccess.READ, passkey)
1615
if (lastData != null):
1716
var data = lastData.get_as_text().split("|")
1817
if (data[2].ends_with('/')):
@@ -28,7 +27,7 @@ func _on_btn_login_pressed():
2827
print("login pressed")
2928
lblError.text = "Logging in...."
3029

31-
PraxisMapper.serverURL = txtServer.text
30+
PraxisServer.serverURL = txtServer.text
3231
api2.response_data.connect(login_completed)
3332
api2.Login('', txtUsername.text, txtPassword.text)
3433

@@ -42,22 +41,22 @@ func login_completed(result):
4241
json.parse(result.get_string_from_utf8())
4342
var data = json.get_data()
4443
print(data)
45-
#if successful, save name/pwd/server to file to load as auto-login next time. #NOTE: may use ConfigFile for this specifically.
44+
#if successful, save name/pwd/server to file to load as auto-login next time.
4645
var authData = FileAccess.open_encrypted_with_pass("user://savedData.access", FileAccess.WRITE, "passkeyGoesHere")
4746
authData.store_string(txtUsername.text + "|" + txtPassword.text + "|" +txtServer.text)
4847
authData.close()
4948

50-
PraxisMapper.username = txtUsername.text
51-
PraxisMapper.password = txtPassword.text
52-
PraxisMapper.serverURL = txtServer.text
53-
PraxisMapper.authKey = data.authToken
49+
PraxisServer.username = txtUsername.text
50+
PraxisServer.password = txtPassword.text
51+
PraxisServer.serverURL = txtServer.text
52+
PraxisServer.authKey = data.authToken
5453

5554
get_tree().change_scene_to_file("res://Scenes/OverheadView.tscn")
5655

5756
func _on_btn_create_acct_pressed():
5857
print("create pressed")
5958
lblError.text = "Creating account...."
60-
PraxisMapper.serverURL = txtServer.text
59+
PraxisServer.serverURL = txtServer.text
6160
api2.response_data.connect(createCompleted)
6261
api2.CreateAccount(txtUsername.text, txtPassword.text)
6362

PraxisMapper/Scripts/PlusCodes.gd

+33-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
1-
extends RefCounted
1+
extends Node
22
class_name PlusCodes
33

44
var SEPARATOR_ = '+'
55
static var CODE_ALPHABET_ = '23456789CFGHJMPQRVWX'
66

7-
#var GRID_COLUMNS_ = 4
8-
#var GRID_ROWS_ = 5
9-
#note: a reasonable alternative would be a 3x3 grid in a 9-char code set.
10-
#would be longer codes but could be number-only, and then indexable similar to S2 codes but
11-
#in regular rectangles instead.
12-
13-
#for decoding the 11th digit?
14-
#var GRID_ROW_MULTIPLIER = 3125
15-
#var GRID_COL_MULTIPLIER = 1024
16-
17-
187
static func EncodeLatLon(lat, lon):
198
return EncodeLatLonSize(lat, lon, 10)
209

@@ -95,3 +84,35 @@ static func ShiftCode(code, xChange, yChange):
9584
newCode = newCode + CODE_ALPHABET_[yVals[i]] + CODE_ALPHABET_[xVals[i]]
9685

9786
return newCode
87+
88+
static func Decode(plusCode):
89+
var lat = -90.0
90+
var lon = -180.0
91+
plusCode = plusCode.replace("+", "")
92+
var totalChars = plusCode.length()
93+
var charsProcessed = 0
94+
var precision = 20
95+
var xVal = 0
96+
var yVal = 0
97+
while (charsProcessed < totalChars):
98+
if (charsProcessed < 10):
99+
xVal = PlusCodes.GetLetterIndex(plusCode[charsProcessed + 1])
100+
yVal = PlusCodes.GetLetterIndex(plusCode[charsProcessed])
101+
102+
lat += precision * yVal
103+
lon += precision * xVal
104+
precision /= 20.0
105+
charsProcessed += 2
106+
else:
107+
#lat/row is /, column/lon is %
108+
xVal = PlusCodes.GetLetterIndex(plusCode[charsProcessed]) % 4
109+
yVal = PlusCodes.GetLetterIndex(plusCode[charsProcessed]) / 4
110+
111+
lon += (xVal * (precision / (4.0 ** (charsProcessed - 9))))
112+
lat += (yVal * (precision / (5.0 ** (charsProcessed - 9))))
113+
114+
charsProcessed += 1
115+
return Vector2(lon, lat) #x, y!
116+
117+
static func GetLetterIndex(letter):
118+
return CODE_ALPHABET_.find(letter)

0 commit comments

Comments
 (0)