forked from interstellar_development/freettrpg
		
	Version: 0.0.2
Second major release, minor tweaks, fully dynamic stats, now requires the official contentpack.
This commit is contained in:
		
							parent
							
								
									e5911fd155
								
							
						
					
					
						commit
						0a6ff7224a
					
				
					 8 changed files with 72 additions and 143 deletions
				
			
		|  | @ -11,37 +11,6 @@ grow_horizontal = 2 | ||||||
| grow_vertical = 2 | grow_vertical = 2 | ||||||
| script = ExtResource("1_xsj3b") | script = ExtResource("1_xsj3b") | ||||||
| 
 | 
 | ||||||
| [node name="input_name" type="TextEdit" parent="."] |  | ||||||
| offset_left = 16.0 |  | ||||||
| offset_top = 72.0 |  | ||||||
| offset_right = 272.0 |  | ||||||
| offset_bottom = 112.0 |  | ||||||
| placeholder_text = "Name" |  | ||||||
| 
 |  | ||||||
| [node name="input_id" type="TextEdit" parent="."] |  | ||||||
| layout_mode = 0 |  | ||||||
| offset_left = 16.0 |  | ||||||
| offset_top = 16.0 |  | ||||||
| offset_right = 272.0 |  | ||||||
| offset_bottom = 56.0 |  | ||||||
| placeholder_text = "ID" |  | ||||||
| 
 |  | ||||||
| [node name="input_hp" type="TextEdit" parent="."] |  | ||||||
| layout_mode = 0 |  | ||||||
| offset_left = 16.0 |  | ||||||
| offset_top = 128.0 |  | ||||||
| offset_right = 272.0 |  | ||||||
| offset_bottom = 168.0 |  | ||||||
| placeholder_text = "HP" |  | ||||||
| 
 |  | ||||||
| [node name="input_level" type="TextEdit" parent="."] |  | ||||||
| layout_mode = 0 |  | ||||||
| offset_left = 16.0 |  | ||||||
| offset_top = 184.0 |  | ||||||
| offset_right = 272.0 |  | ||||||
| offset_bottom = 224.0 |  | ||||||
| placeholder_text = "Level" |  | ||||||
| 
 |  | ||||||
| [node name="button" type="Button" parent="."] | [node name="button" type="Button" parent="."] | ||||||
| layout_mode = 0 | layout_mode = 0 | ||||||
| offset_left = 512.0 | offset_left = 512.0 | ||||||
|  |  | ||||||
							
								
								
									
										6
									
								
								scenes/menu/input-output.tscn
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								scenes/menu/input-output.tscn
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,6 @@ | ||||||
|  | [gd_scene format=3 uid="uid://rkl6u7cdusys"] | ||||||
|  | 
 | ||||||
|  | [node name="Input-output" type="TextEdit"] | ||||||
|  | offset_right = 168.0 | ||||||
|  | offset_bottom = 40.0 | ||||||
|  | scale = Vector2(2, 2) | ||||||
|  | @ -42,7 +42,7 @@ offset_top = 432.0 | ||||||
| offset_right = 592.0 | offset_right = 592.0 | ||||||
| offset_bottom = 455.0 | offset_bottom = 455.0 | ||||||
| scale = Vector2(3, 3) | scale = Vector2(3, 3) | ||||||
| text = "Version: 0.0.1" | text = "Version: 0.0.2" | ||||||
| 
 | 
 | ||||||
| [connection signal="pressed" from="Button" to="." method="_on_button_pressed"] | [connection signal="pressed" from="Button" to="." method="_on_button_pressed"] | ||||||
| [connection signal="pressed" from="Button2" to="." method="_on_button_2_pressed"] | [connection signal="pressed" from="Button2" to="." method="_on_button_2_pressed"] | ||||||
|  |  | ||||||
|  | @ -11,41 +11,6 @@ grow_horizontal = 2 | ||||||
| grow_vertical = 2 | grow_vertical = 2 | ||||||
| script = ExtResource("1_dcehj") | script = ExtResource("1_dcehj") | ||||||
| 
 | 
 | ||||||
| [node name="input_id" type="TextEdit" parent="."] |  | ||||||
| layout_mode = 0 |  | ||||||
| offset_left = 16.0 |  | ||||||
| offset_top = 16.0 |  | ||||||
| offset_right = 272.0 |  | ||||||
| offset_bottom = 56.0 |  | ||||||
| placeholder_text = "ID" |  | ||||||
| 
 |  | ||||||
| [node name="output_name" type="TextEdit" parent="."] |  | ||||||
| layout_mode = 0 |  | ||||||
| offset_left = 16.0 |  | ||||||
| offset_top = 72.0 |  | ||||||
| offset_right = 272.0 |  | ||||||
| offset_bottom = 112.0 |  | ||||||
| placeholder_text = "Name" |  | ||||||
| editable = false |  | ||||||
| 
 |  | ||||||
| [node name="output_hp" type="TextEdit" parent="."] |  | ||||||
| layout_mode = 0 |  | ||||||
| offset_left = 16.0 |  | ||||||
| offset_top = 128.0 |  | ||||||
| offset_right = 272.0 |  | ||||||
| offset_bottom = 168.0 |  | ||||||
| placeholder_text = "HP" |  | ||||||
| editable = false |  | ||||||
| 
 |  | ||||||
| [node name="output_level" type="TextEdit" parent="."] |  | ||||||
| layout_mode = 0 |  | ||||||
| offset_left = 16.0 |  | ||||||
| offset_top = 184.0 |  | ||||||
| offset_right = 272.0 |  | ||||||
| offset_bottom = 224.0 |  | ||||||
| placeholder_text = "Level" |  | ||||||
| editable = false |  | ||||||
| 
 |  | ||||||
| [node name="button" type="Button" parent="."] | [node name="button" type="Button" parent="."] | ||||||
| layout_mode = 0 | layout_mode = 0 | ||||||
| offset_left = 512.0 | offset_left = 512.0 | ||||||
|  |  | ||||||
|  | @ -1,15 +1,42 @@ | ||||||
| extends Node | extends Node | ||||||
| 
 | 
 | ||||||
| func saveJSON(): | var field = preload("res://scenes/menu/input-output.tscn") | ||||||
| 	var save_path = str("user://player_data"+$input_id.text+".json") | var data:Dictionary | ||||||
|  | 
 | ||||||
|  | func loadJSON(save_path): | ||||||
|  | 	if not FileAccess.file_exists(save_path): | ||||||
|  | 		return false | ||||||
|  | 	var file_access = FileAccess.open(save_path, FileAccess.READ) | ||||||
|  | 	var json_string = file_access.get_line() | ||||||
|  | 	file_access.close() | ||||||
|  | 
 | ||||||
|  | 	var json = JSON.new() | ||||||
|  | 	var error = json.parse(json_string) | ||||||
|  | 	if error: | ||||||
|  | 		print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line()) | ||||||
|  | 		return false | ||||||
|  | 
 | ||||||
|  | 	data = json.data | ||||||
|  | 	return true | ||||||
|  | 
 | ||||||
|  | func _ready(): | ||||||
|  | 	if loadJSON("res://content/stats.json"): | ||||||
|  | 		for i in range(int(data.get("amount"))): | ||||||
|  | 			var field_instance = field.instantiate() | ||||||
|  | 			add_child(field_instance) | ||||||
|  | 			field.resource_name = str("field_"+str(i)) | ||||||
|  | 		for i in range(int(data.get("amount"))): | ||||||
|  | 			get_child(i+1).position = Vector2(16,(16+i*88)) | ||||||
|  | 			get_child(i+1).placeholder_text = data.get(str(i)) | ||||||
|  | 
 | ||||||
|  | func saveJSON(save_path):	 | ||||||
|  | 	var save_data = {} | ||||||
| 	 | 	 | ||||||
| 	var data := { | 	for i in range(int(data.get("amount"))): | ||||||
| 		"name": $input_name.text, | 		if i > 0: | ||||||
| 		"hp": $input_hp.text, | 			save_data[data.get(str(i))] = get_child(i+1).text | ||||||
| 		"level": $input_level.text |  | ||||||
| 	} |  | ||||||
| 	 | 	 | ||||||
| 	var json_string = JSON.stringify(data) | 	var json_string = JSON.stringify(save_data) | ||||||
| 	 | 	 | ||||||
| 	var file_access = FileAccess.open(save_path, FileAccess.WRITE) | 	var file_access = FileAccess.open(save_path, FileAccess.WRITE) | ||||||
| 	if not file_access: | 	if not file_access: | ||||||
|  | @ -20,7 +47,8 @@ func saveJSON(): | ||||||
| 	file_access.close() | 	file_access.close() | ||||||
| 
 | 
 | ||||||
| func _on_button_pressed(): | func _on_button_pressed(): | ||||||
| 	saveJSON() | 	var save_path = str("user://player_data"+get_child(1).text+".json") | ||||||
|  | 	saveJSON(save_path) | ||||||
| 
 | 
 | ||||||
| func _process(delta): | func _process(delta): | ||||||
| 	if Input.is_action_pressed("escape"): | 	if Input.is_action_pressed("escape"): | ||||||
|  |  | ||||||
|  | @ -1,10 +1,12 @@ | ||||||
| extends Node | extends Node | ||||||
| 
 | 
 | ||||||
| func loadJSON(): | var field = preload("res://scenes/menu/input-output.tscn") | ||||||
| 	var save_path = str("user://player_data"+$input_id.text+".json") | var data:Dictionary | ||||||
| 	print(save_path) | var amount | ||||||
|  | 
 | ||||||
|  | func loadJSON(save_path): | ||||||
| 	if not FileAccess.file_exists(save_path): | 	if not FileAccess.file_exists(save_path): | ||||||
| 		return | 		return false | ||||||
| 	var file_access = FileAccess.open(save_path, FileAccess.READ) | 	var file_access = FileAccess.open(save_path, FileAccess.READ) | ||||||
| 	var json_string = file_access.get_line() | 	var json_string = file_access.get_line() | ||||||
| 	file_access.close() | 	file_access.close() | ||||||
|  | @ -13,16 +15,29 @@ func loadJSON(): | ||||||
| 	var error = json.parse(json_string) | 	var error = json.parse(json_string) | ||||||
| 	if error: | 	if error: | ||||||
| 		print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line()) | 		print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line()) | ||||||
| 		return | 		return false | ||||||
| 
 | 
 | ||||||
| 	var data:Dictionary = json.data | 	data = json.data | ||||||
| 	$output_name.text = str("Name: "+data.get("name")) | 	return true | ||||||
| 	$output_hp.text = str("HP: "+data.get("hp")) | 
 | ||||||
| 	$output_level.text = str("Level: "+data.get("level")) | func _ready(): | ||||||
| 	 | 	if loadJSON("res://content/stats.json"): | ||||||
|  | 		for i in range(int(data.get("amount"))): | ||||||
|  | 			var field_instance = field.instantiate() | ||||||
|  | 			add_child(field_instance) | ||||||
|  | 			field.resource_name = str("field_"+str(i)) | ||||||
|  | 		for i in range(int(data.get("amount"))): | ||||||
|  | 			get_child(i+1).position = Vector2(16,(16+i*88)) | ||||||
|  | 			get_child(i+1).placeholder_text = data.get(str(i)) | ||||||
|  | 			if i > 0: | ||||||
|  | 				get_child(i+1).editable = false | ||||||
|  | 		amount = data.get("amount") | ||||||
| 
 | 
 | ||||||
| func _on_button_pressed(): | func _on_button_pressed(): | ||||||
| 	loadJSON() | 	var save_path = str("user://player_data"+get_child(1).text+".json") | ||||||
|  | 	if loadJSON(save_path): | ||||||
|  | 		for i in range(int(amount)-1): | ||||||
|  | 			get_child(i+2).text = data.get(str(get_child(i+2).placeholder_text)) | ||||||
| 
 | 
 | ||||||
| func _process(delta): | func _process(delta): | ||||||
| 	if Input.is_action_pressed("escape"): | 	if Input.is_action_pressed("escape"): | ||||||
|  |  | ||||||
|  | @ -1,7 +1,6 @@ | ||||||
| extends CharacterBody2D | extends CharacterBody2D | ||||||
| 
 | 
 | ||||||
| @export var speed = 200 | @export var speed = 200 | ||||||
| var toCalculate = position |  | ||||||
| var distanceTo = 0 | var distanceTo = 0 | ||||||
| var active = false | var active = false | ||||||
| 
 | 
 | ||||||
|  | @ -15,11 +14,9 @@ func _physics_process(delta): | ||||||
| 	if active: | 	if active: | ||||||
| 		get_input() | 		get_input() | ||||||
| 		move_and_slide() | 		move_and_slide() | ||||||
| 	distanceTo = position.distance_to(toCalculate) | 	var toCalculate = position | ||||||
|  | 	distanceTo += position.distance_to(toCalculate) | ||||||
| 	if distanceTo > 500 and active: | 	if distanceTo > 500 and active: | ||||||
| 		$Label1.visible = false |  | ||||||
| 		$Label2.visible = false |  | ||||||
| 		$Label3.visible = false |  | ||||||
| 		active = false | 		active = false | ||||||
| 		$camera.enabled = false | 		$camera.enabled = false | ||||||
| 		get_parent().next() | 		get_parent().next() | ||||||
|  | @ -28,28 +25,4 @@ func _physics_process(delta): | ||||||
| func start(): | func start(): | ||||||
| 	$camera.enabled = true | 	$camera.enabled = true | ||||||
| 	active = true | 	active = true | ||||||
| 	toCalculate = position |  | ||||||
| 	$Label1.visible = true |  | ||||||
| 	$Label2.visible = true |  | ||||||
| 	$Label3.visible = true |  | ||||||
| 
 | 
 | ||||||
| func loadJSON(id): |  | ||||||
| 	var save_path = str("user://player_data"+str(id)+".json") |  | ||||||
| 	print(save_path) |  | ||||||
| 	if not FileAccess.file_exists(save_path): |  | ||||||
| 		return |  | ||||||
| 	var file_access = FileAccess.open(save_path, FileAccess.READ) |  | ||||||
| 	var json_string = file_access.get_line() |  | ||||||
| 	file_access.close() |  | ||||||
| 
 |  | ||||||
| 	var json = JSON.new() |  | ||||||
| 	var error = json.parse(json_string) |  | ||||||
| 	if error: |  | ||||||
| 		print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line()) |  | ||||||
| 		return |  | ||||||
| 
 |  | ||||||
| 	var data:Dictionary = json.data |  | ||||||
| 	$Label1.text = str("Name: "+data.get("name")) |  | ||||||
| 	$Label2.text = str("HP: "+data.get("hp")) |  | ||||||
| 	$Label3.text = str("Level: "+data.get("level")) |  | ||||||
| 	 |  | ||||||
|  |  | ||||||
|  | @ -17,30 +17,3 @@ shape = SubResource("RectangleShape2D_kf6qt") | ||||||
| 
 | 
 | ||||||
| [node name="camera" type="Camera2D" parent="."] | [node name="camera" type="Camera2D" parent="."] | ||||||
| enabled = false | enabled = false | ||||||
| 
 |  | ||||||
| [node name="Label1" type="Label" parent="."] |  | ||||||
| visible = false |  | ||||||
| offset_left = -384.0 |  | ||||||
| offset_top = 56.0 |  | ||||||
| offset_right = -288.0 |  | ||||||
| offset_bottom = 88.0 |  | ||||||
| scale = Vector2(2, 2) |  | ||||||
| text = "1231" |  | ||||||
| 
 |  | ||||||
| [node name="Label2" type="Label" parent="."] |  | ||||||
| visible = false |  | ||||||
| offset_left = -384.0 |  | ||||||
| offset_top = 120.0 |  | ||||||
| offset_right = -288.0 |  | ||||||
| offset_bottom = 152.0 |  | ||||||
| scale = Vector2(2, 2) |  | ||||||
| text = "1231" |  | ||||||
| 
 |  | ||||||
| [node name="Label3" type="Label" parent="."] |  | ||||||
| visible = false |  | ||||||
| offset_left = -384.0 |  | ||||||
| offset_top = 184.0 |  | ||||||
| offset_right = -288.0 |  | ||||||
| offset_bottom = 216.0 |  | ||||||
| scale = Vector2(2, 2) |  | ||||||
| text = "1231" |  | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Patrick_Pluto
						Patrick_Pluto