Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3082617
Showing
35 changed files
with
2,412 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Godot-specific ignores | ||
.import/ | ||
export.cfg | ||
export_presets.cfg | ||
|
||
# Imported translations (automatically generated from CSV files) | ||
*.translation | ||
|
||
# Mono-specific ignores | ||
.mono/ | ||
data_*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
extends Node | ||
|
||
var cam | ||
var gizmo | ||
var menu_cityobj_selected | ||
|
||
var selected_cityobj: Spatial | ||
|
||
func _ready(): | ||
get_tree().connect("files_dropped", self, "_on_files_dropped") | ||
|
||
func _unhandled_input(event): | ||
if event is InputEventMouseButton: | ||
if event.button_index == BUTTON_LEFT and event.is_pressed(): | ||
_unselect_cityobj() | ||
|
||
func _on_files_dropped(files, _screen): | ||
if len(files) != 1: | ||
print("One file at a time!") | ||
return | ||
var filepath = files[0] | ||
ChunkHandler.LoadChunk(filepath) | ||
|
||
func _select_cityobj(obj: Spatial): | ||
if menu_cityobj_selected: | ||
_unselect_cityobj() | ||
selected_cityobj = obj | ||
selected_cityobj._set_highlight(true) | ||
gizmo.translation = selected_cityobj.translation | ||
|
||
menu_cityobj_selected._select(obj) | ||
menu_cityobj_selected.show() | ||
|
||
func _unselect_cityobj(): | ||
if menu_cityobj_selected: | ||
if selected_cityobj: | ||
selected_cityobj._set_highlight(false) | ||
selected_cityobj = null | ||
menu_cityobj_selected.hide() | ||
|
||
func _save(): | ||
ChunkHandler.SaveChunk() | ||
|
||
func _clear(): | ||
ChunkHandler.ClearChunk() | ||
get_tree().reload_current_scene() | ||
|
||
func _process(_delta): | ||
if gizmo: | ||
if selected_cityobj: | ||
gizmo.show() | ||
gizmo.scale = Vector3.ONE * cam.get_node("pivot").get_node("cam").transform.origin.z * .2 | ||
|
||
gizmo.translation = selected_cityobj.translation | ||
|
||
else: | ||
gizmo.hide() | ||
|
||
# Input | ||
# Focus on selected | ||
if Input.is_key_pressed(KEY_F): | ||
if selected_cityobj: | ||
cam.translation = selected_cityobj.translation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
using Godot; | ||
using System; | ||
using System.IO; | ||
|
||
public class ChunkHandler : Node | ||
{ | ||
ChunkLoader chunkLoader; | ||
ChunkUnloader chunkUnloader; | ||
|
||
CPUChunk loadedChunk; | ||
string loadedChunkPath; | ||
|
||
public override void _Ready() | ||
{ | ||
chunkLoader = GetNode("/root/ChunkLoader") as ChunkLoader; | ||
chunkUnloader = new ChunkUnloader(); | ||
} | ||
|
||
public void ClearChunk() | ||
{ | ||
loadedChunk = null; | ||
} | ||
|
||
public void LoadChunk(string input_filepath) | ||
{ | ||
string cpu_chunk_filepath = ""; | ||
string gpu_chunk_filepath = ""; | ||
// string peg_filepath; | ||
|
||
GD.Print(input_filepath); | ||
|
||
// File Exist | ||
if (!System.IO.File.Exists(input_filepath)) | ||
{ | ||
GD.Print("Error: Input File Doesn't Exist! " + input_filepath); | ||
return; | ||
} | ||
|
||
// File Extension | ||
if (System.IO.Path.GetExtension(input_filepath) == ".chunk_pc") | ||
{ | ||
cpu_chunk_filepath = input_filepath; | ||
gpu_chunk_filepath = System.IO.Path.ChangeExtension(input_filepath, ".g_chunk_pc"); | ||
} | ||
else if (System.IO.Path.GetExtension(input_filepath) == ".g_chunk_pc") | ||
{ | ||
cpu_chunk_filepath = System.IO.Path.ChangeExtension(input_filepath, ".chunk_pc"); | ||
gpu_chunk_filepath = input_filepath; | ||
} | ||
else if (System.IO.Path.GetExtension(input_filepath) == ".g_peg_pc") | ||
{ | ||
cpu_chunk_filepath = System.IO.Path.ChangeExtension(input_filepath, ".chunk_pc"); | ||
gpu_chunk_filepath = System.IO.Path.ChangeExtension(input_filepath, ".g_chunk_pc"); | ||
} | ||
else | ||
{ | ||
GD.Print("Error: Unknown extension!"); | ||
return; | ||
} | ||
|
||
// Chunkfile Exist | ||
if (!System.IO.File.Exists(cpu_chunk_filepath)) | ||
{ | ||
GD.Print("Error: " + cpu_chunk_filepath + " doesn't exist!"); | ||
return; | ||
} | ||
if (!System.IO.File.Exists(gpu_chunk_filepath)) | ||
{ | ||
GD.Print("Error: " + gpu_chunk_filepath + " doesn't exist!"); | ||
return; | ||
} | ||
|
||
loadedChunk = chunkLoader.LoadChunk(cpu_chunk_filepath); | ||
loadedChunkPath = cpu_chunk_filepath; | ||
if (loadedChunk != null) | ||
{ | ||
chunkLoader.LoadGPUChunk(loadedChunk, gpu_chunk_filepath); | ||
ImportChunkToScene(loadedChunk); | ||
} | ||
else | ||
{ | ||
GD.PushWarning("ChunkLoader returned null."); | ||
} | ||
} | ||
|
||
public void ImportChunkToScene(CPUChunk chunk) | ||
{ | ||
Node world = GetNode("/root/main/chunk/cityobjects"); | ||
for (int i = 0; i < chunk.cityObjectCount; i++) | ||
{ | ||
CityObject cityObject = chunk.cityObjects[i]; | ||
uint partId = cityObject.cityObjectPart; | ||
CityObjectPart temp = chunk.cityObjectParts[partId]; | ||
|
||
Spatial cityObjectNode = new Spatial(); | ||
cityObjectNode.SetScript(ResourceLoader.Load("res://scenes/editor/scripts/cityobject.gd")); | ||
cityObjectNode.Translation = temp.pos; | ||
cityObjectNode.Name = cityObject.name; | ||
cityObjectNode.Set("rendermodel_id", temp.model); | ||
cityObjectNode.Set("cityobjpart_id", partId); | ||
|
||
world.AddChild(cityObjectNode); | ||
} | ||
Spatial camera = (Spatial)GetNode("/root/main/editor/cameraman"); | ||
camera.Translation = chunk.cityObjectParts[0].pos; | ||
} | ||
|
||
public void SaveChunk() | ||
{ | ||
// Get cityobject data from nodes | ||
Node cityObjContainer = GetNode("/root/main/chunk/cityobjects"); | ||
for (int i = 0; i < cityObjContainer.GetChildCount(); i++) | ||
{ | ||
Spatial cityObjNode = cityObjContainer.GetChild(i) as Spatial; | ||
uint model = (uint)(int)cityObjNode.Get("rendermodel_id"); | ||
Vector3 pos = cityObjNode.Translation; | ||
|
||
uint partid = loadedChunk.cityObjects[i].cityObjectPart; | ||
loadedChunk.cityObjectParts[partid].pos = pos; | ||
loadedChunk.cityObjectParts[partid].model = model; | ||
} | ||
|
||
string newChunkPath = System.IO.Path.ChangeExtension(loadedChunkPath, "_new.chunk_pc"); | ||
if (System.IO.File.Exists(newChunkPath)) | ||
{ | ||
System.IO.File.Delete(newChunkPath); | ||
} | ||
System.IO.File.Copy(loadedChunkPath, newChunkPath); | ||
chunkUnloader.PatchChunk(loadedChunk, newChunkPath); | ||
|
||
} | ||
} |
Oops, something went wrong.