1
0
Fork 0
mirror of https://github.com/tonytins/dressupzack synced 2025-05-05 13:34:48 -04:00

character_base code is now in an external script

This commit is contained in:
Tony Bark 2021-05-31 02:37:29 -04:00
parent c3a79164a4
commit 230af8d840
3 changed files with 108 additions and 131 deletions

View file

@ -28,112 +28,7 @@
[ext_resource path="res://sprites/clothes/blank_top.png" type="Texture" id=26]
[ext_resource path="res://sprites/character/character_base_head.svg" type="Texture" id=27]
[ext_resource path="res://sprites/character/mouth/mouth11.png" type="Texture" id=28]
[sub_resource type="GDScript" id=1]
script/source = "# Anthony Wilcox licenses this file to you under the MPL 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 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)
file.store_line(json_file)
print_debug(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_line())
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()
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()
GameEvents.emit_signal(\"indicate\")
save_game()
func _on_LoadBtn_pressed():
$Click.play()
GameEvents.emit_signal(\"indicate\")
load_game()
"
[ext_resource path="res://scripts/character_base.gd" type="Script" id=29]
[sub_resource type="SpriteFrames" id=2]
animations = [ {
@ -161,7 +56,7 @@ animations = [ {
[node name="characterBase" type="Node2D"]
position = Vector2( -19, -92 )
script = SubResource( 1 )
script = ExtResource( 29 )
[node name="Click" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 24 )
@ -179,6 +74,7 @@ __meta__ = {
position = Vector2( -33.7592, 99.4079 )
scale = Vector2( 0.927713, 1 )
frames = SubResource( 2 )
frame = 1
playing = true
[node name="legs" type="Sprite" parent="body"]
@ -196,13 +92,13 @@ texture = ExtResource( 27 )
[node name="eyes" type="AnimatedSprite" parent="body/head"]
position = Vector2( 17.6857, 4.22147 )
frames = SubResource( 3 )
frame = 2
frame = 1
playing = true
[node name="mouth" type="AnimatedSprite" parent="body/head"]
position = Vector2( 38.1195, 8.68453 )
frames = SubResource( 4 )
frame = 5
frame = 9
playing = true
[node name="accessory" type="Sprite" parent="body"]

View file

@ -1,22 +0,0 @@
# This project is licensed under the MPL license.
# See the LICENSE file in the project root for more information.
extends Node2D
onready var character = preload("res://resources/character.tres")
onready var accessory = $Accessory
onready var underwear = $Undies
onready var bottom = $Bottom
onready var top = $Top
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

103
scripts/character_base.gd Normal file
View file

@ -0,0 +1,103 @@
# 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 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)
file.store_line(json_file)
print_debug(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_line())
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()
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()
GameEvents.emit_signal("indicate")
save_game()
func _on_LoadBtn_pressed():
$Click.play()
GameEvents.emit_signal("indicate")
load_game()