Merge branch 'develop' into feature/Coin

# Conflicts:
#	godot/Main.tscn
This commit is contained in:
Martin Araneda 2022-08-01 14:17:05 -04:00
commit 2be22ceb68
49 changed files with 1056 additions and 34 deletions

View File

@ -1,8 +1,11 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=4 format=2]
[ext_resource path="res://Main.gdns" type="Script" id=1]
[ext_resource path="res://levels/Prototype.tscn" type="PackedScene" id=2]
[ext_resource path="res://monitor/Monitor.tscn" type="PackedScene" id=3]
[node name="Main" type="Node"]
script = ExtResource( 1 )
level = ExtResource( 2 )
[node name="Monitor" parent="." instance=ExtResource( 3 )]

View File

@ -3,6 +3,6 @@ config_version=3
name="Tiled Map Importer"
description="Importer for TileMaps and TileSets made on Tiled Map Editor"
version="2.3"
version="2.4"
author="George Marques"
script="vnen.tiled_importer.gd"

View File

@ -46,7 +46,7 @@ func get_priority():
return 1
func get_import_order():
return 100
return 101
func get_resource_type():
return "PackedScene"
@ -73,9 +73,9 @@ func get_import_options(preset):
"name": "uv_clip",
"default_value": true
},
{
{
"name": "y_sort",
"default_value": false
"default_value": true
},
{
"name": "image_flags",
@ -119,8 +119,6 @@ func get_option_visibility(option, options):
func import(source_file, save_path, options, r_platform_variants, r_gen_files):
var map_reader = TiledMapReader.new()
# Offset is only optional for importing TileSets
options.apply_offset = true
var scene = map_reader.build(source_file, options)
if typeof(scene) != TYPE_OBJECT:

View File

@ -50,6 +50,8 @@ const whitelist_properties = [
"infinite",
"margin",
"name",
"offsetx",
"offsety",
"orientation",
"probability",
"spacing",
@ -227,10 +229,8 @@ func make_layer(layer, parent, root, data):
tilemap.mode = map_mode
tilemap.cell_half_offset = map_offset
tilemap.format = 1
tilemap.cell_custom_transform = Transform2D(Vector2(cell_size.x, 0), Vector2(0, cell_size.y), Vector2(0, 0))
tilemap.cell_clip_uv = options.uv_clip
tilemap.cell_y_sort = options.y_sort
tilemap.cell_tile_origin = TileMap.TILE_ORIGIN_TOP_LEFT
tilemap.collision_layer = options.collision_layer
tilemap.collision_mask = options.collision_mask
tilemap.z_index = z_index
@ -282,7 +282,7 @@ func make_layer(layer, parent, root, data):
var gid = int_id & ~(FLIPPED_HORIZONTALLY_FLAG | FLIPPED_VERTICALLY_FLAG | FLIPPED_DIAGONALLY_FLAG)
var cell_x = cell_offset.x + chunk.x + (count % int(chunk.width))
var cell_y = cell_offset.y + chunk.y + int(count / chunk.width) + 1
var cell_y = cell_offset.y + chunk.y + int(count / chunk.width)
tilemap.set_cell(cell_x, cell_y, gid, flipped_h, flipped_v, flipped_d)
count += 1
@ -695,7 +695,13 @@ func build_tileset_for_scene(tilesets, source_path, options):
imagesize = Vector2(int(ts.imagewidth), int(ts.imageheight))
var tilesize = Vector2(int(ts.tilewidth), int(ts.tileheight))
var tilecount = int(ts.tilecount)
var tilecount
if not "tilecount" in ts:
tilecount = make_tilecount(tilesize, imagesize, margin, spacing)
else:
tilecount = int(ts.tilecount)
var gid = firstgid
@ -705,6 +711,7 @@ func build_tileset_for_scene(tilesets, source_path, options):
var i = 0
var column = 0
# Needed to look up textures for animations
var tileRegions = []
while i < tilecount:
@ -752,8 +759,6 @@ func build_tileset_for_scene(tilesets, source_path, options):
else:
result.tile_set_texture(gid, image)
result.tile_set_region(gid, region)
if options.apply_offset:
result.tile_set_texture_offset(gid, Vector2(0, -tilesize.y))
elif not rel_id in ts.tiles:
gid += 1
continue
@ -778,8 +783,6 @@ func build_tileset_for_scene(tilesets, source_path, options):
# Error happened
return image
result.tile_set_texture(gid, image)
if options.apply_offset:
result.tile_set_texture_offset(gid, Vector2(0, -image.get_height()))
if "tiles" in ts and rel_id in ts.tiles and "objectgroup" in ts.tiles[rel_id] \
and "objects" in ts.tiles[rel_id].objectgroup:
@ -792,8 +795,6 @@ func build_tileset_for_scene(tilesets, source_path, options):
return shape
var offset = Vector2(float(object.x), float(object.y))
if options.apply_offset:
offset += result.tile_get_texture_offset(gid)
if "width" in object and "height" in object:
offset += Vector2(float(object.width) / 2, float(object.height) / 2)
@ -818,6 +819,11 @@ func build_tileset_for_scene(tilesets, source_path, options):
if not gid in tile_meta: tile_meta[gid] = {}
tile_meta[gid][property] = ts.tiles[rel_id][property]
# If tile has a custom property called 'name', set the tile's name
if property == "name":
result.tile_set_name(gid, ts.tiles[rel_id].properties.name)
gid += 1
i += 1
@ -876,13 +882,14 @@ func load_image(rel_path, source_path, options):
var image = null
if embed:
var img = Image.new()
img.load(total_path)
image = ImageTexture.new()
image.load(total_path)
image.create_from_image(img, flags)
else:
image = ResourceLoader.load(total_path, "ImageTexture")
if image != null:
image.set_flags(flags)
if image != null:
image.set_flags(flags)
return image
@ -1128,6 +1135,17 @@ func object_sorter(first, second):
return first.id < second.id
return first.y < second.y
# Create the tilecount for the TileSet if not present.
# Based on the image and tile dimensions.
func make_tilecount(tilesize, imagesize, margin, spacing):
var horizontal_tile_size = int(tilesize.x + margin * 2 + spacing)
var vertical_tile_size = int(tilesize.y + margin * 2 + spacing)
var horizontal_tile_count = int(imagesize.x) / horizontal_tile_size;
var vertical_tile_count = int(imagesize.y) / vertical_tile_size;
return horizontal_tile_count * vertical_tile_count
# Validates the map dictionary content for missing or invalid keys
# Returns an error code
func validate_map(map):
@ -1170,9 +1188,6 @@ func validate_tileset(tileset):
elif not "tileheight" in tileset or not str(tileset.tileheight).is_valid_integer():
print_error("Missing or invalid tileheight tileset property.")
return ERR_INVALID_DATA
elif not "tilecount" in tileset or not str(tileset.tilecount).is_valid_integer():
print_error("Missing or invalid tilecount tileset property.")
return ERR_INVALID_DATA
if not "image" in tileset:
for tile in tileset.tiles:
if not "image" in tileset.tiles[tile]:

View File

@ -42,6 +42,9 @@ func get_recognized_extensions():
func get_save_extension():
return "res"
func get_import_order():
return 100
func get_resource_type():
return "TileSet"
@ -77,10 +80,6 @@ func get_import_options(preset):
"name": "save_tiled_properties",
"default_value": false
},
{
"name": "apply_offset",
"default_value": false
},
{
"name": "post_import_script",
"default_value": "",

View File

@ -247,7 +247,7 @@ func parse_tile_data(parser):
var prop_data = parse_properties(parser)
data["properties"] = prop_data.properties
data["propertytypes"] = prop_data.propertytypes
elif parser.get_node_name() == "animation":
var frame_list = []
var err2 = parser.read()
@ -265,7 +265,7 @@ func parse_tile_data(parser):
if parser.get_node_name() == "animation":
break
err2 = parser.read()
data["animation"] = frame_list
err = parser.read()

View File

@ -0,0 +1,4 @@
[gd_resource type="DynamicFontData" format=2]
[resource]
font_path = "res://assets/fonts/ttf/PixelOperator8-Bold.ttf"

View File

@ -0,0 +1,4 @@
[gd_resource type="DynamicFontData" format=2]
[resource]
font_path = "res://assets/fonts/ttf/PixelOperatorHB8.ttf"

BIN
godot/assets/fonts/ttf/PixelOperator-Bold.ttf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
godot/assets/fonts/ttf/PixelOperator.ttf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
godot/assets/fonts/ttf/PixelOperator8-Bold.ttf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
godot/assets/fonts/ttf/PixelOperator8.ttf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
godot/assets/fonts/ttf/PixelOperatorHB.ttf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
godot/assets/fonts/ttf/PixelOperatorHB8.ttf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
godot/assets/fonts/ttf/PixelOperatorMono-Bold.ttf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
godot/assets/fonts/ttf/PixelOperatorMono.ttf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
godot/assets/fonts/ttf/PixelOperatorMono8-Bold.ttf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
godot/assets/fonts/ttf/PixelOperatorMono8.ttf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
godot/assets/fonts/ttf/PixelOperatorMonoHB.ttf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
godot/assets/fonts/ttf/PixelOperatorMonoHB8.ttf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
godot/assets/music/level2.ogg (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,15 @@
[remap]
importer="ogg_vorbis"
type="AudioStreamOGGVorbis"
path="res://.import/level2.ogg-0cba17639fcb1c4e45dc4f01c5837760.oggstr"
[deps]
source_file="res://assets/music/level2.ogg"
dest_files=[ "res://.import/level2.ogg-0cba17639fcb1c4e45dc4f01c5837760.oggstr" ]
[params]
loop=true
loop_offset=0

BIN
godot/assets/sounds/coin.wav (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,23 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/coin.wav-9081ee1c6d81d9c34d08bc916297b892.sample"
[deps]
source_file="res://assets/sounds/coin.wav"
dest_files=[ "res://.import/coin.wav-9081ee1c6d81d9c34d08bc916297b892.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0

BIN
godot/assets/sounds/died.wav (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,23 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/died.wav-fc4528ad616bbce5115ae092cb80d346.sample"
[deps]
source_file="res://assets/sounds/died.wav"
dest_files=[ "res://.import/died.wav-fc4528ad616bbce5115ae092cb80d346.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0

BIN
godot/assets/sounds/gem.wav (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,23 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/gem.wav-49535e5638777427fa416449f386aaf6.sample"
[deps]
source_file="res://assets/sounds/gem.wav"
dest_files=[ "res://.import/gem.wav-49535e5638777427fa416449f386aaf6.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0

BIN
godot/assets/sounds/jump.wav (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,23 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/jump.wav-395b727cde98999423d5c020c9c3492f.sample"
[deps]
source_file="res://assets/sounds/jump.wav"
dest_files=[ "res://.import/jump.wav-395b727cde98999423d5c020c9c3492f.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0

BIN
godot/assets/sounds/ui_popup.wav (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,23 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/ui_popup.wav-b70bc280bf50aa4e775c08111118c3ae.sample"
[deps]
source_file="res://assets/sounds/ui_popup.wav"
dest_files=[ "res://.import/ui_popup.wav-b70bc280bf50aa4e775c08111118c3ae.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0

BIN
godot/assets/sounds/ui_select.wav (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,23 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/ui_select.wav-a1e6656879b8474ab79f3a15e3073001.sample"
[deps]
source_file="res://assets/sounds/ui_select.wav"
dest_files=[ "res://.import/ui_select.wav-a1e6656879b8474ab79f3a15e3073001.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=9 format=2]
[gd_scene load_steps=10 format=2]
[ext_resource path="res://characters/player/sprites/green.tres" type="SpriteFrames" id=1]
[ext_resource path="res://characters/player/states/Idle.gdns" type="Script" id=2]
@ -7,6 +7,7 @@
[ext_resource path="res://characters/player/Player.gdns" type="Script" id=5]
[ext_resource path="res://characters/player/states/Jump.gdns" type="Script" id=6]
[ext_resource path="res://characters/player/states/Fall.gdns" type="Script" id=7]
[ext_resource path="res://assets/sounds/jump.wav" type="AudioStream" id=8]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 7, 12 )
@ -40,3 +41,8 @@ script = ExtResource( 6 )
[node name="Fall" type="Node" parent="StateMachine"]
script = ExtResource( 7 )
[node name="Sounds" type="Node" parent="."]
[node name="Jump" type="AudioStreamPlayer" parent="Sounds"]
stream = ExtResource( 8 )

View File

@ -1,9 +1,11 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=7 format=2]
[ext_resource path="res://CameraLimit.gdns" type="Script" id=1]
[ext_resource path="res://characters/player/Player.tscn" type="PackedScene" id=2]
[ext_resource path="res://assets/backgrounds/hills.png" type="Texture" id=3]
[ext_resource path="res://levels/Level2.tmx" type="PackedScene" id=4]
[ext_resource path="res://assets/music/level2.ogg" type="AudioStream" id=5]
[ext_resource path="res://levels/MusicPlayer.gd" type="Script" id=6]
[node name="Level2" type="Node2D"]
@ -39,3 +41,8 @@ centered = false
[node name="Level2" parent="Map" instance=ExtResource( 4 )]
script = ExtResource( 1 )
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
pause_mode = 2
stream = ExtResource( 5 )
script = ExtResource( 6 )

View File

@ -0,0 +1,16 @@
extends AudioStreamPlayer
# there is currently a bug with AudioStreamPlayer
# it doesn't pause when the tree is paused
# so let's manually check if paused and pause the audio
# for this to work pause mode for the node is set to process instead of inherit
func _physics_process(_delta: float) -> void:
if get_tree().paused and playing:
stop()
playing = false
elif not get_tree().paused and not playing:
play()
playing = true

View File

@ -0,0 +1,119 @@
extends Button
signal input_validated(player)
func is_valid_name(name: String) -> bool:
if name.strip_edges() == "":
print_debug("Name is empty!")
return false
if name.split(" ").size() == 1:
print_debug("Doesn't contain at least a first and last name!")
return false
return true
func is_valid_rut(rut: String) -> bool:
var rut_node = get_node("%Rut")
rut = rut_node.clean_rut(rut)
if rut.length() < 8 or rut.length() > 9:
print_debug("RUT length is invalid!")
return false
var rut_temp: String = rut.substr(0, rut.length() - 1)
var verifier: String = rut.substr(rut.length() - 1, 1)
if not rut_temp.is_valid_integer():
print_debug("RUT isn't a valid integer!")
return false
if rut_temp.to_int() > 50000000:
print_debug("RUT is too large, that is a company!")
return false
if verifier != generate_verifier(rut_temp):
return false
return true
func generate_verifier(rut: String) -> String:
if not rut.is_valid_integer():
print_debug("RUT isn't a valid integer!")
return ""
var multiplier: int = 2
var sum: int = 0
var remainder: int = 0
var division: int = 0
var rut_length: int = rut.length()
var i: int = rut_length - 1
while i >= 0:
sum = sum + rut.substr(i, 1).to_int() * multiplier
multiplier = multiplier + 1
if multiplier == 8:
multiplier = 2
i = i - 1
var tempSum: float = sum
division = int(floor(tempSum / 11))
division = division * 11
remainder = sum - division
if remainder != 0:
remainder = 11 - remainder
if remainder == 10:
return "k"
else:
return String(remainder)
func is_valid_email(email: String) -> bool:
var regex = RegEx.new()
regex.compile("\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+")
if regex.search(email) == null:
print_debug("Isn't a valid email address!")
return false
return true
func _on_Button_pressed() -> void:
var name = get_node("%Name")
var rut = get_node("%Rut")
var email = get_node("%Email")
var player: Dictionary = {
"name" : name.text,
"rut" : get_node("%Rut").clean_rut(rut.text),
"email" : email.text
}
if not is_valid_name(player.name):
show_error_message("Ingresa un nombre completo valido por favor!")
return
if not is_valid_rut(player.rut):
show_error_message("Ingresa un RUT valido por favor!")
return
if not is_valid_email(player.email):
show_error_message("Ingresa un email valido por favor!")
return
emit_signal("input_validated", player)
func show_error_message(message: String) -> void:
var popup = get_node("%PopupDialog")
popup.get_node("ErrorMessage").text = message
popup.popup()
popup.focus_mode = Control.FOCUS_ALL
popup.grab_focus()
func _on_PopupDialog_gui_input(event: InputEvent) -> void:
if event.is_pressed():
var popup = get_node("%PopupDialog")
popup.hide()

243
godot/monitor/GUI.tscn Normal file
View File

@ -0,0 +1,243 @@
[gd_scene load_steps=17 format=2]
[ext_resource path="res://assets/fonts/data/PixelOperator.tres" type="DynamicFontData" id=1]
[ext_resource path="res://assets/fonts/data/PixelOperator-Bold.tres" type="DynamicFontData" id=2]
[ext_resource path="res://monitor/Rut.gd" type="Script" id=3]
[ext_resource path="res://monitor/UISounds.gd" type="Script" id=4]
[ext_resource path="res://monitor/EnterButton.gd" type="Script" id=5]
[ext_resource path="res://assets/sounds/ui_popup.wav" type="AudioStream" id=6]
[ext_resource path="res://assets/sounds/ui_select.wav" type="AudioStream" id=7]
[sub_resource type="DynamicFont" id=1]
font_data = ExtResource( 1 )
[sub_resource type="DynamicFont" id=14]
size = 8
font_data = ExtResource( 1 )
[sub_resource type="StyleBoxFlat" id=13]
content_margin_left = 5.0
content_margin_right = 5.0
content_margin_top = 2.0
content_margin_bottom = 2.0
bg_color = Color( 0.313726, 0.290196, 0.290196, 0.752941 )
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
[sub_resource type="DynamicFont" id=11]
size = 12
extra_spacing_top = 2
extra_spacing_bottom = 2
extra_spacing_char = 2
extra_spacing_space = 2
font_data = ExtResource( 2 )
[sub_resource type="StyleBoxFlat" id=12]
content_margin_left = 5.0
content_margin_right = 5.0
content_margin_top = 5.0
content_margin_bottom = 5.0
bg_color = Color( 0.313726, 0.290196, 0.290196, 0.752941 )
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
[sub_resource type="InputEventAction" id=17]
action = "ui_accept"
pressed = true
[sub_resource type="ShortCut" id=18]
shortcut = SubResource( 17 )
[sub_resource type="StyleBoxFlat" id=15]
bg_color = Color( 0.239216, 0.239216, 0.239216, 1 )
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
expand_margin_left = 5.0
expand_margin_right = 5.0
expand_margin_top = 5.0
expand_margin_bottom = 5.0
[sub_resource type="DynamicFont" id=16]
font_data = ExtResource( 2 )
[node name="MonitorGUI" type="CanvasLayer"]
pause_mode = 2
[node name="ColorRect" type="ColorRect" parent="."]
margin_right = 40.0
margin_bottom = 40.0
rect_min_size = Vector2( 512, 288 )
color = Color( 0.0117647, 0.00784314, 0.00784314, 0.376471 )
[node name="GUI" type="Control" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
rect_min_size = Vector2( 512, 0 )
[node name="Sounds" type="Node" parent="GUI"]
script = ExtResource( 4 )
[node name="Popup" type="AudioStreamPlayer" parent="GUI/Sounds"]
stream = ExtResource( 6 )
[node name="Menu" type="AudioStreamPlayer" parent="GUI/Sounds"]
stream = ExtResource( 7 )
[node name="VBoxContainer" type="VBoxContainer" parent="GUI"]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 3
size_flags_vertical = 3
custom_constants/separation = 0
[node name="CenterContainer" type="CenterContainer" parent="GUI/VBoxContainer"]
margin_right = 512.0
margin_bottom = 96.0
rect_min_size = Vector2( 0, 96 )
size_flags_horizontal = 3
[node name="Label" type="Label" parent="GUI/VBoxContainer/CenterContainer"]
margin_top = 30.0
margin_right = 512.0
margin_bottom = 65.0
rect_min_size = Vector2( 512, 0 )
custom_fonts/font = SubResource( 1 )
text = "Ingresa su nombre completo, RUT y email por favor!"
align = 1
autowrap = true
[node name="CenterContainer2" type="CenterContainer" parent="GUI/VBoxContainer"]
margin_top = 96.0
margin_right = 512.0
margin_bottom = 192.0
rect_min_size = Vector2( 0, 96 )
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="VBoxContainer2" type="VBoxContainer" parent="GUI/VBoxContainer/CenterContainer2"]
margin_left = 16.0
margin_top = 14.0
margin_right = 496.0
margin_bottom = 82.0
rect_min_size = Vector2( 480, 0 )
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="Name" type="LineEdit" parent="GUI/VBoxContainer/CenterContainer2/VBoxContainer2"]
unique_name_in_owner = true
margin_right = 480.0
margin_bottom = 20.0
focus_neighbour_left = NodePath("../../../CenterContainer3/Button")
focus_neighbour_top = NodePath("../../../CenterContainer3/Button")
focus_neighbour_right = NodePath("../Rut")
focus_neighbour_bottom = NodePath("../Rut")
focus_next = NodePath("../Rut")
focus_previous = NodePath("../../../CenterContainer3/Button")
custom_fonts/font = SubResource( 14 )
custom_styles/normal = SubResource( 13 )
max_length = 256
context_menu_enabled = false
clear_button_enabled = true
placeholder_text = "Nombre Completo"
caret_blink = true
[node name="Rut" type="LineEdit" parent="GUI/VBoxContainer/CenterContainer2/VBoxContainer2"]
unique_name_in_owner = true
margin_top = 24.0
margin_right = 480.0
margin_bottom = 44.0
focus_neighbour_left = NodePath("../Name")
focus_neighbour_top = NodePath("../Name")
focus_neighbour_right = NodePath("../Email")
focus_neighbour_bottom = NodePath("../Email")
focus_next = NodePath("../Email")
focus_previous = NodePath("../Name")
custom_fonts/font = SubResource( 14 )
custom_styles/normal = SubResource( 13 )
max_length = 12
context_menu_enabled = false
clear_button_enabled = true
placeholder_text = "RUT"
caret_blink = true
script = ExtResource( 3 )
[node name="Email" type="LineEdit" parent="GUI/VBoxContainer/CenterContainer2/VBoxContainer2"]
unique_name_in_owner = true
margin_top = 48.0
margin_right = 480.0
margin_bottom = 68.0
focus_neighbour_left = NodePath("../Rut")
focus_neighbour_top = NodePath("../Rut")
focus_neighbour_right = NodePath("../../../CenterContainer3/Button")
focus_neighbour_bottom = NodePath("../../../CenterContainer3/Button")
focus_next = NodePath("../../../CenterContainer3/Button")
focus_previous = NodePath("../Rut")
custom_fonts/font = SubResource( 14 )
custom_styles/normal = SubResource( 13 )
max_length = 256
context_menu_enabled = false
clear_button_enabled = true
placeholder_text = "Email"
caret_blink = true
[node name="CenterContainer3" type="CenterContainer" parent="GUI/VBoxContainer"]
margin_top = 192.0
margin_right = 512.0
margin_bottom = 288.0
rect_min_size = Vector2( 0, 96 )
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="Button" type="Button" parent="GUI/VBoxContainer/CenterContainer3"]
margin_left = 197.0
margin_top = 34.0
margin_right = 314.0
margin_bottom = 61.0
focus_neighbour_left = NodePath("../../CenterContainer2/VBoxContainer2/Email")
focus_neighbour_top = NodePath("../../CenterContainer2/VBoxContainer2/Email")
focus_neighbour_right = NodePath("../../CenterContainer2/VBoxContainer2/Name")
focus_neighbour_bottom = NodePath("../../CenterContainer2/VBoxContainer2/Name")
focus_next = NodePath("../../CenterContainer2/VBoxContainer2/Name")
focus_previous = NodePath("../../CenterContainer2/VBoxContainer2/Email")
custom_fonts/font = SubResource( 11 )
custom_styles/normal = SubResource( 12 )
shortcut_in_tooltip = false
shortcut = SubResource( 18 )
text = "Ingresar"
script = ExtResource( 5 )
[node name="PopupDialog" type="PopupDialog" parent="."]
unique_name_in_owner = true
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 96.0
margin_top = 96.0
margin_right = -96.0
margin_bottom = -96.0
custom_styles/panel = SubResource( 15 )
[node name="ErrorMessage" type="Label" parent="PopupDialog"]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 3
size_flags_vertical = 7
custom_fonts/font = SubResource( 16 )
text = "Error Message"
align = 1
valign = 1
autowrap = true
[connection signal="focus_entered" from="GUI/VBoxContainer/CenterContainer2/VBoxContainer2/Name" to="GUI/Sounds" method="_play_ui_select_sound"]
[connection signal="focus_entered" from="GUI/VBoxContainer/CenterContainer2/VBoxContainer2/Rut" to="GUI/Sounds" method="_play_ui_select_sound"]
[connection signal="text_changed" from="GUI/VBoxContainer/CenterContainer2/VBoxContainer2/Rut" to="GUI/VBoxContainer/CenterContainer2/VBoxContainer2/Rut" method="_on_Rut_text_changed"]
[connection signal="focus_entered" from="GUI/VBoxContainer/CenterContainer2/VBoxContainer2/Email" to="GUI/Sounds" method="_play_ui_select_sound"]
[connection signal="focus_entered" from="GUI/VBoxContainer/CenterContainer3/Button" to="GUI/Sounds" method="_play_ui_select_sound"]
[connection signal="pressed" from="GUI/VBoxContainer/CenterContainer3/Button" to="GUI/VBoxContainer/CenterContainer3/Button" method="_on_Button_pressed"]
[connection signal="focus_entered" from="PopupDialog" to="GUI/Sounds" method="_play_popup_sound"]
[connection signal="gui_input" from="PopupDialog" to="GUI/VBoxContainer/CenterContainer3/Button" method="_on_PopupDialog_gui_input"]

221
godot/monitor/Monitor.gd Normal file
View File

@ -0,0 +1,221 @@
extends Node
export var monitor_enabled: bool = false
export var development_url: String = "http://localhost:4050/api/v1"
var url_real: String = "https://alai.cromer.cl/api/v1"
export var use_development_url: bool = false
onready var url: String = development_url if use_development_url else url_real
var start_time: int = 0
var started: bool = false
var player: Dictionary = {}
var os_id: int = 0
var godot_version: Dictionary = Engine.get_version_info()
var processor_count: int = OS.get_processor_count()
var screen_count: int = OS.get_screen_count()
var screen_dpi: int = OS.get_screen_dpi()
var screen_size: Vector2 = OS.get_screen_size()
var machine_id: String = OS.get_unique_id()
var locale: String = OS.get_locale()
var game_version: String
var frames: Array = []
var coins: int = 0
var points: int = 0
var objects: Array = []
const empty_object: Dictionary = {
"name": "Object Name",
"state": "Object State",
"position_x": 0,
"position_y": 0,
"velocity_x": 0,
"velocity_y": 0
}
const empty_frame: Dictionary = {
"coins": 0,
"points": 0,
"fps": 0,
"elapsed_time": 0,
"objects": [],
}
# The game dictionary holds all data to be sent to the server
var game: Dictionary = {}
func _ready() -> void:
game_version = get_parent().game_version
player["rut"] = ""
player["name"] = ""
player["email"] = ""
var os_name = OS.get_name()
if os_name == "Android":
os_id = 1
elif os_name == "iOS":
os_id = 2
elif os_name == "HTML5":
os_id = 3
elif os_name == "OSX":
os_id = 4
elif os_name == "Server":
os_id = 5
elif os_name == "Windows":
os_id = 6
elif os_name == "UWP":
os_id = 7
elif os_name == "X11":
os_id = 8
else:
os_id = 0
game["player"] = player
game["level_id"] = 0
game["os_id"] = os_id
game["godot_version"] = godot_version
game["processor_count"] = processor_count
game["machine_id"] = machine_id
game["locale"] = locale
game["screen_count"] = screen_count
game["screen_dpi"] = screen_dpi
game["screen_size"] = screen_size
game["game_version"] = game_version
game["won"] = false
game["timestamp"] = OS.get_unix_time()
game["frames"] = frames
var err = $HTTPRequest.connect("request_completed", self, "_on_request_completed")
if err != OK:
print(err)
err = $MonitorGUI.find_node("Button").connect("input_validated", self, "_on_input_validated")
if err != OK:
print(err)
func _physics_process(_delta: float) -> void:
if monitor_enabled:
if has_node("MonitorGUI") and not $MonitorGUI.visible:
$MonitorGUI.visible = true
if started and not get_tree().paused:
var frame = empty_frame.duplicate(true)
frame["coins"] = coins
frame["points"] = points
frame["fps"] = Engine.get_frames_per_second()
frame["elapsed_time"] = OS.get_ticks_msec() - start_time
var frame_objects = objects.duplicate()
frame["objects"] = frame_objects
frames.append(frame)
if Input.is_action_just_pressed("Send"):
stop_monitor()
send_data()
else:
if Input.is_action_just_pressed("Send"):
start_monitor()
else:
get_tree().paused = false
queue_free()
func _on_input_validated(validated_player: Dictionary) -> void:
$MonitorGUI.queue_free()
get_tree().paused = false
player = validated_player.duplicate(true)
func _object_created(name: String, state: String, position: Vector2, velocity: Vector2) -> void:
if monitor_enabled and started:
add_object(name, state, position, velocity)
func _object_updated(name: String, state: String, position: Vector2, velocity: Vector2) -> void:
if monitor_enabled and started:
remove_object(name)
add_object(name, state, position, velocity)
func _object_removed(name: String) -> void:
if monitor_enabled and started:
remove_object(name)
func start_monitor() -> void:
frames.clear()
game["level_id"] = 2 # PrototypeR
game["won"] = false
game["timestamp"] = OS.get_unix_time()
start_time = OS.get_ticks_msec()
started = true
func stop_monitor() -> void:
started = false
func add_object(name: String, state: String, position: Vector2, velocity: Vector2) -> void:
var object = empty_object.duplicate(true)
object["name"] = name
object["state"] = state
object["position_x"] = position.x
object["position_y"] = position.y
object["velocity_x"] = velocity.x
object["velocity_y"] = velocity.y
objects.append(object)
func remove_object(name: String) -> void:
for i in range(0, objects.size()):
if objects[i]["name"] == name:
objects.remove(i)
func _on_coin_update(amount: int) -> void:
coins = coins + amount
func _on_request_completed(result: int, response_code: int, headers: PoolStringArray, body: PoolByteArray) -> void:
if result != HTTPRequest.RESULT_SUCCESS:
print_debug("Error: Failed to connect with error code: " + str(result))
return
if response_code != HTTPClient.RESPONSE_OK:
print_debug("Error: Failed response with error code: " + str(response_code))
print_debug(headers)
if body.size() > 0:
var json = JSON.parse(body.get_string_from_utf8())
print_debug(JSON.print(json.result, "\t"))
func send_data() -> void:
var json = JSON.print(game)
var headers = ["Content-Type: application/json", "Content-Encoding: gzip", "Content-Transfer-Encoding: base64"]
var body = compress_payload(json)
print("JSON B: " + String(json.length()))
print("JSON MB: " + String(json.length() / pow(2, 20)))
print("Body B: " + String(body.length()))
print("Body MB: " + String(body.length() / pow(2, 20)))
$HTTPRequest.request(url + "/game", headers, false, HTTPClient.METHOD_POST, body)
func compress_payload(payload: String) -> String:
var bytes = payload.to_utf8()
var compressed = bytes.compress(File.COMPRESSION_GZIP)
var new_payload = Marshalls.raw_to_base64(compressed)
return new_payload

View File

@ -0,0 +1,15 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://monitor/Monitor.gd" type="Script" id=1]
[ext_resource path="res://monitor/GUI.tscn" type="PackedScene" id=3]
[node name="Monitor" type="Node"]
pause_mode = 2
script = ExtResource( 1 )
monitor_enabled = true
use_development_url = true
[node name="MonitorGUI" parent="." instance=ExtResource( 3 )]
visible = false
[node name="HTTPRequest" type="HTTPRequest" parent="."]

71
godot/monitor/Rut.gd Normal file
View File

@ -0,0 +1,71 @@
extends LineEdit
var previous_text: String = ""
func _on_Rut_text_changed(_new_text: String) -> void:
var old_pos = caret_position
if text.length() > 12:
text = previous_text
old_pos = old_pos - 2
text = pretty_rut(text)
caret_position = old_pos + 1
previous_text = text
func clean_rut(rut: String) -> String:
rut = rut.strip_escapes()
rut = rut.strip_edges(true, true)
rut = rut.to_lower()
rut = rut.replace(".", "")
rut = rut.replace("-", "")
var rut_temp: String = rut.substr(0, rut.length() - 1)
var verifier: String = rut.substr(rut.length() - 1, 1)
var regex = RegEx.new()
regex.compile("\\D")
rut_temp = regex.sub(rut_temp, "", true)
regex.compile("[^kK\\d]")
verifier = regex.sub(verifier, "", true)
rut = rut_temp + verifier
return rut
func pretty_rut(rut: String) -> String:
rut = clean_rut(rut)
var rut_temp: String = rut.substr(0, rut.length() - 1)
var verifier: String = rut.substr(rut.length() - 1, 1)
var regex = RegEx.new()
regex.compile("[^kK\\d]")
verifier = regex.sub(verifier, "", true)
var byte_array = rut_temp.to_utf8()
byte_array.invert()
var new_byte_array: PoolByteArray = PoolByteArray()
var i = 1
for symbol in byte_array:
new_byte_array.append(symbol)
if i == 3:
new_byte_array.append(".".to_utf8()[0])
i = 0
i = i + 1
if new_byte_array.size() > 0 and new_byte_array[new_byte_array.size() - 1] == ".".to_utf8()[0]:
new_byte_array.resize(new_byte_array.size() - 1)
new_byte_array.invert()
rut_temp = new_byte_array.get_string_from_utf8()
if rut_temp.length() == 0 and verifier.length() > 0:
rut_temp = verifier
elif rut_temp.length() > 0 and verifier.length() > 0:
rut_temp = rut_temp + "-" + verifier
return rut_temp

View File

@ -0,0 +1,9 @@
extends Node
func _play_popup_sound() -> void:
$Popup.play()
func _play_ui_select_sound() -> void:
$Menu.play()

View File

@ -90,6 +90,11 @@ right={
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
Send={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777218,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
[layer_names]

View File

@ -32,7 +32,7 @@ void CameraLimit::_ready()
if (middle_ground != NULL)
{
auto used_rect = middle_ground->get_used_rect();
auto bounds = Vector2(used_rect.position.x + used_rect.size.x, used_rect.position.y + used_rect.size.y - 1);
auto bounds = Vector2(used_rect.position.x + used_rect.size.x, used_rect.position.y + used_rect.size.y);
node = get_tree()->get_root()->find_node("Camera2D", true, false);
auto camera = cast_to<Camera2D>(node);
if (camera != NULL)

View File

@ -9,6 +9,7 @@ void Main::_register_methods()
{
register_method("_ready", &Main::_ready);
register_method("_physics_process", &Main::_physics_process);
register_property<Main, String>("game_version", &Main::set_game_version, &Main::get_game_version, String(main::game_version.c_str()));
register_property<Main, Ref<PackedScene>>("level", &Main::set_level, &Main::get_level, NULL, GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, String("PackedScene"));
register_property<Main, bool>("full_screen", &Main::set_full_screen, &Main::get_full_screen, main::full_screen);
register_property<Main, Vector2>("window_size", &Main::set_window_size, &Main::get_window_size, main::window_size);
@ -28,6 +29,7 @@ void Main::_init()
_os = OS::get_singleton();
_input = Input::get_singleton();
game_version = String(main::game_version.c_str());
full_screen = main::full_screen;
window_size = main::window_size;
launch_screen = main::launch_screen;
@ -35,6 +37,7 @@ void Main::_init()
void Main::_ready()
{
get_tree()->set_pause(true);
if (get_full_screen())
{
_os->set_window_fullscreen(true);
@ -71,6 +74,16 @@ Ref<PackedScene> Main::get_level()
return this->level;
}
void Main::set_game_version(String game_version)
{
this->game_version = game_version;
}
String Main::get_game_version()
{
return this->game_version;
}
void Main::set_full_screen(bool full_screen)
{
this->full_screen = full_screen;

View File

@ -1,6 +1,7 @@
#ifndef ALAI_MAIN_H
#define ALAI_MAIN_H
#include <string>
#include <Godot.hpp>
#include <Node.hpp>
#include <OS.hpp>
@ -21,6 +22,11 @@ namespace godot
*/
namespace main
{
/**
* @brief The default value for the game version.
*
*/
const std::string game_version = "0.1.0";
/**
* @brief The default value for if the game should start in full screen.
*
@ -64,6 +70,11 @@ namespace godot
*
*/
Ref<PackedScene> level;
/**
* @brief The current version of the game.
*
*/
String game_version;
/**
* @brief If the window is full screen or not.
*
@ -137,6 +148,20 @@ namespace godot
*/
Ref<PackedScene> get_level();
/**
* @brief Set the game version object.
*
* @param[in] game_version The new version fo the game.
*/
void set_game_version(String game_version);
/**
* @brief Get the game version object.
*
* @return String The current version of the game.
*/
String get_game_version();
/**
* @brief Set the full screen object.
*

View File

@ -5,6 +5,7 @@
#include <VisibilityNotifier2D.hpp>
#include <SceneTree.hpp>
#include <Texture.hpp>
#include <Viewport.hpp>
using namespace godot;
using namespace player;
@ -21,6 +22,9 @@ void Player::_register_methods()
register_property<Player, float>("gravity", &Player::set_gravity, &Player::get_gravity, player::gravity);
register_property<Player, float>("run_speed", &Player::set_run_speed, &Player::get_run_speed, player::run_speed);
register_property<Player, bool>("double_jump", &Player::set_double_jump, &Player::get_double_jump, player::double_jump);
register_signal<Player>("object_created", "name", GODOT_VARIANT_TYPE_STRING, "state", GODOT_VARIANT_TYPE_STRING, "position", GODOT_VARIANT_TYPE_VECTOR2, "velocity", GODOT_VARIANT_TYPE_VECTOR2);
register_signal<Player>("object_updated", "name", GODOT_VARIANT_TYPE_STRING, "state", GODOT_VARIANT_TYPE_STRING, "position", GODOT_VARIANT_TYPE_VECTOR2, "velocity", GODOT_VARIANT_TYPE_VECTOR2);
register_signal<Player>("object_removed", "name", GODOT_VARIANT_TYPE_STRING);
}
Player::Player()
@ -58,7 +62,6 @@ void Player::_ready()
//animated_sprite->set_sprite_frames(sprite_frames);
auto node = get_parent()->find_node("Middleground");
if (node != nullptr)
{
auto tile_map = Object::cast_to<TileMap>(node);
@ -69,6 +72,27 @@ void Player::_ready()
{
WARN_PRINT("Middleground not found!");
}
auto object_node = get_tree()->get_root()->get_node("Main")->find_node("Monitor");
if (object_node != nullptr)
{
auto state = get_node("StateMachine")->get_child(0);
if (state != nullptr)
{
connect("object_created", object_node, "_object_created");
connect("object_updated", object_node, "_object_updated");
connect("object_removed", object_node, "_object_removed");
emit_signal("object_created", this->get_name(), state->get_name(), get_global_position(), velocity);
}
else
{
WARN_PRINT("State not found!");
}
}
else
{
WARN_PRINT("Data not found!");
}
}
void Player::_physics_process(float delta)
@ -110,6 +134,16 @@ void Player::_physics_process(float delta)
}
}
}
auto state = get_node("StateMachine")->get_child(0);
if (state != nullptr)
{
emit_signal("object_updated", this->get_name(), state->get_name(), get_global_position(), velocity);
}
else
{
WARN_PRINT("State not found!");
}
}
void Player::set_sprite_frames(Ref<SpriteFrames> sprite_frames)

View File

@ -1,6 +1,8 @@
#include "player/states/PlayerJump.h"
#include "player/Player.h"
#include <AudioStreamPlayer.hpp>
using namespace godot;
using namespace player;
@ -26,6 +28,9 @@ void PlayerJump::_init()
void PlayerJump::_state_enter(const String state)
{
auto jump_sound = get_parent()->get_node<AudioStreamPlayer>("Sounds/Jump");
jump_sound->play();
animated_sprite = get_parent()->get_node<AnimatedSprite>("AnimatedSprite");
animated_sprite->stop();
animated_sprite->set_animation("air");