Skip to content

Commit 430060a

Browse files
authored
Features/patch 1 (#1)
Initial creation
1 parent 9ef6e8c commit 430060a

File tree

15 files changed

+698
-0
lines changed

15 files changed

+698
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
.#*
3+
*~
4+
build
5+
example/addons

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
11
# godot-auth
22
Godot Engine (v3.0) Authentication System
3+
4+
## Running the example
5+
6+
1. Click start menu, type `Command Prompt`
7+
1. Right-click `Command Prompt` and click on `Run as Administrator`
8+
1. Run the commands below, assuming you checked out the repo into a `Documents\src\godot-auth` directory.
9+
10+
```powershell
11+
cd c:\Users\YOUR_USERNAME\Documents\src\godot-auth\example
12+
mklink /D addons c:\Users\YOUR_USERNAME\Documents\src\godot-auth\addons
13+
```
14+
15+
If you check out the main.gd, as of this writing, there's probably a good bit of cleanup that can be done to avoid DRY.
16+
17+
## File Backend
18+
19+
It seems that the `user://` path resolves to `C:\Users\YOUR_USERNAME\AppData\Roaming\Godot\app_userdata\Godot Auth`.
20+
21+
## Links
22+
23+
* https://coffeecoderblog.wordpress.com/2016/07/03/creating-a-save-system-in-godot/
24+
* https://godotengine.org/qa/6491/read-&-write
25+
* https://godotengine.org/qa/315/saving-loading-files-there-any-build-file-parsing-can-use-how

addons/godot-auth/auth.gd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
extends Reference
2+
3+
const Pair = preload("res://addons/godot-auth/pair.gd")
4+
5+
"""
6+
Constructor accepting a backend repository
7+
"""
8+
func _init(backend):
9+
if backend == null:
10+
return Pair.new(false, "No backend provided")

addons/godot-auth/backend.gd

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
extends Reference
2+
3+
func create(user):
4+
pass
5+
6+
func find(id):
7+
pass
8+
9+
func update(user):
10+
pass
11+
12+
func remove(id):
13+
pass
14+
15+
func disable(id):
16+
pass

addons/godot-auth/backend/file.gd

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
extends "res://addons/godot-auth/backend.gd"
2+
3+
const Pair = preload("res://addons/godot-auth/pair.gd")
4+
const User = preload("res://addons/godot-auth/user.gd")
5+
6+
const AUTH_DIR = "user://auth"
7+
8+
var auth_dir
9+
10+
"""
11+
Constructor accepting directory to store auth files
12+
"""
13+
func _init(auth_dir_ = AUTH_DIR):
14+
auth_dir = str(auth_dir_)
15+
16+
# If the auth directory doesnt exist, create it
17+
var dir = Directory.new()
18+
if !dir.dir_exists(auth_dir):
19+
dir.open("user://")
20+
dir.make_dir(auth_dir)
21+
22+
func create(user):
23+
var filename = str(auth_dir, "/", user.id, ".json")
24+
25+
var dir = Directory.new()
26+
if dir.file_exists(filename):
27+
return Pair.new(false, str("Auth file already exists for user: id=", user.id))
28+
29+
var file = File.new()
30+
file.open(filename, File.WRITE)
31+
if file.is_open(): file.store_line(user.to_json())
32+
file.close()
33+
34+
return Pair.new(true, str("Successfully created auth file for user: id=", user.id))
35+
36+
func find(id):
37+
var filename = str(auth_dir, "/", id, ".json")
38+
39+
var dir = Directory.new()
40+
if !dir.file_exists(filename):
41+
return Pair.new(false, str("Auth file does not exist for user: id=", id))
42+
43+
# User variable to return back after hydrating from file
44+
var user
45+
46+
# Open file and read the data in
47+
var file = File.new()
48+
file.open(filename, File.READ)
49+
var t = parse_json(file.get_as_text())
50+
file.close()
51+
52+
# Debug output
53+
print(t)
54+
55+
return User.new(t.id, t.username, t.password, t.status)
56+
57+
func update(user):
58+
var filename = str(auth_dir, "/", user.id, ".json")
59+
60+
var dir = Directory.new()
61+
if !dir.file_exists(filename):
62+
return Pair.new(false, str("Auth file does not exist for user: id=", user.id))
63+
64+
var file = File.new()
65+
file.open(filename, File.WRITE)
66+
if file.is_open(): file.store_line(user.to_json())
67+
file.close()
68+
69+
return Pair.new(true, str("Successfully updated auth file for user: file=", filename))
70+
71+
func remove(id):
72+
var filename = str(auth_dir, "/", id, ".json")
73+
74+
var dir = Directory.new()
75+
if !dir.file_exists(filename):
76+
return Pair.new(false, str("Auth file does not exist for user: id=", id))
77+
78+
dir.remove(filename)
79+
80+
return Pair.new(true, str("Successfully removed auth file for user: file=", filename))
81+
82+
func disable(id):
83+
var user = find(id)
84+
85+
user.set_status("inactive")
86+
update(user)

addons/godot-auth/pair.gd

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
extends Reference
2+
3+
var first = null setget , first
4+
var second = null setget , second
5+
6+
func _init(first_, second_):
7+
first = first_
8+
second = second_
9+
10+
func first():
11+
return first
12+
13+
func second():
14+
return second

addons/godot-auth/user.gd

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
extends Reference
2+
3+
const Pair = preload("res://addons/godot-auth/pair.gd")
4+
5+
var id
6+
var username
7+
var password
8+
var status
9+
var _valid_statuses = ["active", "inactive"]
10+
11+
func _init(id_, username_, password_, status_ = Status.ACTIVE):
12+
id = int(id_)
13+
username = str(username_)
14+
password = str(password_)
15+
set_status(status_)
16+
17+
func set_status(status_):
18+
if status_ == null:
19+
status_ = "active"
20+
21+
if status_ in _valid_statuses:
22+
status = status_
23+
else:
24+
return Pair.new(false, str("Invalid status: status=", status_))
25+
26+
func to_json():
27+
return to_json({id = id, username = username, password = password, status = status})
Binary file not shown.

example/default_env.tres

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
[gd_resource type="Environment" load_steps=2 format=2]
2+
3+
[sub_resource type="ProceduralSky" id=1]
4+
5+
radiance_size = 4
6+
sky_top_color = Color( 0.0470588, 0.454902, 0.976471, 1 )
7+
sky_horizon_color = Color( 0.556863, 0.823529, 0.909804, 1 )
8+
sky_curve = 0.25
9+
sky_energy = 1.0
10+
ground_bottom_color = Color( 0.101961, 0.145098, 0.188235, 1 )
11+
ground_horizon_color = Color( 0.482353, 0.788235, 0.952941, 1 )
12+
ground_curve = 0.01
13+
ground_energy = 1.0
14+
sun_color = Color( 1, 1, 1, 1 )
15+
sun_latitude = 35.0
16+
sun_longitude = 0.0
17+
sun_angle_min = 1.0
18+
sun_angle_max = 100.0
19+
sun_curve = 0.05
20+
sun_energy = 16.0
21+
texture_size = 2
22+
23+
[resource]
24+
25+
background_mode = 2
26+
background_sky = SubResource( 1 )
27+
background_sky_custom_fov = 0.0
28+
background_color = Color( 0, 0, 0, 1 )
29+
background_energy = 1.0
30+
background_canvas_max_layer = 0
31+
ambient_light_color = Color( 0, 0, 0, 1 )
32+
ambient_light_energy = 1.0
33+
ambient_light_sky_contribution = 1.0
34+
fog_enabled = false
35+
fog_color = Color( 0.5, 0.6, 0.7, 1 )
36+
fog_sun_color = Color( 1, 0.9, 0.7, 1 )
37+
fog_sun_amount = 0.0
38+
fog_depth_enabled = true
39+
fog_depth_begin = 10.0
40+
fog_depth_curve = 1.0
41+
fog_transmit_enabled = false
42+
fog_transmit_curve = 1.0
43+
fog_height_enabled = false
44+
fog_height_min = 0.0
45+
fog_height_max = 100.0
46+
fog_height_curve = 1.0
47+
tonemap_mode = 0
48+
tonemap_exposure = 1.0
49+
tonemap_white = 1.0
50+
auto_exposure_enabled = false
51+
auto_exposure_scale = 0.4
52+
auto_exposure_min_luma = 0.05
53+
auto_exposure_max_luma = 8.0
54+
auto_exposure_speed = 0.5
55+
ss_reflections_enabled = false
56+
ss_reflections_max_steps = 64
57+
ss_reflections_fade_in = 0.15
58+
ss_reflections_fade_out = 2.0
59+
ss_reflections_depth_tolerance = 0.2
60+
ss_reflections_roughness = true
61+
ssao_enabled = false
62+
ssao_radius = 1.0
63+
ssao_intensity = 1.0
64+
ssao_radius2 = 0.0
65+
ssao_intensity2 = 1.0
66+
ssao_bias = 0.01
67+
ssao_light_affect = 0.0
68+
ssao_color = Color( 0, 0, 0, 1 )
69+
ssao_quality = 0
70+
ssao_blur = 3
71+
ssao_edge_sharpness = 4.0
72+
dof_blur_far_enabled = false
73+
dof_blur_far_distance = 10.0
74+
dof_blur_far_transition = 5.0
75+
dof_blur_far_amount = 0.1
76+
dof_blur_far_quality = 1
77+
dof_blur_near_enabled = false
78+
dof_blur_near_distance = 2.0
79+
dof_blur_near_transition = 1.0
80+
dof_blur_near_amount = 0.1
81+
dof_blur_near_quality = 1
82+
glow_enabled = false
83+
glow_levels/1 = false
84+
glow_levels/2 = false
85+
glow_levels/3 = true
86+
glow_levels/4 = false
87+
glow_levels/5 = true
88+
glow_levels/6 = false
89+
glow_levels/7 = false
90+
glow_intensity = 0.8
91+
glow_strength = 1.0
92+
glow_bloom = 0.0
93+
glow_blend_mode = 2
94+
glow_hdr_threshold = 1.0
95+
glow_hdr_scale = 2.0
96+
glow_bicubic_upscale = false
97+
adjustment_enabled = false
98+
adjustment_brightness = 1.0
99+
adjustment_contrast = 1.0
100+
adjustment_saturation = 1.0
101+

example/export_presets.cfg

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[preset.0]
2+
3+
name="Windows Desktop"
4+
platform="Windows Desktop"
5+
runnable=true
6+
custom_features=""
7+
export_filter="all_resources"
8+
include_filter=""
9+
exclude_filter=""
10+
patch_list=PoolStringArray( )
11+
12+
[preset.0.options]
13+
14+
texture_format/s3tc=true
15+
texture_format/etc=false
16+
texture_format/etc2=false
17+
binary_format/64_bits=true
18+
custom_template/release=""
19+
custom_template/debug=""

example/icon.png

3.42 KB
Loading

example/icon.png.import

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="StreamTexture"
5+
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
6+
7+
[deps]
8+
9+
source_md5="ae7e641067601e2184afcade49abd283"
10+
11+
[params]
12+
13+
compress/mode=0
14+
compress/lossy_quality=0.7
15+
compress/hdr_mode=0
16+
compress/normal_map=0
17+
flags/repeat=0
18+
flags/filter=true
19+
flags/mipmaps=false
20+
flags/anisotropic=false
21+
flags/srgb=2
22+
process/fix_alpha_border=true
23+
process/premult_alpha=false
24+
process/HDR_as_SRGB=false
25+
stream=false
26+
size_limit=0
27+
detect_3d=true
28+
svg/scale=1.0

0 commit comments

Comments
 (0)