Skip to content

Commit

Permalink
Features/patch 1 (#1)
Browse files Browse the repository at this point in the history
Initial creation
  • Loading branch information
brandonlamb authored Dec 12, 2017
1 parent 9ef6e8c commit 430060a
Show file tree
Hide file tree
Showing 15 changed files with 698 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
.#*
*~
build
example/addons
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
# godot-auth
Godot Engine (v3.0) Authentication System

## Running the example

1. Click start menu, type `Command Prompt`
1. Right-click `Command Prompt` and click on `Run as Administrator`
1. Run the commands below, assuming you checked out the repo into a `Documents\src\godot-auth` directory.

```powershell
cd c:\Users\YOUR_USERNAME\Documents\src\godot-auth\example
mklink /D addons c:\Users\YOUR_USERNAME\Documents\src\godot-auth\addons
```

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.

## File Backend

It seems that the `user://` path resolves to `C:\Users\YOUR_USERNAME\AppData\Roaming\Godot\app_userdata\Godot Auth`.

## Links

* https://coffeecoderblog.wordpress.com/2016/07/03/creating-a-save-system-in-godot/
* https://godotengine.org/qa/6491/read-&-write
* https://godotengine.org/qa/315/saving-loading-files-there-any-build-file-parsing-can-use-how
10 changes: 10 additions & 0 deletions addons/godot-auth/auth.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends Reference

const Pair = preload("res://addons/godot-auth/pair.gd")

"""
Constructor accepting a backend repository
"""
func _init(backend):
if backend == null:
return Pair.new(false, "No backend provided")
16 changes: 16 additions & 0 deletions addons/godot-auth/backend.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extends Reference

func create(user):
pass

func find(id):
pass

func update(user):
pass

func remove(id):
pass

func disable(id):
pass
86 changes: 86 additions & 0 deletions addons/godot-auth/backend/file.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
extends "res://addons/godot-auth/backend.gd"

const Pair = preload("res://addons/godot-auth/pair.gd")
const User = preload("res://addons/godot-auth/user.gd")

const AUTH_DIR = "user://auth"

var auth_dir

"""
Constructor accepting directory to store auth files
"""
func _init(auth_dir_ = AUTH_DIR):
auth_dir = str(auth_dir_)

# If the auth directory doesnt exist, create it
var dir = Directory.new()
if !dir.dir_exists(auth_dir):
dir.open("user://")
dir.make_dir(auth_dir)

func create(user):
var filename = str(auth_dir, "/", user.id, ".json")

var dir = Directory.new()
if dir.file_exists(filename):
return Pair.new(false, str("Auth file already exists for user: id=", user.id))

var file = File.new()
file.open(filename, File.WRITE)
if file.is_open(): file.store_line(user.to_json())
file.close()

return Pair.new(true, str("Successfully created auth file for user: id=", user.id))

func find(id):
var filename = str(auth_dir, "/", id, ".json")

var dir = Directory.new()
if !dir.file_exists(filename):
return Pair.new(false, str("Auth file does not exist for user: id=", id))

# User variable to return back after hydrating from file
var user

# Open file and read the data in
var file = File.new()
file.open(filename, File.READ)
var t = parse_json(file.get_as_text())
file.close()

# Debug output
print(t)

return User.new(t.id, t.username, t.password, t.status)

func update(user):
var filename = str(auth_dir, "/", user.id, ".json")

var dir = Directory.new()
if !dir.file_exists(filename):
return Pair.new(false, str("Auth file does not exist for user: id=", user.id))

var file = File.new()
file.open(filename, File.WRITE)
if file.is_open(): file.store_line(user.to_json())
file.close()

return Pair.new(true, str("Successfully updated auth file for user: file=", filename))

func remove(id):
var filename = str(auth_dir, "/", id, ".json")

var dir = Directory.new()
if !dir.file_exists(filename):
return Pair.new(false, str("Auth file does not exist for user: id=", id))

dir.remove(filename)

return Pair.new(true, str("Successfully removed auth file for user: file=", filename))

func disable(id):
var user = find(id)

user.set_status("inactive")
update(user)
14 changes: 14 additions & 0 deletions addons/godot-auth/pair.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extends Reference

var first = null setget , first
var second = null setget , second

func _init(first_, second_):
first = first_
second = second_

func first():
return first

func second():
return second
27 changes: 27 additions & 0 deletions addons/godot-auth/user.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extends Reference

const Pair = preload("res://addons/godot-auth/pair.gd")

var id
var username
var password
var status
var _valid_statuses = ["active", "inactive"]

func _init(id_, username_, password_, status_ = Status.ACTIVE):
id = int(id_)
username = str(username_)
password = str(password_)
set_status(status_)

func set_status(status_):
if status_ == null:
status_ = "active"

if status_ in _valid_statuses:
status = status_
else:
return Pair.new(false, str("Invalid status: status=", status_))

func to_json():
return to_json({id = id, username = username, password = password, status = status})
Binary file not shown.
101 changes: 101 additions & 0 deletions example/default_env.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
[gd_resource type="Environment" load_steps=2 format=2]

[sub_resource type="ProceduralSky" id=1]

radiance_size = 4
sky_top_color = Color( 0.0470588, 0.454902, 0.976471, 1 )
sky_horizon_color = Color( 0.556863, 0.823529, 0.909804, 1 )
sky_curve = 0.25
sky_energy = 1.0
ground_bottom_color = Color( 0.101961, 0.145098, 0.188235, 1 )
ground_horizon_color = Color( 0.482353, 0.788235, 0.952941, 1 )
ground_curve = 0.01
ground_energy = 1.0
sun_color = Color( 1, 1, 1, 1 )
sun_latitude = 35.0
sun_longitude = 0.0
sun_angle_min = 1.0
sun_angle_max = 100.0
sun_curve = 0.05
sun_energy = 16.0
texture_size = 2

[resource]

background_mode = 2
background_sky = SubResource( 1 )
background_sky_custom_fov = 0.0
background_color = Color( 0, 0, 0, 1 )
background_energy = 1.0
background_canvas_max_layer = 0
ambient_light_color = Color( 0, 0, 0, 1 )
ambient_light_energy = 1.0
ambient_light_sky_contribution = 1.0
fog_enabled = false
fog_color = Color( 0.5, 0.6, 0.7, 1 )
fog_sun_color = Color( 1, 0.9, 0.7, 1 )
fog_sun_amount = 0.0
fog_depth_enabled = true
fog_depth_begin = 10.0
fog_depth_curve = 1.0
fog_transmit_enabled = false
fog_transmit_curve = 1.0
fog_height_enabled = false
fog_height_min = 0.0
fog_height_max = 100.0
fog_height_curve = 1.0
tonemap_mode = 0
tonemap_exposure = 1.0
tonemap_white = 1.0
auto_exposure_enabled = false
auto_exposure_scale = 0.4
auto_exposure_min_luma = 0.05
auto_exposure_max_luma = 8.0
auto_exposure_speed = 0.5
ss_reflections_enabled = false
ss_reflections_max_steps = 64
ss_reflections_fade_in = 0.15
ss_reflections_fade_out = 2.0
ss_reflections_depth_tolerance = 0.2
ss_reflections_roughness = true
ssao_enabled = false
ssao_radius = 1.0
ssao_intensity = 1.0
ssao_radius2 = 0.0
ssao_intensity2 = 1.0
ssao_bias = 0.01
ssao_light_affect = 0.0
ssao_color = Color( 0, 0, 0, 1 )
ssao_quality = 0
ssao_blur = 3
ssao_edge_sharpness = 4.0
dof_blur_far_enabled = false
dof_blur_far_distance = 10.0
dof_blur_far_transition = 5.0
dof_blur_far_amount = 0.1
dof_blur_far_quality = 1
dof_blur_near_enabled = false
dof_blur_near_distance = 2.0
dof_blur_near_transition = 1.0
dof_blur_near_amount = 0.1
dof_blur_near_quality = 1
glow_enabled = false
glow_levels/1 = false
glow_levels/2 = false
glow_levels/3 = true
glow_levels/4 = false
glow_levels/5 = true
glow_levels/6 = false
glow_levels/7 = false
glow_intensity = 0.8
glow_strength = 1.0
glow_bloom = 0.0
glow_blend_mode = 2
glow_hdr_threshold = 1.0
glow_hdr_scale = 2.0
glow_bicubic_upscale = false
adjustment_enabled = false
adjustment_brightness = 1.0
adjustment_contrast = 1.0
adjustment_saturation = 1.0

19 changes: 19 additions & 0 deletions example/export_presets.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[preset.0]

name="Windows Desktop"
platform="Windows Desktop"
runnable=true
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
patch_list=PoolStringArray( )

[preset.0.options]

texture_format/s3tc=true
texture_format/etc=false
texture_format/etc2=false
binary_format/64_bits=true
custom_template/release=""
custom_template/debug=""
Binary file added example/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions example/icon.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"

[deps]

source_md5="ae7e641067601e2184afcade49abd283"

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Loading

0 comments on commit 430060a

Please sign in to comment.