mirror of
https://github.com/JHDev2006/Super-Mario-Bros.-Remastered-Public.git
synced 2025-10-24 00:10:52 +00:00
improvements
This commit is contained in:
175
Scenes/Prefabs/Autoload/NewLevelBuilder.gd
Normal file
175
Scenes/Prefabs/Autoload/NewLevelBuilder.gd
Normal file
@@ -0,0 +1,175 @@
|
||||
extends Node
|
||||
|
||||
var entity_map := {}
|
||||
|
||||
|
||||
const base64_charset := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||
|
||||
var sub_level_file = null
|
||||
|
||||
var level_file := {}
|
||||
|
||||
const BASE_LEVEL_SCENE: PackedScene = preload("res://Scenes/Levels/CustomLevelBase.tscn")
|
||||
|
||||
static var sub_levels: Array[PackedScene] = [null, null, null, null, null]
|
||||
|
||||
signal level_building_complete
|
||||
|
||||
var building = false
|
||||
|
||||
func _ready() -> void:
|
||||
load_entity_map()
|
||||
|
||||
func load_level(level_file := {}) -> void:
|
||||
building = true
|
||||
for i in 5:
|
||||
sub_levels[i] = build_sublevel(i, level_file)
|
||||
level_building_complete.emit()
|
||||
building = false
|
||||
|
||||
func build_sublevel(level_idx := 0, level_file := {}) -> PackedScene:
|
||||
var level = BASE_LEVEL_SCENE.instantiate()
|
||||
sub_level_file = level_file["Levels"][level_idx]
|
||||
return pack_level_into_scene(build_level(level))
|
||||
|
||||
func pack_level_into_scene(level: Node) -> PackedScene:
|
||||
var scene = PackedScene.new()
|
||||
scene.pack(level)
|
||||
return scene
|
||||
|
||||
func load_entity_map() -> void:
|
||||
entity_map = JSON.parse_string(FileAccess.open(EntityIDMapper.MAP_PATH, FileAccess.READ).get_as_text())
|
||||
|
||||
func build_level(level: Node = null) -> Node:
|
||||
if sub_level_file.is_empty():
|
||||
return null
|
||||
var layer_id := 0
|
||||
for layer in sub_level_file["Layers"]:
|
||||
for chunk_id in layer:
|
||||
var chunk = layer[chunk_id]
|
||||
add_tiles(level, LevelSaver.decompress_string(chunk["Tiles"]), int(chunk_id), int(layer_id))
|
||||
add_entities(level, LevelSaver.decompress_string(chunk["Entities"]), int(chunk_id), int(layer_id))
|
||||
layer_id += 1
|
||||
apply_level_data(level, sub_level_file["Data"])
|
||||
apply_bg_data(level, sub_level_file["BG"])
|
||||
return level
|
||||
|
||||
func add_tiles(level: Node, chunk := "", chunk_id := 0, layer := 0) -> void:
|
||||
for tile in chunk.split("=", false):
|
||||
var tile_position := Vector2i.ZERO
|
||||
var tile_atlas_position := Vector2i.ZERO
|
||||
var source_id := 0
|
||||
|
||||
tile_position = decode_tile_position_from_chars(tile[0], tile[1], chunk_id)
|
||||
source_id = base64_charset.find(tile[4])
|
||||
tile_atlas_position = Vector2i(base64_charset.find(tile[2]), base64_charset.find(tile[3]))
|
||||
level.get_node("TileLayer" + str(layer + 1)).set_cell(tile_position, source_id, tile_atlas_position)
|
||||
|
||||
func add_entities(level: Node, chunk := "", chunk_id := 0, layer := 0) -> void:
|
||||
for entity in chunk.split("=", false):
|
||||
var entity_id = entity.get_slice(",", 1)
|
||||
var entity_chunk_position = entity.get_slice(",", 0)
|
||||
var entity_tile_position = decode_tile_position_from_chars(entity_chunk_position[0], entity_chunk_position[1], chunk_id)
|
||||
var entity_node: Node = null
|
||||
if entity_map.has(entity_id) == false:
|
||||
Global.log_error("MISSING ENTITY ID!!!! JOE FORGOT TO UPDATE THE MAP AGAIN :(")
|
||||
continue
|
||||
if entity_map[entity_id][0] != "res://Scenes/Prefabs/Entities/Player.tscn":
|
||||
entity_node = load(entity_map[entity_id][0]).instantiate()
|
||||
else:
|
||||
entity_node = get_node("EntityLayer1/Player")
|
||||
if entity_node == null:
|
||||
continue
|
||||
var offset = entity_map[entity_id][1].split(",")
|
||||
entity_node.global_position = entity_tile_position * 16 + (Vector2i(8, 8) + Vector2i(int(offset[0]), int(offset[1])))
|
||||
level.get_node("EntityLayer" + str(layer + 1)).add_child(entity_node)
|
||||
entity_node.reset_physics_interpolation()
|
||||
entity_node.owner = level
|
||||
entity_node.set_meta("tile_position", entity_tile_position)
|
||||
entity_node.set_meta("tile_offset", Vector2(int(offset[0]), int(offset[1])))
|
||||
if entity_node.has_node("EditorPropertyExposer"):
|
||||
entity_node.get_node("EditorPropertyExposer").apply_string(entity)
|
||||
|
||||
func reset_player(player: Player) -> void: ## Function literally here to just reset the player back to default starting, if loading into a level file, that hasnt been written yet (pipes)
|
||||
player.show()
|
||||
player.state_machine.transition_to("Normal")
|
||||
player.global_position = Vector2(-232, 0)
|
||||
|
||||
func gzip_encode(text: String) -> String:
|
||||
var bytes = Marshalls.base64_to_raw(text)
|
||||
bytes.compress(FileAccess.COMPRESSION_GZIP)
|
||||
return Marshalls.raw_to_base64(bytes)
|
||||
|
||||
func gzip_decode(text: String) -> String:
|
||||
var bytes = Marshalls.base64_to_raw(text)
|
||||
bytes.decompress_dynamic(-1, FileAccess.COMPRESSION_GZIP)
|
||||
return Marshalls.raw_to_base64(bytes)
|
||||
|
||||
func apply_level_data(level: Level, data := "") -> void:
|
||||
var split = data.split("=")
|
||||
var values := []
|
||||
for i in split:
|
||||
if i.length() == 2:
|
||||
values.append(decode_from_base64_2char(i))
|
||||
elif i.length() == 1:
|
||||
values.append(base64_charset.find(i))
|
||||
else:
|
||||
values.append(i)
|
||||
level.theme = Level.THEME_IDXS[values[0]]
|
||||
Global.level_theme = level.theme
|
||||
level.theme_time = ["Day", "Night"][values[1]]
|
||||
Global.theme_time = level.theme_time
|
||||
level.campaign = ["SMB1", "SMBLL", "SMBS", "SMBANN"][values[3]]
|
||||
Global.current_campaign = level.campaign
|
||||
level.can_backscroll = bool(values[4])
|
||||
level.vertical_height = -int(values[5])
|
||||
level.time_limit = int(values[6])
|
||||
ResourceSetterNew.cache.clear()
|
||||
Global.level_theme_changed.emit()
|
||||
|
||||
func apply_bg_data(level: Node, data := "") -> void:
|
||||
var split = data.split("=", false)
|
||||
var id := 0
|
||||
|
||||
const BG_VALUES := ["primary_layer", "second_layer", "second_layer_offset", "time_of_day", "particles", "liquid_layer", "overlay_clouds"]
|
||||
var SELECTORS = [%PrimaryLayer, %SecondLayer, %SecondLayerOffset, %TimeOfDay, %Particles, %LiquidLayer, %OverlayClouds]
|
||||
for i in split:
|
||||
var value := 0
|
||||
if i.length() > 1:
|
||||
value = (decode_from_base64_2char(i))
|
||||
else:
|
||||
value = (base64_charset.find(i))
|
||||
if is_instance_valid($TileMenu):
|
||||
if SELECTORS[id] is SpinBox:
|
||||
SELECTORS[id].value = value
|
||||
elif SELECTORS[id] is Button:
|
||||
SELECTORS[id].set_pressed_no_signal(bool(value))
|
||||
else:
|
||||
SELECTORS[id].selected = value
|
||||
level.get_node("LevelBG").set_value(value, BG_VALUES[id])
|
||||
id += 1
|
||||
|
||||
|
||||
func decode_tile_position_from_chars(char_x: String, char_y: String, chunk_idx: int) -> Vector2i:
|
||||
|
||||
var local_x = base64_charset.find(char_x)
|
||||
var local_y = base64_charset.find(char_y)
|
||||
|
||||
return Vector2i(local_x + (chunk_idx * 32), local_y - 30)
|
||||
|
||||
func decode_from_base64_2char(encoded: String) -> int:
|
||||
if encoded.length() != 2:
|
||||
push_error("Encoded string must be exactly 2 characters.")
|
||||
return -1
|
||||
|
||||
var idx1 = base64_charset.find(encoded[0])
|
||||
var idx2 = base64_charset.find(encoded[1])
|
||||
|
||||
if idx1 == -1 or idx2 == -1:
|
||||
push_error("Invalid character in base64 string.")
|
||||
return -1
|
||||
|
||||
return (idx1 << 6) | idx2
|
||||
|
||||
func tile_to_chunk_idx(tile_position := Vector2i.ZERO) -> int:
|
||||
return floor(tile_position.x / 32.0)
|
||||
1
Scenes/Prefabs/Autoload/NewLevelBuilder.gd.uid
Normal file
1
Scenes/Prefabs/Autoload/NewLevelBuilder.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c7bgjliycurbp
|
||||
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=41 format=3 uid="uid://bod0jkf7jc5pm"]
|
||||
[gd_scene load_steps=42 format=3 uid="uid://bod0jkf7jc5pm"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bjbd3a6su47si" path="res://Scripts/Classes/UI/GameHUD.gd" id="1_f34v2"]
|
||||
[ext_resource type="Script" uid="uid://caq1qiwmy0mox" path="res://Scripts/Parts/BetterAnimatedSprite.gd" id="2_cbrve"]
|
||||
@@ -106,6 +106,9 @@ _data = {
|
||||
&"RESET": SubResource("Animation_oqalm")
|
||||
}
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_h6dkv"]
|
||||
shader = ExtResource("9_oqalm")
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jwl8o"]
|
||||
bg_color = Color(0, 0, 0, 1)
|
||||
|
||||
@@ -783,6 +786,7 @@ region_rect = Rect2(0, 0, 8, 8)
|
||||
[node name="ModernRadar" type="Sprite2D" parent="ModernHUD/TopLeft/RedCoins/YoshiEgg"]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
material = SubResource("ShaderMaterial_h6dkv")
|
||||
texture = ExtResource("7_r3m7e")
|
||||
centered = false
|
||||
hframes = 3
|
||||
@@ -824,6 +828,7 @@ hframes = 2
|
||||
region_rect = Rect2(0, 0, 8, 8)
|
||||
|
||||
[node name="LifeCount" type="HBoxContainer" parent="ModernHUD/TopLeft"]
|
||||
visible = false
|
||||
layout_mode = 0
|
||||
offset_left = 20.0
|
||||
offset_top = 44.0
|
||||
@@ -833,6 +838,7 @@ theme_override_constants/separation = -4
|
||||
|
||||
[node name="CharacterIcon" type="TextureRect" parent="ModernHUD/TopLeft/LifeCount"]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
texture = ExtResource("10_2w8b3")
|
||||
@@ -860,7 +866,23 @@ metadata/_custom_type_script = "uid://cbal8ms2oe1ik"
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 2
|
||||
text = "*"
|
||||
text = "*00"
|
||||
|
||||
[node name="DeathCount" type="Control" parent="ModernHUD/TopLeft"]
|
||||
anchors_preset = 0
|
||||
offset_left = 20.0
|
||||
offset_top = 44.0
|
||||
offset_right = 60.0
|
||||
offset_bottom = 60.0
|
||||
|
||||
[node name="DeathCountLabel" type="Label" parent="ModernHUD/TopLeft/DeathCount"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 0
|
||||
offset_left = -4.0
|
||||
offset_right = 36.0
|
||||
offset_bottom = 16.0
|
||||
size_flags_horizontal = 2
|
||||
text = "☠*00"
|
||||
|
||||
[node name="ModernKeyCount" type="Control" parent="ModernHUD/TopLeft"]
|
||||
unique_name_in_owner = true
|
||||
@@ -1066,7 +1088,7 @@ metadata/_custom_type_script = "uid://cbal8ms2oe1ik"
|
||||
|
||||
[node name="TextShadowColourChanger" type="Node" parent="." node_paths=PackedStringArray("labels", "shadow_node")]
|
||||
script = ExtResource("18_jwl8o")
|
||||
labels = [NodePath("../Main/ScoreName/CharacterName"), NodePath("../Main/ScoreName/Score"), NodePath("../Main/CoinCount/CoinLabel"), NodePath("../Main/LevelDisplay/WorldTitle"), NodePath("../Main/LevelDisplay/WorldTitle/LevelNum"), NodePath("../Main/TimeDisplay/TimeLabel"), NodePath("../Main/TimeDisplay/TimeLabel/Time"), NodePath("../Main/TimeDisplay/TimeLabel/VBoxContainer/Stopwatch"), NodePath("../Main/TimeDisplay/TimeLabel/VBoxContainer/PB"), NodePath("../ModernHUD/TopLeft/CoinCount/ModernCoinCount"), NodePath("../ModernHUD/Right/ModernTime"), NodePath("../ModernHUD/Right/ModernTime/ModernScore"), NodePath("../Main/CoinCount/KeyCount/KeyAmount"), NodePath("../ModernHUD/TopLeft/ModernKeyCount/ModernKeyAmount"), NodePath("../ModernHUD/TopLeft/LifeCount/ModernLifeCount"), NodePath("../Combo/ComboAmount"), null, null, NodePath("../ModernHUD/Right/ModernTime/VBoxContainer/ModernPB"), NodePath("../Main/TimeDisplay/TimeLabel/VBoxContainer/IGT"), NodePath("../ModernHUD/Right/ModernTime/VBoxContainer/ModernIGT")]
|
||||
labels = [NodePath("../Main/ScoreName/CharacterName"), NodePath("../Main/ScoreName/Score"), NodePath("../Main/CoinCount/CoinLabel"), NodePath("../Main/LevelDisplay/WorldTitle"), NodePath("../Main/LevelDisplay/WorldTitle/LevelNum"), NodePath("../Main/TimeDisplay/TimeLabel"), NodePath("../Main/TimeDisplay/TimeLabel/Time"), NodePath("../Main/TimeDisplay/TimeLabel/VBoxContainer/Stopwatch"), NodePath("../Main/TimeDisplay/TimeLabel/VBoxContainer/PB"), NodePath("../ModernHUD/TopLeft/CoinCount/ModernCoinCount"), NodePath("../ModernHUD/Right/ModernTime"), NodePath("../ModernHUD/Right/ModernTime/ModernScore"), NodePath("../Main/CoinCount/KeyCount/KeyAmount"), NodePath("../ModernHUD/TopLeft/ModernKeyCount/ModernKeyAmount"), NodePath("../ModernHUD/TopLeft/LifeCount/ModernLifeCount"), NodePath("../Combo/ComboAmount"), NodePath("../ModernHUD/TopLeft/DeathCount/DeathCountLabel"), null, NodePath("../ModernHUD/Right/ModernTime/VBoxContainer/ModernPB"), NodePath("../Main/TimeDisplay/TimeLabel/VBoxContainer/IGT"), NodePath("../ModernHUD/Right/ModernTime/VBoxContainer/ModernIGT")]
|
||||
shadow_node = NodePath("../Main/RedCoins/BorderL/Shadow")
|
||||
|
||||
[node name="HudTemplate" type="Sprite2D" parent="."]
|
||||
@@ -1078,7 +1100,7 @@ centered = false
|
||||
|
||||
[node name="LabelFontChanger" type="Node" parent="." node_paths=PackedStringArray("labels")]
|
||||
script = ExtResource("15_jwl8o")
|
||||
labels = [NodePath("../Main/ScoreName/CharacterName"), NodePath("../Main/ScoreName/Score"), NodePath("../Main/CoinCount/CoinLabel"), NodePath("../Main/LevelDisplay/WorldTitle"), NodePath("../Main/LevelDisplay/WorldTitle/LevelNum"), NodePath("../Main/TimeDisplay/TimeLabel"), NodePath("../Main/TimeDisplay/TimeLabel/Time"), NodePath("../ModernHUD/TopLeft/CoinCount/ModernCoinCount"), NodePath("../ModernHUD/Right/ModernTime"), NodePath("../ModernHUD/Right/ModernTime/ModernScore"), NodePath("../Main/CoinCount/KeyCount/KeyAmount"), NodePath("../Main/TimeDisplay/TimeLabel/VBoxContainer/Stopwatch"), NodePath("../Main/TimeDisplay/TimeLabel/VBoxContainer/PB"), NodePath("../ModernHUD/TopLeft/LifeCount/ModernLifeCount"), NodePath("../Main/CoinCount/KeyCount/KeyAmount"), NodePath("../Combo/ComboAmount"), NodePath("../ModernHUD/TopLeft/ModernKeyCount/ModernKeyAmount"), NodePath("../Main/LevelDisplay/WorldTitle/LevelNum/Crown"), NodePath("../ModernHUD/Right/ModernTime/VBoxContainer/ModernPB"), NodePath("../Main/TimeDisplay/TimeLabel/VBoxContainer/IGT"), NodePath("../ModernHUD/Right/ModernTime/VBoxContainer/ModernIGT")]
|
||||
labels = [NodePath("../Main/ScoreName/CharacterName"), NodePath("../Main/ScoreName/Score"), NodePath("../Main/CoinCount/CoinLabel"), NodePath("../Main/LevelDisplay/WorldTitle"), NodePath("../Main/LevelDisplay/WorldTitle/LevelNum"), NodePath("../Main/TimeDisplay/TimeLabel"), NodePath("../Main/TimeDisplay/TimeLabel/Time"), NodePath("../ModernHUD/TopLeft/CoinCount/ModernCoinCount"), NodePath("../ModernHUD/Right/ModernTime"), NodePath("../ModernHUD/Right/ModernTime/ModernScore"), NodePath("../Main/CoinCount/KeyCount/KeyAmount"), NodePath("../Main/TimeDisplay/TimeLabel/VBoxContainer/Stopwatch"), NodePath("../Main/TimeDisplay/TimeLabel/VBoxContainer/PB"), NodePath("../ModernHUD/TopLeft/LifeCount/ModernLifeCount"), NodePath("../Main/CoinCount/KeyCount/KeyAmount"), NodePath("../Combo/ComboAmount"), NodePath("../ModernHUD/TopLeft/ModernKeyCount/ModernKeyAmount"), NodePath("../Main/LevelDisplay/WorldTitle/LevelNum/Crown"), NodePath("../ModernHUD/Right/ModernTime/VBoxContainer/ModernPB"), NodePath("../Main/TimeDisplay/TimeLabel/VBoxContainer/IGT"), NodePath("../ModernHUD/Right/ModernTime/VBoxContainer/ModernIGT"), NodePath("../ModernHUD/TopLeft/DeathCount/DeathCountLabel")]
|
||||
metadata/_custom_type_script = "uid://co6tjg3w6qpd8"
|
||||
|
||||
[node name="TextureUpdater" type="Node" parent="." node_paths=PackedStringArray("sprites")]
|
||||
|
||||
Reference in New Issue
Block a user