Skip to content

Commit

Permalink
Merge pull request #8 from PieterVdc/add-players
Browse files Browse the repository at this point in the history
add extra players
  • Loading branch information
rainlizard authored Apr 30, 2024
2 parents b43f89d + 149a36e commit 4f89793
Show file tree
Hide file tree
Showing 282 changed files with 3,074 additions and 322 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ custom_slabs.cfg
custom_objects.cfg

unearthdata/tmapa0*
unearthdata/tmapb0*
textures

### Godot ###
Expand Down
9 changes: 5 additions & 4 deletions Autoload/Constants.gd
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
extends Node
const TILE_SIZE = 96
const SUBTILE_SIZE = 32

const ownerFloorCol = [Color8(132,44,0,255), Color8(136,112,148,255), Color8(52,92,4,255), Color8(188,156,0,255), Color8(207,207,207,255), Color8(52,36,4,255)] #Color8(180,160,124,255)
const ownerRoomCol = [Color8(156,48,0,255), Color8(160,136,180,255), Color8(56,112,12,255), Color8(228,212,0,255), Color8(242,242,242,255), Color8(0,0,0,0)] #Color8(188,168,132,255)
const ownershipNames = ["Red","Blue","Green","Yellow","White","None"]
const PLAYERS_COUNT = 9
# red blue green yellow white neutral Purple Black Orange
const ownerFloorCol = [Color8(132,44,0,255), Color8(136,112,148,255), Color8(52, 92, 4,255), Color8(188,156,0,255), Color8(207,207,207,255), Color8(52,36,4,255), Color8(171, 80,120,255), Color8(32,32,32,255), Color8(188,108,53,255)] #Color8(180,160,124,255)
const ownerRoomCol = [Color8(156,48,0,255), Color8(160,136,180,255), Color8(56,112,12,255), Color8(228,212,0,255), Color8(242,242,242,255), Color8(0,0,0,0), Color8(200,104,164,255), Color8(1,1,1,255), Color8(211,132,72,255)] #Color8(188,168,132,255)
const ownershipNames = ["Red","Blue","Green","Yellow","White","None","Purple","Black","Orange"]

const listOrientations = [
0, # ANGLE_NORTH
Expand Down
16 changes: 8 additions & 8 deletions Autoload/Cube.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ enum {
NONE = 5
}
const ownedCube = {
"FloorMarker" : [192,193,194,195,199,198],
"WallMarker" : [67,68,69,70,71,4],
"PortalMarker" : [382,422,423,424,426,425],
"HeartMarker" : [382,422,423,424,426,425],
"BarracksFlag" : [393,427,428,429,431,430],
"BannerLeft" : [160,410,413,416,419,77],
"BannerMiddle" : [161,411,414,417,420,77],
"BannerRight" : [162,412,415,418,421,77],
"FloorMarker" : [192,193,194,195,199,198,455,462,469],
"WallMarker" : [67, 68, 69, 70, 71, 448,454,461,468],
"PortalMarker" : [382,422,423,424,426,425,452,459,466],
"HeartMarker" : [382,422,423,424,426,425,452,459,466],
"BarracksFlag" : [393,427,428,429,431,430,453,460,467],
"BannerLeft" : [160,410,413,416,419,445,449,456,463],
"BannerMiddle" : [161,411,414,417,420,446,450,457,464],
"BannerRight" : [162,412,415,418,421,447,451,458,465],
}

const rngCube = {
Expand Down
8 changes: 8 additions & 0 deletions Autoload/Things.gd
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ var DATA_OBJECT = {
134 : ["Armageddon", null,null, preload("res://dk_images/keepower_64/armagedn_std.png"), null, TAB_SPELL],
135 : ["Possess", null,null, preload("res://dk_images/keepower_64/possess_std.png"), null, TAB_SPELL],
136 : ["Gold Bag (100)", null,null, preload("res://dk_images/valuables/gold_sack_tp/r1frame01.png"), null, TAB_GOLD],
161 : ["White Flag", null,null, preload("res://dk_images/furniture/flagpole_whiteflag_tp/AnimFlagpoleWhite.tres"), null, TAB_FURNITURE],
162 : ["White Heart Flame", null,null, preload("res://edited_images/heartflames/heartflame_white/AnimWhiteHeartFlame.tres"), null, TAB_FURNITURE],
164 : ["Purple Flag", null,null, preload("res://dk_images/furniture/flagpole_purpleflag_tp/AnimFlagpolePurple.tres"), null, TAB_FURNITURE],
165 : ["Purple Heart Flame", null,null, preload("res://edited_images/heartflames/heartflame_purple/AnimPurpleHeartFlame.tres"), null, TAB_FURNITURE],
166 : ["Black Flag", null,null, preload("res://dk_images/furniture/flagpole_blackflag_tp/AnimFlagpoleBlack.tres"), null, TAB_FURNITURE],
167 : ["Black Heart Flame", null,null, preload("res://edited_images/heartflames/heartflame_black/AnimBlackHeartFlame.tres"), null, TAB_FURNITURE],
168 : ["Orange Flag", null,null, preload("res://dk_images/furniture/flagpole_orangeflag_tp/AnimFlagpoleOrange.tres"), null, TAB_FURNITURE],
169 : ["Orange Heart Flame", null,null, preload("res://edited_images/heartflames/heartflame_orange/AnimOrangeHeartFlame.tres"), null, TAB_FURNITURE],
}

var LIST_OF_BOXES = {
Expand Down
2 changes: 1 addition & 1 deletion Autoload/Version.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extends Node

var major_minor = "0.44"
var major_minor = "0.45"
var patch = "0000"
var full = ""
var unearth_map_format_version:float = 1.05
Expand Down
119 changes: 79 additions & 40 deletions Scenes/CurrentTextures.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ onready var oColumnEditorVoxelView = Nodelist.list["oColumnEditorVoxelView"]
onready var oMapProperties = Nodelist.list["oMapProperties"]

const IMAGE_FORMAT = Image.FORMAT_RGB8
const textureWidth = 256
const textureHeight = 2176

enum {
LOADING_NOT_STARTED
LOADING_IN_PROGRESS
Expand All @@ -45,6 +44,7 @@ func _notification(what: int):
yield(get_tree(),'idle_frame')
oMapProperties._on_MapProperties_visibility_changed() # Refresh list of styles if it's visible


func _on_ReloadTextureMapsButton_pressed():
if texturesLoadedState != LOADING_IN_PROGRESS: # Don't do anything if it's already doing something
oMessage.quick("Reloading tilesets")
Expand Down Expand Up @@ -96,6 +96,7 @@ func start():
if oDataSlab.get_cell(0,0) != -1:
set_current_texture_pack()


func scan_dk_data_directory():
var path = oGame.DK_DATA_DIRECTORY
var dictionary = {}
Expand All @@ -105,7 +106,7 @@ func scan_dk_data_directory():
var fileName = dir.get_next()
while fileName != "":
if dir.current_is_dir() == false:
if fileName.to_upper().begins_with("TMAPA") == true: # Get file regardless of case (case insensitive)
if fileName.to_upper().begins_with("TMAP") == true: # Get file regardless of case (case insensitive)
if fileName.to_upper().get_extension() == "DAT":
if fileName.to_upper().begins_with("TMAPANIM") == false:
var getModifiedTime = File.new().get_modified_time(path.plus_file(fileName))
Expand All @@ -121,25 +122,33 @@ func convert_tmapa_to_image(tmapaDatPath):
var file = File.new()
if file.open(tmapaDatPath, File.READ) == OK:
CODETIME_START = OS.get_ticks_msec()
var imageSize = file.get_len() # (Width * Height)

var img = Image.new()
img.create(textureWidth, textureHeight, false, IMAGE_FORMAT)
file.seek(0)
img.lock()
for y in textureHeight:
for x in textureWidth:
var paletteIndex = file.get_8()
img.set_pixel(x,y,paletteData[paletteIndex])
img.unlock()

print('Converted tmapa*.dat to image in: '+str(OS.get_ticks_msec()-CODETIME_START)+'ms')
var dkTextureData = file.get_buffer(imageSize)
file.close()

var data = PoolByteArray()
data.resize(256 * 2176 * 3)
data.fill(0) # Any space that goes beyond the size of tmapb will be set to black

var idx = 0
for i in imageSize:
var color = paletteData[dkTextureData[i]]
data[idx] = color.r8
data[idx + 1] = color.g8
data[idx + 2] = color.b8
idx += 3

var img = Image.new()
img.create_from_data(256, 2176, false, IMAGE_FORMAT, data)

print("Converted " + str(tmapaDatPath.get_file()) + " to image in: " + str(OS.get_ticks_msec() - CODETIME_START) + "ms")
return img
else:
print("Failed to open file.")
return null


func save_image_as_png(img, inputPath):
var fileName = inputPath.get_file().get_basename().to_lower() + ".png"

Expand All @@ -152,57 +161,77 @@ func save_image_as_png(img, inputPath):

func load_cache_filename(path):
var fileName = path.get_file().get_basename().to_lower()
var cachePath = Settings.unearthdata.plus_file(fileName + ".png")

if(fileName.to_lower().find("tmapa") == -1):
return

var cachePathtmapa = Settings.unearthdata.plus_file(fileName + ".png")
var cachePathtmapb = Settings.unearthdata.plus_file(fileName.replace("tmapa","tmapb") + ".png")
var tmapaNumber = int(fileName.to_lower().trim_prefix("tmapa")) # Get the specific position to create within the array
if File.new().file_exists(cachePath) == true:

if File.new().file_exists(cachePathtmapa) == true:
# Need to call load() on an Image class if I want the save and load to work correctly (otherwise it saves too fast and doesn't load or something)
var img = Image.new()
img.load(cachePath)
load_image_into_cache(img, tmapaNumber)
var imgA = Image.new()
imgA.load(cachePathtmapa)
var imgB = Image.new()
imgB.load(cachePathtmapb)
load_image_into_cache(imgA, imgB, tmapaNumber)
#print('Loaded cache file: ' + cachePath)
return OK
else:
print('Cache file not found: ' + cachePath)
print('Cache file not found: ' + cachePathtmapa)
cachedTextures.clear()
return FAILED

func load_image_into_cache(img, tmapaNumber):

func load_image_into_cache(imgA, imgB, tmapaNumber):
tmapaNumber = int(tmapaNumber)
while cachedTextures.size() <= tmapaNumber: # Fill all array positions, in case a tmapa00#.dat file inbetween is deleted
cachedTextures.append([null, null])
cachedTextures[tmapaNumber] = convert_img_to_two_texture_arrays(img)
cachedTextures[tmapaNumber] = convert_img_to_two_texture_arrays(imgA,imgB)


# SLICE COUNT being too high is the reason TextureArray doesn't work on old PC. (NOT IMAGE SIZE, NOT MIPMAPS EITHER)
# RES files might actually take longer to generate a TextureArray from than PNG, not sure.
func convert_img_to_two_texture_arrays(img):
if img.get_format() != IMAGE_FORMAT:
img.convert(IMAGE_FORMAT)

func convert_img_to_two_texture_arrays(imgA,imgB):
if imgA.get_format() != IMAGE_FORMAT:
imgA.convert(IMAGE_FORMAT)
if imgB.get_format() != IMAGE_FORMAT:
imgB.convert(IMAGE_FORMAT)

var twoTextureArrays = [
TextureArray.new(),
TextureArray.new(),
TextureArray.new(),
TextureArray.new(),
]
var xSlices = 8
var ySlices = 34
var sliceWidth = 32 #img.get_width() / xSlices;
var sliceHeight = 32 #img.get_height() / ySlices;
twoTextureArrays[0].create(sliceWidth, sliceHeight, xSlices*ySlices, IMAGE_FORMAT, TextureLayered.FLAG_MIPMAPS+TextureLayered.FLAG_ANISOTROPIC_FILTER)
twoTextureArrays[1].create(sliceWidth, sliceHeight, xSlices*ySlices, IMAGE_FORMAT, TextureLayered.FLAG_MIPMAPS+TextureLayered.FLAG_ANISOTROPIC_FILTER)
twoTextureArrays[2].create(sliceWidth, sliceHeight, xSlices*ySlices, IMAGE_FORMAT, TextureLayered.FLAG_MIPMAPS+TextureLayered.FLAG_ANISOTROPIC_FILTER)
twoTextureArrays[3].create(sliceWidth, sliceHeight, xSlices*ySlices, IMAGE_FORMAT, TextureLayered.FLAG_MIPMAPS+TextureLayered.FLAG_ANISOTROPIC_FILTER)

for i in 2:
for i in 4:
var yOffset = 0
if i == 1:
if i == 1 or i == 3:
yOffset = 34

for y in ySlices:
for x in xSlices:
var slice = img.get_rect(Rect2(x*sliceWidth, (y+yOffset)*sliceHeight, sliceWidth, sliceHeight))
var slice
if i < 2:
slice = imgA.get_rect(Rect2(x*sliceWidth, (y+yOffset)*sliceHeight, sliceWidth, sliceHeight))
else:
slice = imgB.get_rect(Rect2(x*sliceWidth, (y+yOffset)*sliceHeight, sliceWidth, sliceHeight))
slice.generate_mipmaps() #Important otherwise it's black when zoomed out
twoTextureArrays[i].set_layer_data(slice, (y*xSlices)+x)

return twoTextureArrays


func set_current_texture_pack():
var value = oDataLevelStyle.data

Expand All @@ -215,29 +244,39 @@ func set_current_texture_pack():

# 2D
if oOverheadGraphics.arrayOfColorRects.size() > 0:
oOverheadGraphics.arrayOfColorRects[0].get_material().set_shader_param("dkTextureMap_Split_A", cachedTextures[value][0])
oOverheadGraphics.arrayOfColorRects[0].get_material().set_shader_param("dkTextureMap_Split_B", cachedTextures[value][1])
oOverheadGraphics.arrayOfColorRects[0].get_material().set_shader_param("dkTextureMap_Split_A1", cachedTextures[value][0])
oOverheadGraphics.arrayOfColorRects[0].get_material().set_shader_param("dkTextureMap_Split_A2", cachedTextures[value][1])
oOverheadGraphics.arrayOfColorRects[0].get_material().set_shader_param("dkTextureMap_Split_B1", cachedTextures[value][2])
oOverheadGraphics.arrayOfColorRects[0].get_material().set_shader_param("dkTextureMap_Split_B2", cachedTextures[value][3])

# 3D
if oGame3D.materialArray.size() > 0:
oGame3D.materialArray[0].set_shader_param("dkTextureMap_Split_A", cachedTextures[value][0])
oGame3D.materialArray[0].set_shader_param("dkTextureMap_Split_B", cachedTextures[value][1])
oGame3D.materialArray[0].set_shader_param("dkTextureMap_Split_A1", cachedTextures[value][0])
oGame3D.materialArray[0].set_shader_param("dkTextureMap_Split_A2", cachedTextures[value][1])
oGame3D.materialArray[0].set_shader_param("dkTextureMap_Split_B1", cachedTextures[value][2])
oGame3D.materialArray[0].set_shader_param("dkTextureMap_Split_B2", cachedTextures[value][3])

for nodeID in get_tree().get_nodes_in_group("VoxelViewer"):
if nodeID.oAllVoxelObjects.mesh != null:
nodeID.oAllVoxelObjects.mesh.surface_get_material(0).set_shader_param("dkTextureMap_Split_A", cachedTextures[value][0])
nodeID.oAllVoxelObjects.mesh.surface_get_material(0).set_shader_param("dkTextureMap_Split_B", cachedTextures[value][1])
nodeID.oAllVoxelObjects.mesh.surface_get_material(0).set_shader_param("dkTextureMap_Split_A1", cachedTextures[value][0])
nodeID.oAllVoxelObjects.mesh.surface_get_material(0).set_shader_param("dkTextureMap_Split_A2", cachedTextures[value][1])
nodeID.oAllVoxelObjects.mesh.surface_get_material(0).set_shader_param("dkTextureMap_Split_B1", cachedTextures[value][2])
nodeID.oAllVoxelObjects.mesh.surface_get_material(0).set_shader_param("dkTextureMap_Split_B2", cachedTextures[value][3])
if nodeID.oSelectedVoxelObject.mesh != null:
nodeID.oSelectedVoxelObject.mesh.surface_get_material(0).set_shader_param("dkTextureMap_Split_A", cachedTextures[value][0])
nodeID.oSelectedVoxelObject.mesh.surface_get_material(0).set_shader_param("dkTextureMap_Split_B", cachedTextures[value][1])
nodeID.oSelectedVoxelObject.mesh.surface_get_material(0).set_shader_param("dkTextureMap_Split_A1", cachedTextures[value][0])
nodeID.oSelectedVoxelObject.mesh.surface_get_material(0).set_shader_param("dkTextureMap_Split_A2", cachedTextures[value][1])
nodeID.oSelectedVoxelObject.mesh.surface_get_material(0).set_shader_param("dkTextureMap_Split_B1", cachedTextures[value][2])
nodeID.oSelectedVoxelObject.mesh.surface_get_material(0).set_shader_param("dkTextureMap_Split_B2", cachedTextures[value][3])

assign_textures_to_slab_window(value)


func assign_textures_to_slab_window(value): # Called by SlabStyleWindow
for nodeID in get_tree().get_nodes_in_group("SlabDisplay"):
nodeID.get_material().set_shader_param("dkTextureMap_Split_A", cachedTextures[value][0])
nodeID.get_material().set_shader_param("dkTextureMap_Split_B", cachedTextures[value][1])
nodeID.get_material().set_shader_param("dkTextureMap_Split_A1", cachedTextures[value][0])
nodeID.get_material().set_shader_param("dkTextureMap_Split_A2", cachedTextures[value][1])
nodeID.get_material().set_shader_param("dkTextureMap_Split_B1", cachedTextures[value][2])
nodeID.get_material().set_shader_param("dkTextureMap_Split_B2", cachedTextures[value][3])



Expand Down
6 changes: 4 additions & 2 deletions Scenes/GenerateTerrainOLD.gd
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,10 @@ func create_surface_materials():

var mat = ShaderMaterial.new()
mat.shader = preload("res://Shaders/display_texture_3d.shader")
mat.set_shader_param("dkTextureMap_Split_A", oTextureCache.cachedTextures[map][0])
mat.set_shader_param("dkTextureMap_Split_B", oTextureCache.cachedTextures[map][1])
mat.set_shader_param("dkTextureMap_Split_A1", oTextureCache.cachedTextures[map][0])
mat.set_shader_param("dkTextureMap_Split_A2", oTextureCache.cachedTextures[map][1])
mat.set_shader_param("dkTextureMap_Split_B1", oTextureCache.cachedTextures[map][2])
mat.set_shader_param("dkTextureMap_Split_B2", oTextureCache.cachedTextures[map][3])
mat.set_shader_param("animationDatabase", preload("res://Shaders/textureanimationdatabase.png"))

materialArray.append(mat)
Expand Down
45 changes: 45 additions & 0 deletions Scenes/GenericGridItem.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
extends PanelContainer

signal pressed

var img_normal setget set_image_normal
var img_pressed
var img_hover
var img_margin = 0
var orig_backcol

func _ready():
if img_normal:
$TextureRect.texture = img_normal
orig_backcol = get_stylebox("panel").bg_color


get_stylebox("panel").content_margin_left = img_margin
get_stylebox("panel").content_margin_right = img_margin
get_stylebox("panel").content_margin_top = img_margin
get_stylebox("panel").content_margin_bottom = img_margin

func _on_GenericGridItem_mouse_entered():
if img_hover:
$TextureRect.texture = img_hover

get_stylebox("panel").bg_color = orig_backcol * 1.25

func _on_GenericGridItem_mouse_exited():
if img_normal:
$TextureRect.texture = img_normal

get_stylebox("panel").bg_color = orig_backcol

func _on_GenericGridItem_gui_input(event):
if event is InputEventMouseButton:
if event.pressed and event.button_index == BUTTON_LEFT:
if img_pressed:
$TextureRect.texture = img_pressed
emit_signal("pressed")
else:
$TextureRect.texture = img_normal

func set_image_normal(setVal):
$TextureRect.texture = setVal
img_normal = setVal
41 changes: 35 additions & 6 deletions Scenes/GenericGridItem.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
[gd_scene format=2]
[gd_scene load_steps=3 format=2]

[node name="GenericGridItem" type="TextureButton"]
anchor_right = 1.0
anchor_bottom = 1.0
focus_mode = 0
[ext_resource path="res://Scenes/GenericGridItem.gd" type="Script" id=1]

[sub_resource type="StyleBoxFlat" id=1]
resource_local_to_scene = true
content_margin_left = 0.0
content_margin_right = 0.0
content_margin_top = 0.0
content_margin_bottom = 0.0
bg_color = Color( 0.20976, 0.1932, 0.23, 1 )
border_width_left = 1
border_width_top = 1
border_width_right = 1
border_width_bottom = 1
border_color = Color( 1, 1, 1, 0.25098 )
shadow_color = Color( 0.117647, 0.113725, 0.133333, 1 )
shadow_size = 1
shadow_offset = Vector2( 8, 8 )

[node name="GenericGridItem" type="PanelContainer"]
mouse_filter = 1
size_flags_horizontal = 3
size_flags_vertical = 3
custom_styles/panel = SubResource( 1 )
script = ExtResource( 1 )

[node name="TextureRect" type="TextureRect" parent="."]
mouse_filter = 2
size_flags_horizontal = 3
size_flags_vertical = 3
expand = true
stretch_mode = 5
stretch_mode = 6

[connection signal="gui_input" from="." to="." method="_on_GenericGridItem_gui_input"]
[connection signal="mouse_entered" from="." to="." method="_on_GenericGridItem_mouse_entered"]
[connection signal="mouse_exited" from="." to="." method="_on_GenericGridItem_mouse_exited"]
Loading

0 comments on commit 4f89793

Please sign in to comment.