Skip to content

Commit

Permalink
midas door and darkened bedrock
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Jan 26, 2025
1 parent cd145eb commit 2843b60
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Autoload/Names.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const things = {
"STEEL" : "Iron Door",
"MAGIC" : "Magic Door",
"SECRET" : "Secret Door",
"MIDAS" : "Midas Door",
},
TYPE.TRAP : {
"BOULDER" : "Boulder Trap",
Expand Down Expand Up @@ -327,6 +328,8 @@ const slabs = {
"PURPLE_PATH": "Purple Path",
"DOOR_SECRET" : "Secret Door",
"DOOR_SECRET2" : "Secret Door",
"DOOR_MIDAS" : "Midas Door",
"DOOR_MIDAS2" : "Midas Door",
"HARD_FLOOR" : "Bedrock",
"AUTOMATIC_WALL" : "Wall Automatic",
};
2 changes: 2 additions & 0 deletions Autoload/Slabs.gd
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ var icons = {
"HEART_PEDESTAL": preload("res://dk_images/crucials/anim0949/r1frame01.png"),
"DOOR_SECRET": preload("res://extra_images/secret_door.png"),
"DOOR_SECRET2": preload("res://extra_images/secret_door.png"),
"DOOR_MIDAS": preload("res://extra_images/midas_door.png"),
"DOOR_MIDAS2": preload("res://extra_images/midas_door.png"),
}

var slabOrder = [
Expand Down
2 changes: 2 additions & 0 deletions Scenes/CustomTooltip.gd
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func set_floortexture(floorTextureValue):

oTooltipPic.material.set_shader_param("showOnlySpecificStyle", 0)
oTooltipPic.material.set_shader_param("slxData", preload("res://Shaders/Black3x3.png"))
#oTooltipPic.material.set_shader_param("slabIdData", preload("res://Shaders/Bedrock3x3.png"))
oTooltipPic.material.set_shader_param("slabIdData", preload("res://Shaders/Black3x3.png"))
oTooltipPic.material.set_shader_param("fieldSizeInSubtiles", Vector2(1, 1))
oTooltipPic.material.set_shader_param("animationDatabase", preload("res://Shaders/textureanimationdatabase.png"))
oTooltipPic.material.set_shader_param("viewTextures", dataTexture)
136 changes: 135 additions & 1 deletion Scenes/DataSlab.gd
Original file line number Diff line number Diff line change
@@ -1 +1,135 @@
extends Grid
extends Node

const U8 = 1
const U16 = 2

var buffer = StreamPeerBuffer.new()
var bytes_per_entry = 1
var width = 0
var height = 0
var buffer_size = 0

var idImgData = Image.new()
var idTexData = ImageTexture.new()

#func _input(event):
# if event is InputEventKey and event.pressed and event.scancode == KEY_F11:
# var filename = "a.png"
# var err = idImgData.save_png(filename)
# if err == OK:
# print("Saved slab ID debug image to: ", filename)
# else:
# print("Failed to save slab ID debug image, error: ", err)

func initialize(w, h, fillValue, setPerEntryBytes):
# Initialize the grid
width = w
height = h
bytes_per_entry = setPerEntryBytes
buffer_size = width * height * bytes_per_entry

# Clearing a buffer is troublesome, in order to do so I need to set the buffer to an equal-sized blank PoolByteArray. (this takes 0ms)
var blankByteArray = PoolByteArray([])
blankByteArray.resize(buffer_size)
blankByteArray.fill(fillValue)
buffer.data_array = blankByteArray

func initialize_img():
# Initialize the image
idImgData.create(width, height, false, idImgData.FORMAT_RGB8)
idImgData.lock()

# Load buffer data into image
for y in range(height):
for x in range(width):
var value = get_cell(x, y)
idImgData.set_pixel(x, y, Color8(value, value, value))

idImgData.unlock()
idTexData.create_from_image(idImgData)

func set_cellv(pos, value):
set_cell(pos.x, pos.y, value)

func set_cell(x, y, value):
# Update grid
var seek_pos = (y * width + x) * bytes_per_entry
if seek_pos >= 0 and seek_pos < buffer_size:
buffer.seek(seek_pos)
if bytes_per_entry == U8:
buffer.put_u8(value)
elif bytes_per_entry == U16:
buffer.put_u16(value)

# Update idImgData
if x >= 0 and x < width and y >= 0 and y < height:
idImgData.lock()
idImgData.set_pixel(x, y, Color8(value, value, value))
idImgData.unlock()
idTexData.create_from_image(idImgData)

func get_cell(x, y):
var seek_pos = (y * width + x) * bytes_per_entry
if seek_pos >= 0 and seek_pos < buffer_size:
buffer.seek(seek_pos)
if bytes_per_entry == U8:
return buffer.get_u8()
elif bytes_per_entry == U16:
return buffer.get_u16()
return -1

func get_cellv(pos):
return get_cell(pos.x, pos.y)


func resize(new_width, new_height, fillValue):
# Resize grid
var new_buffer_size = new_width * new_height * bytes_per_entry
var new_buffer = StreamPeerBuffer.new()
var new_data_array = PoolByteArray([])
new_data_array.resize(new_buffer_size)
new_data_array.fill(fillValue)
new_buffer.data_array = new_data_array

var copy_width = min(width, new_width)
var copy_height = min(height, new_height)

# This is necessary for the strangely sized data structures that are like: Vector2((width*3)+1,(height*3)+1)
match name:
"DataOwnership", "DataClmPos", "DataWibble":
copy_width -= 1
copy_height -= 1

for y in range(copy_height):
for x in range(copy_width):
var old_value = get_cell(x, y)
var new_seek_pos = (y * new_width + x) * bytes_per_entry
new_buffer.seek(new_seek_pos)
if bytes_per_entry == U8:
new_buffer.put_u8(old_value)
elif bytes_per_entry == U16:
new_buffer.put_u16(old_value)

width = new_width
height = new_height
buffer_size = new_buffer_size
buffer = new_buffer

# Resize image
var new_image = Image.new()
new_image.create(new_width, new_height, false, idImgData.FORMAT_RGB8)
new_image.fill(Color8(fillValue, fillValue, fillValue))

# Copy old image data
new_image.lock()
idImgData.lock()
var copy_widthi = min(width, new_width)
var copy_heighti = min(height, new_height)
for y in range(copy_heighti):
for x in range(copy_widthi):
new_image.set_pixel(x, y, idImgData.get_pixel(x, y))
idImgData.unlock()
new_image.unlock()

idImgData = new_image
idTexData.create_from_image(idImgData)
2 changes: 1 addition & 1 deletion Scenes/OpenMap.gd
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func start():
#for i in 200:
# yield(get_tree(), "idle_frame")
#oCurrentMap.clear_map()
open_map("C:/Games/Dungeon Keeper/levels/personal/map00002.slb")
open_map("C:/Games/Dungeon Keeper/levels/personal/map00001.slb")
#open_map("D:/Dungeon Keeper/campgns/dpthshdw/map00014.slb")
else:
# initialize a cleared map
Expand Down
1 change: 1 addition & 0 deletions Scenes/OverheadGraphics.gd
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func createDisplayField(setMap, showStyle):
mat.set_shader_param("animationDatabase", preload("res://Shaders/textureanimationdatabase.png"))
mat.set_shader_param("viewTextures", overheadTexData)
mat.set_shader_param("slxData", oDataSlx.slxTexData)
mat.set_shader_param("slabIdData", oDataSlab.idTexData)

arrayOfColorRects.append(displayField)
oGame2D.add_child_below_node(self, displayField)
Expand Down
2 changes: 2 additions & 0 deletions Scenes/ReadData.gd
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,11 @@ func new_txt():
func read_slb(buffer):
oDataSlab.initialize(M.xSize, M.ySize, 0, Grid.U16)
oDataSlab.buffer.set_data_array(buffer.data_array)
oDataSlab.initialize_img()

func new_slb():
oDataSlab.initialize(M.xSize, M.ySize, 0, Grid.U16)
oDataSlab.initialize_img()

func read_own(buffer):
oDataOwnership.initialize((M.xSize*3)+1, (M.ySize*3)+1, 5, Grid.U8)
Expand Down
4 changes: 4 additions & 0 deletions Scenes/SlabDisplay.gd
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func set_visual(columnArray):
material.set_shader_param("fieldSizeInSubtiles", Vector2(3, 3))
material.set_shader_param("animationDatabase", preload("res://Shaders/textureanimationdatabase.png"))
material.set_shader_param("viewTextures", dataTexture)
if slabID == 57:
material.set_shader_param("slabIdData", preload("res://Shaders/Bedrock3x3.png"))
else:
material.set_shader_param("slabIdData", preload("res://Shaders/Black3x3.png"))

#func _process(delta):
# print(material.get_shader_param("dkTextureMap_Split_A"))
Binary file added Shaders/Bedrock3x3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions Shaders/Bedrock3x3.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/Bedrock3x3.png-83955db44e9a66884d8395bb895d23b6.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Shaders/Bedrock3x3.png"
dest_files=[ "res://.import/Bedrock3x3.png-83955db44e9a66884d8395bb895d23b6.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=true
flags/anisotropic=true
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0
22 changes: 18 additions & 4 deletions Shaders/display_texture_2d.shader
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ const vec2 oneTileSize = vec2(32,32);
const float TEXTURE_ANIMATION_SPEED = 12.0;
uniform int showOnlySpecificStyle = 77777;
uniform sampler2D slxData;
uniform sampler2D slabIdData;
uniform sampler2DArray dkTextureMap_Split_A1;
uniform sampler2DArray dkTextureMap_Split_A2;
uniform sampler2DArray dkTextureMap_Split_B1;
uniform sampler2DArray dkTextureMap_Split_B2;

uniform vec2 fieldSizeInSubtiles = vec2(0.0, 0.0);

const float DARKENING_FACTOR = 0.35;

// Exact same function as in Godot Source Code
float calc_mip_level(vec2 texture_coord) {
vec2 dx = dFdx(texture_coord);
Expand Down Expand Up @@ -62,6 +65,9 @@ void fragment() {
discard;
}

// Get the slab ID
int slabId = int(texelGet(slabIdData, ivec2(slabX, slabY), 0).r * 255.0);

int index = getIndex(ivec2(subtileX,subtileY));
if (index >= 544 && index < 1000) { // 544 is the index where the TexAnims start (544 - 999)
int frame = int(mod(TIME * TEXTURE_ANIMATION_SPEED, 8));
Expand All @@ -71,14 +77,22 @@ void fragment() {
vec2 resolutionOfField = fieldSizeInSubtiles * oneTileSize;
float mipmapLevel = calc_mip_level(UV * resolutionOfField);

vec4 finalColor;
if (index < 272) { // Splitting the TextureArray into 2, so that it will work on older PCs.
COLOR = textureLod(dkTextureMap_Split_A1, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index)), mipmapLevel);
finalColor = textureLod(dkTextureMap_Split_A1, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index)), mipmapLevel);
} else if (index < 544){
COLOR = textureLod(dkTextureMap_Split_A2, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index-272)), mipmapLevel);
finalColor = textureLod(dkTextureMap_Split_A2, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index-272)), mipmapLevel);
} else if (index < 1272){
COLOR = textureLod(dkTextureMap_Split_B1, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index-1000)), mipmapLevel);
finalColor = textureLod(dkTextureMap_Split_B1, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index-1000)), mipmapLevel);
} else {
finalColor = textureLod(dkTextureMap_Split_B2, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index-1272)), mipmapLevel);
}

// Apply darkening if slabId is 57
if (slabId == 57) {
COLOR = vec4(finalColor.rgb * (1.0-DARKENING_FACTOR), finalColor.a);
} else {
COLOR = textureLod(dkTextureMap_Split_B2, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index-1272)), mipmapLevel);
COLOR = finalColor;
}
}

Expand Down

0 comments on commit 2843b60

Please sign in to comment.