Skip to content

Commit

Permalink
fix division by 0 bug, slabset format, grid data window
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Nov 1, 2023
1 parent 7fdabe6 commit a2f43f8
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Scenes/Camera2D.gd
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func reset_camera(x, y):
desired_offset = offset

# Determine the zoom levels required to fit the map's width and height within the viewport
var zoomForWidth = mapWidthInPixels / OS.window_size.x
var zoomForHeight = mapHeightInPixels / OS.window_size.y
var zoomForWidth = mapWidthInPixels / max(1, OS.window_size.x)
var zoomForHeight = mapHeightInPixels / max(1, OS.window_size.y)

# Set the zoom level to the maximum of the two calculated zoom levels to ensure the entire map fits within the viewport
var initialZoom = max(zoomForWidth, zoomForHeight) * Settings.UI_SCALE.y
Expand Down
2 changes: 1 addition & 1 deletion Scenes/ExportPreview.gd
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func set_basic_camera_stuff():
func calculate_zoom():
var terrain_size = Vector3(M.xSize * 3, 8, M.ySize * 3)
# Calculate the window's aspect ratio
var window_aspect_ratio = OS.window_size.x / OS.window_size.y
var window_aspect_ratio = OS.window_size.x / max(1, OS.window_size.y)

# Zoom out based on the dominant dimension
if window_aspect_ratio > 1: # Landscape mode
Expand Down
3 changes: 3 additions & 0 deletions Scenes/GridDataButtongroup.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[gd_resource type="ButtonGroup" format=2]

[resource]
85 changes: 83 additions & 2 deletions Scenes/Main.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=175 format=2]
[gd_scene load_steps=177 format=2]

[ext_resource path="res://Scenes/SlabStyle.gd" type="Script" id=1]
[ext_resource path="res://Scenes/SlabPlacement.gd" type="Script" id=2]
Expand Down Expand Up @@ -153,6 +153,8 @@
[ext_resource path="res://Scenes/ExportPreview.gd" type="Script" id=151]
[ext_resource path="res://Scenes/SpinBoxPropertiesValue.tscn" type="PackedScene" id=152]
[ext_resource path="res://Scenes/ResizeCurrentMapSize.gd" type="Script" id=153]
[ext_resource path="res://Scenes/oAnalyzeGrids.gd" type="Script" id=154]
[ext_resource path="res://Scenes/GridDataButtongroup.tres" type="ButtonGroup" id=155]

[sub_resource type="TileSet" id=1]
0/name = "Wibble_0.png 0"
Expand Down Expand Up @@ -623,6 +625,9 @@ color = Color( 0.172549, 0.164706, 0.196078, 1 )
material = SubResource( 19 )
expand = true
[node name="oAnalyzeGrids" type="Node2D" parent="Game2D"]
script = ExtResource( 154 )
[node name="Ui" type="CanvasLayer" parent="."]
layer = 2
script = ExtResource( 78 )
Expand Down Expand Up @@ -1671,7 +1676,7 @@ custom_colors/font_color_hover = Color( 1, 0.65098, 0.556863, 1 )
custom_colors/font_color_pressed = Color( 0.333333, 0.607843, 1, 1 )
text = "View"
align = 0
items = [ "Map folder", null, 0, false, false, 0, 0, null, "", false, "Script file", null, 0, false, false, 1, 0, null, "", false, "Log file", null, 0, false, false, 2, 0, null, "", false, "", null, 0, false, true, -1, 0, null, "", true, "3D: 1st person", null, 0, false, false, 3, 0, null, "", false ]
items = [ "Map folder", null, 0, false, false, 0, 0, null, "", false, "Script file", null, 0, false, false, 1, 0, null, "", false, "Log file", null, 0, false, false, 2, 0, null, "", false, "", null, 0, false, true, -1, 0, null, "", true, "3D: 1st person", null, 0, false, false, 3, 0, null, "", false, "", null, 0, false, true, -1, 0, null, "", true, "Grid data", null, 0, false, false, 4, 0, null, "", false ]
switch_on_hover = true
__meta__ = {
"_edit_use_anchors_": false
Expand Down Expand Up @@ -5875,6 +5880,82 @@ size_flags_horizontal = 6
size_flags_vertical = 8
text = "Apply"

[node name="GridDataWindow" type="WindowDialog" parent="Ui/UiSystem"]
visible = true
margin_left = 1704.0
margin_top = -2160.0
margin_right = 1985.0
margin_bottom = -1894.0
rect_min_size = Vector2( 281, 266 )
mouse_filter = 1
window_title = "Display grid data"
resizable = true

[node name="MarginContainer" type="MarginContainer" parent="Ui/UiSystem/GridDataWindow"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 1
size_flags_horizontal = 3
size_flags_vertical = 3
custom_constants/margin_right = 20
custom_constants/margin_top = 20
custom_constants/margin_left = 20
custom_constants/margin_bottom = 20

[node name="VBoxContainer" type="VBoxContainer" parent="Ui/UiSystem/GridDataWindow/MarginContainer"]
margin_left = 20.0
margin_top = 20.0
margin_right = 262.0
margin_bottom = 247.0

[node name="GridDataCheckBox1" type="CheckBox" parent="Ui/UiSystem/GridDataWindow/MarginContainer/VBoxContainer"]
margin_right = 242.0
margin_bottom = 29.0
group = ExtResource( 155 )
text = "Slab (.slb)"

[node name="GridDataCheckBox2" type="CheckBox" parent="Ui/UiSystem/GridDataWindow/MarginContainer/VBoxContainer"]
margin_top = 33.0
margin_right = 242.0
margin_bottom = 62.0
group = ExtResource( 155 )
text = "Ownership (.own)"

[node name="GridDataCheckBox3" type="CheckBox" parent="Ui/UiSystem/GridDataWindow/MarginContainer/VBoxContainer"]
margin_top = 66.0
margin_right = 242.0
margin_bottom = 95.0
group = ExtResource( 155 )
text = "Column Positions (.dat)"

[node name="GridDataCheckBox4" type="CheckBox" parent="Ui/UiSystem/GridDataWindow/MarginContainer/VBoxContainer"]
margin_top = 99.0
margin_right = 242.0
margin_bottom = 128.0
group = ExtResource( 155 )
text = "Wibble (.wib)"

[node name="GridDataCheckBox5" type="CheckBox" parent="Ui/UiSystem/GridDataWindow/MarginContainer/VBoxContainer"]
margin_top = 132.0
margin_right = 242.0
margin_bottom = 161.0
group = ExtResource( 155 )
text = "Liquid (.wlb)"

[node name="GridDataCheckBox6" type="CheckBox" parent="Ui/UiSystem/GridDataWindow/MarginContainer/VBoxContainer"]
margin_top = 165.0
margin_right = 242.0
margin_bottom = 194.0
group = ExtResource( 155 )
text = "Style (.slx)"

[node name="GridDataCheckBox7" type="CheckBox" parent="Ui/UiSystem/GridDataWindow/MarginContainer/VBoxContainer"]
margin_top = 198.0
margin_right = 242.0
margin_bottom = 227.0
group = ExtResource( 155 )
text = "Custom Slabs (.une)"

[node name="UiMessages" type="Control" parent="Ui"]
anchor_right = 1.0
anchor_bottom = 1.0
Expand Down
17 changes: 10 additions & 7 deletions Scenes/Menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ onready var oDataLof = Nodelist.list["oDataLof"]
onready var oDkClm = Nodelist.list["oDkClm"]
onready var oExportPreview = Nodelist.list["oExportPreview"]
onready var oResizeCurrentMapSize = Nodelist.list["oResizeCurrentMapSize"]
onready var oGridDataWindow = Nodelist.list["oGridDataWindow"]

var recentlyOpened = []
var recentlyOpenedPopupMenu = PopupMenu.new()
Expand Down Expand Up @@ -248,13 +249,15 @@ func _on_ViewSubmenu_Pressed(pressedID):
oGenerateTerrain.start()
oUi.switch_to_1st_person()
4:
if oEditor.currentView == oEditor.VIEW_2D:
oEditor.set_view_3d()
oGenerateTerrain.start()
oUi.switch_to_3D_overhead()
5:
if oEditor.currentView == oEditor.VIEW_3D:
oEditor.set_view_2d()
Utils.popup_centered(oGridDataWindow)
# 4:
# if oEditor.currentView == oEditor.VIEW_2D:
# oEditor.set_view_3d()
# oGenerateTerrain.start()
# oUi.switch_to_3D_overhead()
# 5:
# if oEditor.currentView == oEditor.VIEW_3D:
# oEditor.set_view_2d()

func _on_MenuButtonSettings_pressed():
oMenuButtonSettings.get_popup().visible = false
Expand Down
2 changes: 1 addition & 1 deletion Scenes/SlabPalette.gd
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func create_cfg_slabset(filePath): #"res://slabset.cfg"
4: beginLine = 'RelativeY'
5: beginLine = 'RelativeZ'
6: beginLine = 'ThingType'
7: beginLine = 'ThingSubtype'
7: beginLine = 'Subtype'
8: beginLine = 'EffectRange'
if z == 1: continue # skip "VariationIndex"

Expand Down
80 changes: 80 additions & 0 deletions Scenes/oAnalyzeGrids.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
extends Node2D

onready var oDataWibble = Nodelist.list["oDataWibble"]
onready var oDataLiquid = Nodelist.list["oDataLiquid"]
onready var oDataSlab = Nodelist.list["oDataSlab"]
onready var oDataOwnership = Nodelist.list["oDataOwnership"]
onready var oDataClmPos = Nodelist.list["oDataClmPos"]
onready var oDataCustomSlab = Nodelist.list["oDataCustomSlab"]
onready var oDataSlx = Nodelist.list["oDataSlx"]
onready var oGridDataCheckBox1 = Nodelist.list["oGridDataCheckBox1"]
onready var oGridDataCheckBox2 = Nodelist.list["oGridDataCheckBox2"]
onready var oGridDataCheckBox3 = Nodelist.list["oGridDataCheckBox3"]
onready var oGridDataCheckBox4 = Nodelist.list["oGridDataCheckBox4"]
onready var oGridDataCheckBox5 = Nodelist.list["oGridDataCheckBox5"]
onready var oGridDataCheckBox6 = Nodelist.list["oGridDataCheckBox6"]
onready var oGridDataCheckBox7 = Nodelist.list["oGridDataCheckBox7"]

onready var tilemap_data = {
"Wibble": {
"extension": ".wib",
"node": oDataWibble
},
"Liquid": {
"extension": ".wlb",
"node": oDataLiquid
},
"Slab": {
"extension": ".slb",
"node": oDataSlab
},
"Ownership": {
"extension": ".own",
"node": oDataOwnership
},
"ColumnPositions": {
"extension": ".dat",
"node": oDataClmPos
},
"CustomSlabs": {
"extension": ".une",
"node": oDataCustomSlab
},
"Style": {
"extension": ".slx",
"node": oDataSlx
}
}

var tileDrawDist = 96 # Example value, adjust as needed
var dynamic_font = DynamicFont.new() # Initialize DynamicFont

func _ready():
dynamic_font.font_data = preload("res://Theme/ClassicConsole.ttf")
dynamic_font.size = 36

oGridDataCheckBox1.connect("pressed", self, "_on_checkbox", ["Slab"])
oGridDataCheckBox2.connect("pressed", self, "_on_checkbox", ["Ownership"])
oGridDataCheckBox3.connect("pressed", self, "_on_checkbox", ["Column Positions"])
oGridDataCheckBox4.connect("pressed", self, "_on_checkbox", ["Wibble"])
oGridDataCheckBox5.connect("pressed", self, "_on_checkbox", ["Liquid"])
oGridDataCheckBox6.connect("pressed", self, "_on_checkbox", ["Style"])
oGridDataCheckBox7.connect("pressed", self, "_on_checkbox", ["Custom Slabs"])

func _on_checkbox(aaa):
print(aaa)

func _draw():
return
if is_instance_valid(oDataWibble) == false: return

var node = tilemap_data["Slab"]["node"]

for x in range(M.xSize):
for y in range(M.ySize):
var value = node.get_cell(x,y)
var string = str(value)
var pos = Vector2(x * tileDrawDist, y * tileDrawDist) + Vector2(tileDrawDist * 0.5, tileDrawDist * 0.5)
pos.x -= dynamic_font.get_string_size(string).x * 0.5 # Center string
pos.y += dynamic_font.get_string_size(string).y * 0.25
draw_string(dynamic_font, pos, string, Color(1, 1, 1, 1))

0 comments on commit a2f43f8

Please sign in to comment.