Skip to content

Commit

Permalink
Initial commit for the launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Martomate committed Jun 30, 2019
0 parents commit aa2c935
Show file tree
Hide file tree
Showing 40 changed files with 663 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .import/background.png-98289422cd7d93003950872a7b97021f.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_md5="14d7b363adde663a2aecf034ffcd7b4c"
dest_md5="e7d43bb43f3343b22a57983b87ad4d09"

Binary file not shown.
3 changes: 3 additions & 0 deletions .import/button_focus.png-0a50fcfc61c2d12bdc3066c079b16efe.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_md5="f0631945fc4f002ab0ca23e74915bf0e"
dest_md5="9e49e3c9f9d0be420b111a7b588fa807"

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_md5="cf208a246ebfe91019ec76bf4b89a051"
dest_md5="89bdc2a1dfc340328f1c684fee2e4919"

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_md5="3e6cf01ecc1792c4caa9d8490c94db8a"
dest_md5="9a1a5822a2742edf780a7bd0508c40bc"

Binary file not shown.
3 changes: 3 additions & 0 deletions .import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_md5="f6858a227f37125e64dd63a0698f55ff"
dest_md5="84354d389441ec14189ad820ba651c8c"

Binary file not shown.
3 changes: 3 additions & 0 deletions .import/icon_2d_big.png-66af80b41df5b14ec63d782610b10142.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_md5="60ba4a2c96433e7261d7e7ccbf34d274"
dest_md5="5041785c72d8e22b708e0013644a5b2c"

Binary file not shown.
3 changes: 3 additions & 0 deletions .import/icon_3d_big.png-f906e6fa403cc9bf0aa7bf29a63327f3.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_md5="5eae9d8c57d395119b94fbcec7009a80"
dest_md5="a845b52e53bfe10afbfe1e278d6f1fa3"

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_md5="60ba4a2c96433e7261d7e7ccbf34d274"
dest_md5="5041785c72d8e22b708e0013644a5b2c"

14 changes: 14 additions & 0 deletions GameVersion.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class_name GameVersion

var id: String
var name: String
var release_date: String
var download_url: String
var download_size: int

func _init(id: String, name: String, release_date: String, download_url: String, download_size: int):
self.id = id
self.name = name
self.release_date = release_date
self.download_url = download_url
self.download_size = download_size
Binary file added Hexacraft Launcher.exe
Binary file not shown.
Binary file added Hexacraft Launcher.pck
Binary file not shown.
Binary file added Hexacraft Launcher_original.exe
Binary file not shown.
Binary file added Verdana.ttf
Binary file not shown.
24 changes: 24 additions & 0 deletions VersionList.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
extends VBoxContainer

export (PackedScene) var ListItemType

var _selected_version: GameVersion = null

func _ready():
remove_child($VersionListItem)
$RequestVersionList.request("https://www.martomate.com/api/hexacraft/versions")

func _on_RequestVersionList_request_completed(result, response_code, headers, body):
var p = JSON.parse(body.get_string_from_utf8())
if typeof(p.result) == TYPE_ARRAY:
for v in p.result:
var item = ListItemType.instance()
print(v)
var gameVersion = GameVersion.new(v["id"], v["name"], v["release_date"], v["url"])
item.fillWithData(gameVersion)
add_child(item)
else:
print("unexpected results")

func selected_version():
return _selected_version
4 changes: 4 additions & 0 deletions VersionListItem.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extends MarginContainer

func fillWithData(id: String, name: String, release_date: String, download_url: String):
$HBoxContainer/VersionNumber.text = str(name, "\treleased on ", release_date, "\nUrl: ", download_url)
19 changes: 19 additions & 0 deletions VersionListItem.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://VersionListItem.gd" type="Script" id=1]

[node name="VersionListItem" type="MarginContainer"]
margin_right = 40.0
margin_bottom = 40.0
script = ExtResource( 1 )

[node name="HBoxContainer" type="HBoxContainer" parent="."]
margin_right = 40.0
margin_bottom = 40.0

[node name="VersionNumber" type="Label" parent="HBoxContainer"]
margin_top = 13.0
margin_right = 20.0
margin_bottom = 27.0
text = "0.8"

30 changes: 30 additions & 0 deletions Versions.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
extends HBoxContainer

# Declare member variables here. Examples:
# var a = 2
# var b = "text"

# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.

# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass


func _on_Play_pressed():
var list = $VersionListPanel/ScrollContainer/VersionList

if !game_version_downloaded():
download_game_version()
run_game(version)
pass # Replace with function body.


func _on_Refresh_pressed():
pass # Replace with function body.


func _on_AddManually_pressed():
pass # Replace with function body.
105 changes: 105 additions & 0 deletions Window.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
extends Control

var currentVersion = "latest-version"

var launcher_data_path: String = "user://launcher_data.json"

var versions: Dictionary = {}

func _ready():
var file = File.new()
if file.file_exists(launcher_data_path):
file.open(launcher_data_path, File.READ)
var json = JSON.parse(file.get_as_text())
loadVersionsDict(json["versions"])
else:
$CenterPlay/MarginPlay/Play.hide()

$VersionListRequest.request("https://www.martomate.com/api/hexacraft/versions")

func saveLauncherData():
var file = File.new()
file.open("user://launcher_data.json", File.WRITE)
var jsonStr = JSON.print({"versions": versions.values()})
file.store_string(jsonStr)

func _on_Play_pressed():
if ensureVersionIsDownloaded(currentVersion):
startGame(currentVersion)

func startGame(versionID):
print("success!")

func ensureVersionIsDownloaded(versionID):
var version = versions[versionID]
var dir = Directory.new()
print(dir.open("user://"))

var base = "user://versions/" + version.name

if !dir.dir_exists(base):
dir.make_dir(base)

$VersionDownloader.download_file = "user://temp/tmp.zip"
$VersionDownloader.request(version.download_url)
$CenterPlay/MarginPlay/Play.hide()
$CenterPlay/MarginPlay/Progress.show()
$CenterPlay/MarginPlay/Progress.max_value = version.download_size
$DownloadProgress.start()
print("Requesting " + version.download_url)
return false
else:
return true

func _on_Versions_item_selected(ID):
var versionSelector = $MarginContainer/HBoxContainer/Versions
currentVersion = versionSelector.get_item_metadata(ID)

func _on_Settings_pressed():
pass # Replace with function body.


func _on_VersionListRequest_request_completed(result, response_code, headers, body):
if result == HTTPRequest.RESULT_SUCCESS:
loadVersionsDict(JSON.parse(body.get_string_from_utf8()))
$CenterPlay/MarginPlay/Play.show()
saveLauncherData()
else:
print(str("Could not download latest version list. Result was: ", result))

func loadVersionsDict(p: JSONParseResult):
if typeof(p.result) == TYPE_ARRAY:
for v in p.result:
var id = v["id"]
versions[id] = GameVersion.new(id, v["name"], v["release_date"], v["url"], v["fileSize"])

var sortedVersions = Array(versions.values())
sortedVersions.sort_custom(GameVersionSorter, "sort")

var versionSelector = $MarginContainer/HBoxContainer/Versions
versionSelector.clear()

versions["latest-version"] = sortedVersions[0]
versionSelector.add_item(str("Latest version (", sortedVersions[0].name, ")"))
versionSelector.set_item_metadata(0, "latest-version")

for v in sortedVersions:
versionSelector.add_item(v.name)
versionSelector.set_item_metadata(versionSelector.get_item_count() - 1, v.id)

versionSelector.select(0)

else:
print("unexpected results")

class GameVersionSorter:
static func sort(a, b):
return a.release_date > b.release_date


func _on_VersionDownloader_request_completed(result, response_code, headers, body):
startGame(currentVersion)


func _on_DownloadProgress_timeout():
$CenterPlay/MarginPlay/Progress.value = $VersionDownloader.get_downloaded_bytes()
135 changes: 135 additions & 0 deletions Window.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
[gd_scene load_steps=10 format=2]

[ext_resource path="res://main_theme.tres" type="Theme" id=1]
[ext_resource path="res://Window.gd" type="Script" id=2]
[ext_resource path="res://background.png" type="Texture" id=3]
[ext_resource path="res://Verdana.ttf" type="DynamicFontData" id=4]
[ext_resource path="res://play_button_style.tres" type="StyleBox" id=5]

[sub_resource type="DynamicFont" id=1]
size = 64
outline_size = 2
outline_color = Color( 0, 0, 0, 1 )
font_data = ExtResource( 4 )

[sub_resource type="Theme" id=3]
Button/colors/font_color = Color( 0.878431, 0.878431, 0.878431, 1 )
Button/colors/font_color_disabled = Color( 0.9, 0.9, 0.9, 0.2 )
Button/colors/font_color_hover = Color( 0.941176, 0.941176, 0.941176, 1 )
Button/colors/font_color_pressed = Color( 1, 1, 1, 1 )
Button/constants/hseparation = 2
Button/fonts/font = null
Button/styles/disabled = null
Button/styles/focus = ExtResource( 5 )
Button/styles/hover = ExtResource( 5 )
Button/styles/normal = ExtResource( 5 )
Button/styles/pressed = ExtResource( 5 )

[sub_resource type="DynamicFont" id=2]
size = 32
font_data = ExtResource( 4 )

[sub_resource type="Theme" id=4]
ProgressBar/colors/font_color = Color( 0.941176, 0.941176, 0.941176, 1 )
ProgressBar/colors/font_color_shadow = Color( 0, 0, 0, 1 )
ProgressBar/fonts/font = null
ProgressBar/styles/bg = ExtResource( 5 )
ProgressBar/styles/fg = null

[node name="Window" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
theme = ExtResource( 1 )
script = ExtResource( 2 )

[node name="TextureRect" type="TextureRect" parent="."]
margin_right = 720.0
margin_bottom = 540.0
texture = ExtResource( 3 )

[node name="GameTitle" type="Label" parent="."]
anchor_right = 1.0
margin_bottom = 79.0
custom_fonts/font = SubResource( 1 )
text = "Hexacraft"
align = 1

[node name="CenterPlay" type="CenterContainer" parent="."]
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_top = -192.0

[node name="MarginPlay" type="MarginContainer" parent="CenterPlay"]
margin_left = 296.0
margin_right = 424.0
margin_bottom = 192.0
custom_constants/margin_bottom = 128

[node name="Play" type="Button" parent="CenterPlay/MarginPlay"]
margin_right = 128.0
margin_bottom = 64.0
rect_min_size = Vector2( 128, 64 )
size_flags_horizontal = 0
theme = SubResource( 3 )
custom_fonts/font = SubResource( 2 )
text = "Play"

[node name="Progress" type="ProgressBar" parent="CenterPlay/MarginPlay"]
visible = false
margin_right = 128.0
margin_bottom = 64.0
rect_min_size = Vector2( 128, 64 )
theme = SubResource( 4 )

[node name="MarginContainer" type="MarginContainer" parent="."]
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_top = -37.0
custom_constants/margin_right = 8
custom_constants/margin_left = 8
custom_constants/margin_bottom = 8

[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer"]
margin_left = 8.0
margin_right = 712.0
margin_bottom = 29.0

[node name="Versions" type="OptionButton" parent="MarginContainer/HBoxContainer"]
margin_right = 215.0
margin_bottom = 29.0
size_flags_horizontal = 0
text = "Latest release (0.8)"
flat = true
items = [ "Latest release (0.8)", null, false, -1, null ]
selected = 0

[node name="Filler" type="Label" parent="MarginContainer/HBoxContainer"]
margin_left = 219.0
margin_top = 3.0
margin_right = 604.0
margin_bottom = 26.0
size_flags_horizontal = 3

[node name="Settings" type="Button" parent="MarginContainer/HBoxContainer"]
margin_left = 608.0
margin_right = 704.0
margin_bottom = 29.0
size_flags_horizontal = 0
text = "Settings"
flat = true

[node name="VersionListRequest" type="HTTPRequest" parent="."]

[node name="VersionDownloader" type="HTTPRequest" parent="."]

[node name="DownloadProgress" type="Timer" parent="."]
wait_time = 0.1

[connection signal="pressed" from="CenterPlay/MarginPlay/Play" to="." method="_on_Play_pressed"]
[connection signal="item_selected" from="MarginContainer/HBoxContainer/Versions" to="." method="_on_Versions_item_selected"]
[connection signal="pressed" from="MarginContainer/HBoxContainer/Settings" to="." method="_on_Settings_pressed"]
[connection signal="request_completed" from="VersionListRequest" to="." method="_on_VersionListRequest_request_completed"]
[connection signal="request_completed" from="VersionDownloader" to="." method="_on_VersionDownloader_request_completed"]
[connection signal="timeout" from="DownloadProgress" to="." method="_on_DownloadProgress_timeout"]
Binary file added background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit aa2c935

Please sign in to comment.