mirror of
https://github.com/tonytins/dressupzack
synced 2025-06-25 08:04:43 -04:00
Cleaned up code base
- Moved character variables and News API address to global GameData class
This commit is contained in:
parent
ec79a57f96
commit
e90a500858
18 changed files with 153 additions and 168 deletions
|
@ -1,8 +1,108 @@
|
|||
# This project is licensed under the Artistic-2.0 license.
|
||||
# See the LICENSE file in the project root for more information.
|
||||
extends Resource
|
||||
extends Node2D
|
||||
|
||||
var top = null
|
||||
var bottom = null
|
||||
var underwear = null
|
||||
var accessory = null
|
||||
const _TDU_VERSION = "0.2"
|
||||
const _SAVE_FILE = "user://character.tdu"
|
||||
|
||||
onready var blank_accessory = preload("res://sprites/clothes/blank_top.png")
|
||||
onready var base_top = preload("res://sprites/character/character_base_top.svg")
|
||||
onready var base_bottom = preload("res://sprites/character/character_base_legs.svg")
|
||||
|
||||
onready var export_win = $Controls/Container/ExportWin
|
||||
onready var import_win = $Controls/Container/ImportWin
|
||||
|
||||
onready var accessory = $Body/Accessory
|
||||
#onready var underwear = $Undies
|
||||
onready var bottom = $Body/Legs
|
||||
onready var top = $Body/Top
|
||||
# onready var eyes = $Body/Head/Eyes
|
||||
# onready var mouth = $Body/Head/Mouth
|
||||
|
||||
func _process(delta):
|
||||
|
||||
if GameData.accessory != null:
|
||||
accessory.texture = GameData.accessory
|
||||
|
||||
# if GameData.underwear != null:
|
||||
# underwear.texture = GameData.underwear
|
||||
|
||||
if GameData.bottom != null:
|
||||
bottom.texture = GameData.bottom
|
||||
|
||||
if GameData.top != null:
|
||||
top.texture = GameData.top
|
||||
|
||||
func save_game():
|
||||
var data_file = {
|
||||
"version": _TDU_VERSION,
|
||||
"game_ver": GameData.version,
|
||||
"accessory": "res://sprites/clothes/blank_top.png",
|
||||
"top": "res://sprites/clothes/blank_top.png",
|
||||
"bottom": "res://sprites/character/character_base_legs.svg",
|
||||
}
|
||||
|
||||
data_file["accessory"] = accessory.texture.resource_path
|
||||
data_file["top"] = top.texture.resource_path
|
||||
data_file["bottom"] = bottom.texture.resource_path
|
||||
|
||||
var file = File.new()
|
||||
if file.open(_SAVE_FILE, File.WRITE) != 0:
|
||||
print("Error opening file")
|
||||
return
|
||||
var json_file = to_json(data_file)
|
||||
|
||||
GameEvents.emit_signal("indicate")
|
||||
|
||||
file.store_line(json_file)
|
||||
file.close()
|
||||
|
||||
func load_game():
|
||||
var file = File.new()
|
||||
|
||||
if not file.file_exists(_SAVE_FILE):
|
||||
print("File not found!")
|
||||
return
|
||||
|
||||
if file.open(_SAVE_FILE, File.READ) != 0:
|
||||
print("Error opening file")
|
||||
return
|
||||
|
||||
var data = parse_json(file.get_as_text())
|
||||
|
||||
var top_texture = ImageTexture.new()
|
||||
var accessory_texture = ImageTexture.new()
|
||||
var bottom_texture = ImageTexture.new()
|
||||
var top_image = Image.new()
|
||||
var accessory_image = Image.new()
|
||||
var bottom_image = Image.new()
|
||||
|
||||
GameEvents.emit_signal("indicate")
|
||||
|
||||
top_image.load(data["top"])
|
||||
top_texture.create_from_image(top_image)
|
||||
top.texture = top_texture
|
||||
|
||||
bottom_image.load(data["bottom"])
|
||||
top_texture.create_from_image(top_image)
|
||||
bottom.texture = top_texture
|
||||
|
||||
accessory_image.load(data["accessory"])
|
||||
accessory_texture.create_from_image(top_image)
|
||||
accessory.texture = accessory_texture
|
||||
|
||||
file.close()
|
||||
|
||||
func _on_clearBtn_pressed():
|
||||
$Click.play()
|
||||
GameData.accessory = blank_accessory
|
||||
GameData.bottom = base_bottom
|
||||
GameData.top = base_top
|
||||
|
||||
func _on_SaveBtn_pressed():
|
||||
$Click.play()
|
||||
save_game()
|
||||
|
||||
func _on_LoadBtn_pressed():
|
||||
$Click.play()
|
||||
load_game()
|
||||
|
|
|
@ -3,3 +3,15 @@
|
|||
extends Node
|
||||
|
||||
var version = "0.0.0"
|
||||
|
||||
const NEWS_API = "https://static.tonybark.com/news/dressup.json"
|
||||
|
||||
var top = null
|
||||
var bottom = null
|
||||
var underwear = null
|
||||
var accessory = null
|
||||
|
||||
enum characters {
|
||||
ZACK,
|
||||
ANTHONY
|
||||
}
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
# This project is licensed under the Artistic-2.0 license.
|
||||
# See the LICENSE file in the project root for more information.
|
||||
extends Node2D
|
||||
|
||||
const _TDU_VERSION = "0.2"
|
||||
const _SAVE_FILE = "user://character.tdu"
|
||||
|
||||
onready var character = preload("res://resources/character.tres")
|
||||
onready var blank_accessory = preload("res://sprites/clothes/blank_top.png")
|
||||
onready var base_top = preload("res://sprites/character/character_base_top.svg")
|
||||
onready var base_bottom = preload("res://sprites/character/character_base_legs.svg")
|
||||
|
||||
onready var export_win = $Controls/Container/ExportWin
|
||||
onready var import_win = $Controls/Container/ImportWin
|
||||
|
||||
onready var accessory = $Body/Accessory
|
||||
#onready var underwear = $Undies
|
||||
onready var bottom = $Body/Legs
|
||||
onready var top = $Body/Top
|
||||
# onready var eyes = $Body/Head/Eyes
|
||||
# onready var mouth = $Body/Head/Mouth
|
||||
|
||||
func _process(delta):
|
||||
|
||||
if character.accessory != null:
|
||||
accessory.texture = character.accessory
|
||||
|
||||
# if character.underwear != null:
|
||||
# underwear.texture = character.underwear
|
||||
|
||||
if character.bottom != null:
|
||||
bottom.texture = character.bottom
|
||||
|
||||
if character.top != null:
|
||||
top.texture = character.top
|
||||
|
||||
func save_game():
|
||||
var data_file = {
|
||||
"version": _TDU_VERSION,
|
||||
"game_ver": GameData.version,
|
||||
"accessory": "res://sprites/clothes/blank_top.png",
|
||||
"top": "res://sprites/clothes/blank_top.png",
|
||||
"bottom": "res://sprites/character/character_base_legs.svg",
|
||||
}
|
||||
|
||||
data_file["accessory"] = accessory.texture.resource_path
|
||||
data_file["top"] = top.texture.resource_path
|
||||
data_file["bottom"] = bottom.texture.resource_path
|
||||
|
||||
var file = File.new()
|
||||
if file.open(_SAVE_FILE, File.WRITE) != 0:
|
||||
print("Error opening file")
|
||||
return
|
||||
var json_file = to_json(data_file)
|
||||
|
||||
GameEvents.emit_signal("indicate")
|
||||
|
||||
file.store_line(json_file)
|
||||
file.close()
|
||||
|
||||
func load_game():
|
||||
var file = File.new()
|
||||
|
||||
if not file.file_exists(_SAVE_FILE):
|
||||
print("File not found!")
|
||||
return
|
||||
|
||||
if file.open(_SAVE_FILE, File.READ) != 0:
|
||||
print("Error opening file")
|
||||
return
|
||||
|
||||
var data = parse_json(file.get_as_text())
|
||||
|
||||
var top_texture = ImageTexture.new()
|
||||
var accessory_texture = ImageTexture.new()
|
||||
var bottom_texture = ImageTexture.new()
|
||||
var top_image = Image.new()
|
||||
var accessory_image = Image.new()
|
||||
var bottom_image = Image.new()
|
||||
|
||||
GameEvents.emit_signal("indicate")
|
||||
|
||||
top_image.load(data["top"])
|
||||
top_texture.create_from_image(top_image)
|
||||
top.texture = top_texture
|
||||
|
||||
bottom_image.load(data["bottom"])
|
||||
top_texture.create_from_image(top_image)
|
||||
bottom.texture = top_texture
|
||||
|
||||
accessory_image.load(data["accessory"])
|
||||
accessory_texture.create_from_image(top_image)
|
||||
accessory.texture = accessory_texture
|
||||
|
||||
file.close()
|
||||
|
||||
func _on_clearBtn_pressed():
|
||||
$Click.play()
|
||||
character.accessory = blank_accessory
|
||||
character.bottom = base_bottom
|
||||
character.top = base_top
|
||||
|
||||
func _on_SaveBtn_pressed():
|
||||
$Click.play()
|
||||
save_game()
|
||||
|
||||
func _on_LoadBtn_pressed():
|
||||
$Click.play()
|
||||
load_game()
|
|
@ -3,5 +3,5 @@
|
|||
extends "res://scripts/clothing/clothing_base.gd"
|
||||
|
||||
func _on_accessory_pressed():
|
||||
character.accessory = texture_normal
|
||||
GameData.accessory = texture_normal
|
||||
$select.play()
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
extends "res://scripts/clothing/clothing_base.gd"
|
||||
|
||||
func _on_bottoms_pressed():
|
||||
character.bottom = texture_normal
|
||||
GameData.bottom = texture_normal
|
||||
$select.play()
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
extends "res://scripts/clothing/clothing_base.gd"
|
||||
|
||||
func _on_tops_pressed():
|
||||
character.top = texture_normal
|
||||
GameData.top = texture_normal
|
||||
$select.play()
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
extends "res://scripts/clothing/clothing_base.gd"
|
||||
|
||||
func _on_undies_pressed():
|
||||
character.underwear = texture_normal
|
||||
GameData.underwear = texture_normal
|
||||
$select.play()
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
# This project is licensed under the Artistic-2.0 license.
|
||||
# See the LICENSE file in the project root for more information.
|
||||
extends Node2D
|
|
@ -2,8 +2,6 @@
|
|||
# See the LICENSE file in the project root for more information.
|
||||
extends Control
|
||||
|
||||
const _NEWS_API = "https://static.tonybark.com/news/dressup.json"
|
||||
|
||||
export var version: String = "1.0.0"
|
||||
|
||||
onready var character = preload("res://resources/character.tres")
|
||||
|
@ -18,11 +16,11 @@ onready var news_btn = $CenterBtns/ButtonCtr/NewsBtn
|
|||
onready var http_request = $NewsWin/NewsBtns/HTTPRequest
|
||||
|
||||
func _ready():
|
||||
var verLabel = $versionLbl
|
||||
var verLabel = $VersionLbl
|
||||
verLabel.text = "v" + version
|
||||
GameData.version = version
|
||||
|
||||
var err = http_request.request(_NEWS_API)
|
||||
var err = http_request.request(GameData.NEWS_API)
|
||||
|
||||
if err != OK:
|
||||
news_btn.disabled = true
|
|
@ -1,7 +1,5 @@
|
|||
extends WindowDialog
|
||||
|
||||
const _NEWS_API = "https://static.tonybark.com/news/dressup.json"
|
||||
|
||||
onready var news_list = $News
|
||||
onready var http_request = $NewsBtns/HTTPRequest
|
||||
|
||||
|
@ -16,4 +14,4 @@ func _on_HTTPRequest_request_completed(result, response_code, headers, body):
|
|||
|
||||
func _on_SyncBtn_pressed():
|
||||
news_list.clear()
|
||||
http_request.request(_NEWS_API)
|
||||
http_request.request(GameData.NEWS_API)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue