From 59329ed5c370a2925412198058f3c837b1702f14 Mon Sep 17 00:00:00 2001 From: wuke32767 <2446214230@qq.com> Date: Fri, 15 Nov 2024 16:32:41 +0800 Subject: [PATCH 1/8] relink all `this` to RealEntity (auto?) apply .editorcfg, and auto solve all error; remove .editcfg; replace "this" with "base"; solve all error; replace base to realentity --- .editorconfig.dog | 244 ++++++++++++++++++++ Source/Entities/LockBlocks/BaseLockBlock.cs | 51 ++-- 2 files changed, 270 insertions(+), 25 deletions(-) create mode 100644 .editorconfig.dog diff --git a/.editorconfig.dog b/.editorconfig.dog new file mode 100644 index 0000000..a94e8cb --- /dev/null +++ b/.editorconfig.dog @@ -0,0 +1,244 @@ +# 如果要从更高级别的目录继承 .editorconfig 设置,请删除以下行 +root = true + +# c# 文件 +[*.cs] + +#### Core EditorConfig 选项 #### + +# 缩进和间距 +indent_size = 4 +indent_style = space +tab_width = 4 + +# 新行首选项 +end_of_line = crlf +insert_final_newline = false + +#### .NET 代码操作 #### + +# 类型成员 +dotnet_hide_advanced_members = false +dotnet_member_insertion_location = with_other_members_of_the_same_kind +dotnet_property_generation_behavior = prefer_throwing_properties + +# 符号搜索 +dotnet_search_reference_assemblies = true + +#### .NET 编码约定 #### + +# 组织 Using +dotnet_separate_import_directive_groups = false +dotnet_sort_system_directives_first = false +file_header_template = unset + +# this. 和 Me. 首选项 +dotnet_style_qualification_for_event = true:error +dotnet_style_qualification_for_field = true +dotnet_style_qualification_for_method = true:error +dotnet_style_qualification_for_property = true:error + +# 语言关键字与 bcl 类型首选项 +dotnet_style_predefined_type_for_locals_parameters_members = true +dotnet_style_predefined_type_for_member_access = true + +# 括号首选项 +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity +dotnet_style_parentheses_in_other_operators = never_if_unnecessary +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity + +# 修饰符首选项 +dotnet_style_require_accessibility_modifiers = for_non_interface_members + +# 表达式级首选项 +dotnet_prefer_system_hash_code = true +dotnet_style_coalesce_expression = true +dotnet_style_collection_initializer = true +dotnet_style_explicit_tuple_names = true +dotnet_style_namespace_match_folder = true +dotnet_style_null_propagation = true +dotnet_style_object_initializer = true +dotnet_style_operator_placement_when_wrapping = beginning_of_line +dotnet_style_prefer_auto_properties = true +dotnet_style_prefer_collection_expression = when_types_loosely_match +dotnet_style_prefer_compound_assignment = true +dotnet_style_prefer_conditional_expression_over_assignment = true +dotnet_style_prefer_conditional_expression_over_return = true +dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed +dotnet_style_prefer_inferred_anonymous_type_member_names = true +dotnet_style_prefer_inferred_tuple_names = true +dotnet_style_prefer_is_null_check_over_reference_equality_method = true +dotnet_style_prefer_simplified_boolean_expressions = true +dotnet_style_prefer_simplified_interpolation = true + +# 字段首选项 +dotnet_style_readonly_field = true + +# 参数首选项 +dotnet_code_quality_unused_parameters = all + +# 禁止显示首选项 +dotnet_remove_unnecessary_suppression_exclusions = none + +# 新行首选项 +dotnet_style_allow_multiple_blank_lines_experimental = true +dotnet_style_allow_statement_immediately_after_block_experimental = true + +#### c# 编码约定 #### + +# var 首选项 +csharp_style_var_elsewhere = false +csharp_style_var_for_built_in_types = false +csharp_style_var_when_type_is_apparent = false + +# Expression-bodied 成员 +csharp_style_expression_bodied_accessors = true +csharp_style_expression_bodied_constructors = false +csharp_style_expression_bodied_indexers = true +csharp_style_expression_bodied_lambdas = true +csharp_style_expression_bodied_local_functions = false +csharp_style_expression_bodied_methods = false +csharp_style_expression_bodied_operators = false +csharp_style_expression_bodied_properties = true + +# 模式匹配首选项 +csharp_style_pattern_matching_over_as_with_null_check = true +csharp_style_pattern_matching_over_is_with_cast_check = true +csharp_style_prefer_extended_property_pattern = true +csharp_style_prefer_not_pattern = true +csharp_style_prefer_pattern_matching = true +csharp_style_prefer_switch_expression = true + +# Null 检查首选项 +csharp_style_conditional_delegate_call = true + +# 修饰符首选项 +csharp_prefer_static_anonymous_function = true +csharp_prefer_static_local_function = true +csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async +csharp_style_prefer_readonly_struct = true +csharp_style_prefer_readonly_struct_member = true + +# 代码块首选项 +csharp_prefer_braces = true +csharp_prefer_simple_using_statement = true +csharp_prefer_system_threading_lock = true +csharp_style_namespace_declarations = block_scoped +csharp_style_prefer_method_group_conversion = true +csharp_style_prefer_primary_constructors = true +csharp_style_prefer_top_level_statements = true + +# 表达式级首选项 +csharp_prefer_simple_default_expression = true +csharp_style_deconstructed_variable_declaration = true +csharp_style_implicit_object_creation_when_type_is_apparent = true:warning +csharp_style_inlined_variable_declaration = true +csharp_style_prefer_index_operator = true +csharp_style_prefer_local_over_anonymous_function = true +csharp_style_prefer_null_check_over_type_check = true +csharp_style_prefer_range_operator = true +csharp_style_prefer_tuple_swap = true +csharp_style_prefer_utf8_string_literals = true +csharp_style_throw_expression = true +csharp_style_unused_value_assignment_preference = discard_variable +csharp_style_unused_value_expression_statement_preference = discard_variable + +# "using" 指令首选项 +csharp_using_directive_placement = outside_namespace + +# 新行首选项 +csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true +csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true +csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true +csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true +csharp_style_allow_embedded_statements_on_same_line_experimental = true + +#### C# 格式规则 #### + +# 新行首选项 +csharp_new_line_before_catch = true +csharp_new_line_before_else = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_open_brace = all +csharp_new_line_between_query_expression_clauses = true + +# 缩进首选项 +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = true +csharp_indent_labels = one_less_than_current +csharp_indent_switch_labels = true + +# 空格键首选项 +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + +# 包装首选项 +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = true + +#### 命名样式 #### + +# 命名规则 + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +# 符号规范 + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# 命名样式 + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case diff --git a/Source/Entities/LockBlocks/BaseLockBlock.cs b/Source/Entities/LockBlocks/BaseLockBlock.cs index 1de8cef..0f83f32 100644 --- a/Source/Entities/LockBlocks/BaseLockBlock.cs +++ b/Source/Entities/LockBlocks/BaseLockBlock.cs @@ -9,6 +9,7 @@ namespace Celeste.Mod.MoreLockBlocks.Entities { public abstract class BaseLockBlock : Solid { + public Solid RealEntity; public EntityID ID; protected readonly string overrideSpritePath; @@ -34,12 +35,12 @@ protected struct OpeningSettings public BaseLockBlock(EntityData data, Vector2 offset, EntityID id, string defaultSpriteID = "MoreLockBlocks_generic_lock", string defaultUnlockSfx = "event:/game/03_resort/key_unlock") : base(data.Position + offset, 32f, 32f, false) { ID = id; - DisableLightsInside = false; - Add(new PlayerCollider(OnPlayer, new Circle(60f, 16f, 16f))); + RealEntity.DisableLightsInside = false; + RealEntity.Add(new PlayerCollider(OnPlayer, new Circle(60f, 16f, 16f))); - Add(Sprite = string.IsNullOrWhiteSpace(overrideSpritePath = data.Attr("spritePath", "")) ? MoreLockBlocksGFX.SpriteBank.Create(defaultSpriteID) : BuildCustomSprite(overrideSpritePath)); + RealEntity.Add(Sprite = string.IsNullOrWhiteSpace(overrideSpritePath = data.Attr("spritePath", "")) ? MoreLockBlocksGFX.SpriteBank.Create(defaultSpriteID) : BuildCustomSprite(overrideSpritePath)); Sprite.Play("idle"); - Sprite.Position = new Vector2(Width / 2f, Height / 2f); + Sprite.Position = new Vector2(RealEntity.Width / 2f, RealEntity.Height / 2f); string dzhakeHelperKeySettings = data.Attr("dzhakeHelperKeySettings", ""); bool _ = int.TryParse(dzhakeHelperKeySettings, out int dzhakeHelperKeyGroup); @@ -148,8 +149,8 @@ protected void TryOpen(Player player, Follower fol) [MethodImpl(MethodImplOptions.NoInlining)] protected virtual void TryOpen_DzhakeHelperLoaded(Player player, Follower fol) { - Collidable = false; - if (!Scene.CollideCheck(player.Center, Center)) + RealEntity.Collidable = false; + if (!RealEntity.Scene.CollideCheck(player.Center, RealEntity.Center)) { opening = true; if (fol.Entity is Key key) @@ -160,25 +161,25 @@ protected virtual void TryOpen_DzhakeHelperLoaded(Player player, Follower fol) { key2.StartedUsing = true; } - Add(new Coroutine(UnlockRoutine(fol))); + RealEntity.Add(new Coroutine(UnlockRoutine(fol))); } - Collidable = true; + RealEntity.Collidable = true; } [MethodImpl(MethodImplOptions.NoInlining)] protected virtual void TryOpen_DzhakeHelperUnloaded(Player player, Follower fol) { - Collidable = false; - if (!Scene.CollideCheck(player.Center, Center)) + RealEntity.Collidable = false; + if (!RealEntity.Scene.CollideCheck(player.Center, RealEntity.Center)) { opening = true; if (fol.Entity is Key key) { key.StartedUsing = true; } - Add(new Coroutine(UnlockRoutine(fol))); + RealEntity.Add(new Coroutine(UnlockRoutine(fol))); } - Collidable = true; + RealEntity.Collidable = true; } #endregion @@ -199,19 +200,19 @@ protected IEnumerator UnlockRoutine(Follower fol) [MethodImpl(MethodImplOptions.NoInlining)] protected virtual IEnumerator UnlockRoutine_DzhakeHelperLoaded(Follower fol) { - SoundEmitter emitter = SoundEmitter.Play(unlockSfxName, this); + SoundEmitter emitter = SoundEmitter.Play(unlockSfxName, RealEntity); emitter.Source.DisposeOnTransition = true; - Level level = SceneAs(); + Level level = RealEntity.SceneAs(); Key key = fol.Entity as Key; CustomKey key2 = fol.Entity as CustomKey; if (key is not null) { - Add(new Coroutine(key.UseRoutine(Center + new Vector2(0f, 2f)))); + RealEntity.Add(new Coroutine(key.UseRoutine(RealEntity.Center + new Vector2(0f, 2f)))); } else if (key2 is not null) { - Add(new Coroutine(key2.UseRoutine(Center + new Vector2(0f, 2f)))); + RealEntity.Add(new Coroutine(key2.UseRoutine(RealEntity.Center + new Vector2(0f, 2f)))); } yield return 1.2f; @@ -242,8 +243,8 @@ protected virtual IEnumerator UnlockRoutine_DzhakeHelperLoaded(Follower fol) } } - Tag |= Tags.TransitionUpdate; - Collidable = false; + RealEntity.Tag |= Tags.TransitionUpdate; + RealEntity.Collidable = false; emitter.Source.DisposeOnTransition = false; yield return Sprite.PlayRoutine("open"); @@ -251,18 +252,18 @@ protected virtual IEnumerator UnlockRoutine_DzhakeHelperLoaded(Follower fol) Input.Rumble(RumbleStrength.Medium, RumbleLength.Medium); yield return Sprite.PlayRoutine("burst"); - RemoveSelf(); + RealEntity.RemoveSelf(); } [MethodImpl(MethodImplOptions.NoInlining)] protected virtual IEnumerator UnlockRoutine_DzhakeHelperUnloaded(Follower fol) { - SoundEmitter emitter = SoundEmitter.Play(unlockSfxName, this); + SoundEmitter emitter = SoundEmitter.Play(unlockSfxName, RealEntity); emitter.Source.DisposeOnTransition = true; - Level level = SceneAs(); + Level level = RealEntity.SceneAs(); Key key = fol.Entity as Key; - Add(new Coroutine(key.UseRoutine(Center + new Vector2(0f, 2f)))); + RealEntity.Add(new Coroutine(key.UseRoutine(RealEntity.Center + new Vector2(0f, 2f)))); yield return 1.2f; UnlockingRegistered = true; @@ -278,8 +279,8 @@ protected virtual IEnumerator UnlockRoutine_DzhakeHelperUnloaded(Follower fol) yield return null; } - Tag |= Tags.TransitionUpdate; - Collidable = false; + RealEntity.Tag |= Tags.TransitionUpdate; + RealEntity.Collidable = false; emitter.Source.DisposeOnTransition = false; yield return Sprite.PlayRoutine("open"); @@ -287,7 +288,7 @@ protected virtual IEnumerator UnlockRoutine_DzhakeHelperUnloaded(Follower fol) Input.Rumble(RumbleStrength.Medium, RumbleLength.Medium); yield return Sprite.PlayRoutine("burst"); - RemoveSelf(); + RealEntity.RemoveSelf(); } #endregion From e309db189df039e7e5c46e9fa40dfac5fec300ee Mon Sep 17 00:00:00 2001 From: wuke32767 <2446214230@qq.com> Date: Sat, 16 Nov 2024 00:05:57 +0800 Subject: [PATCH 2/8] removed editerconfig --- .editorconfig.dog | 244 ---------------------------------------------- 1 file changed, 244 deletions(-) delete mode 100644 .editorconfig.dog diff --git a/.editorconfig.dog b/.editorconfig.dog deleted file mode 100644 index a94e8cb..0000000 --- a/.editorconfig.dog +++ /dev/null @@ -1,244 +0,0 @@ -# 如果要从更高级别的目录继承 .editorconfig 设置,请删除以下行 -root = true - -# c# 文件 -[*.cs] - -#### Core EditorConfig 选项 #### - -# 缩进和间距 -indent_size = 4 -indent_style = space -tab_width = 4 - -# 新行首选项 -end_of_line = crlf -insert_final_newline = false - -#### .NET 代码操作 #### - -# 类型成员 -dotnet_hide_advanced_members = false -dotnet_member_insertion_location = with_other_members_of_the_same_kind -dotnet_property_generation_behavior = prefer_throwing_properties - -# 符号搜索 -dotnet_search_reference_assemblies = true - -#### .NET 编码约定 #### - -# 组织 Using -dotnet_separate_import_directive_groups = false -dotnet_sort_system_directives_first = false -file_header_template = unset - -# this. 和 Me. 首选项 -dotnet_style_qualification_for_event = true:error -dotnet_style_qualification_for_field = true -dotnet_style_qualification_for_method = true:error -dotnet_style_qualification_for_property = true:error - -# 语言关键字与 bcl 类型首选项 -dotnet_style_predefined_type_for_locals_parameters_members = true -dotnet_style_predefined_type_for_member_access = true - -# 括号首选项 -dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity -dotnet_style_parentheses_in_other_binary_operators = always_for_clarity -dotnet_style_parentheses_in_other_operators = never_if_unnecessary -dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity - -# 修饰符首选项 -dotnet_style_require_accessibility_modifiers = for_non_interface_members - -# 表达式级首选项 -dotnet_prefer_system_hash_code = true -dotnet_style_coalesce_expression = true -dotnet_style_collection_initializer = true -dotnet_style_explicit_tuple_names = true -dotnet_style_namespace_match_folder = true -dotnet_style_null_propagation = true -dotnet_style_object_initializer = true -dotnet_style_operator_placement_when_wrapping = beginning_of_line -dotnet_style_prefer_auto_properties = true -dotnet_style_prefer_collection_expression = when_types_loosely_match -dotnet_style_prefer_compound_assignment = true -dotnet_style_prefer_conditional_expression_over_assignment = true -dotnet_style_prefer_conditional_expression_over_return = true -dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed -dotnet_style_prefer_inferred_anonymous_type_member_names = true -dotnet_style_prefer_inferred_tuple_names = true -dotnet_style_prefer_is_null_check_over_reference_equality_method = true -dotnet_style_prefer_simplified_boolean_expressions = true -dotnet_style_prefer_simplified_interpolation = true - -# 字段首选项 -dotnet_style_readonly_field = true - -# 参数首选项 -dotnet_code_quality_unused_parameters = all - -# 禁止显示首选项 -dotnet_remove_unnecessary_suppression_exclusions = none - -# 新行首选项 -dotnet_style_allow_multiple_blank_lines_experimental = true -dotnet_style_allow_statement_immediately_after_block_experimental = true - -#### c# 编码约定 #### - -# var 首选项 -csharp_style_var_elsewhere = false -csharp_style_var_for_built_in_types = false -csharp_style_var_when_type_is_apparent = false - -# Expression-bodied 成员 -csharp_style_expression_bodied_accessors = true -csharp_style_expression_bodied_constructors = false -csharp_style_expression_bodied_indexers = true -csharp_style_expression_bodied_lambdas = true -csharp_style_expression_bodied_local_functions = false -csharp_style_expression_bodied_methods = false -csharp_style_expression_bodied_operators = false -csharp_style_expression_bodied_properties = true - -# 模式匹配首选项 -csharp_style_pattern_matching_over_as_with_null_check = true -csharp_style_pattern_matching_over_is_with_cast_check = true -csharp_style_prefer_extended_property_pattern = true -csharp_style_prefer_not_pattern = true -csharp_style_prefer_pattern_matching = true -csharp_style_prefer_switch_expression = true - -# Null 检查首选项 -csharp_style_conditional_delegate_call = true - -# 修饰符首选项 -csharp_prefer_static_anonymous_function = true -csharp_prefer_static_local_function = true -csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async -csharp_style_prefer_readonly_struct = true -csharp_style_prefer_readonly_struct_member = true - -# 代码块首选项 -csharp_prefer_braces = true -csharp_prefer_simple_using_statement = true -csharp_prefer_system_threading_lock = true -csharp_style_namespace_declarations = block_scoped -csharp_style_prefer_method_group_conversion = true -csharp_style_prefer_primary_constructors = true -csharp_style_prefer_top_level_statements = true - -# 表达式级首选项 -csharp_prefer_simple_default_expression = true -csharp_style_deconstructed_variable_declaration = true -csharp_style_implicit_object_creation_when_type_is_apparent = true:warning -csharp_style_inlined_variable_declaration = true -csharp_style_prefer_index_operator = true -csharp_style_prefer_local_over_anonymous_function = true -csharp_style_prefer_null_check_over_type_check = true -csharp_style_prefer_range_operator = true -csharp_style_prefer_tuple_swap = true -csharp_style_prefer_utf8_string_literals = true -csharp_style_throw_expression = true -csharp_style_unused_value_assignment_preference = discard_variable -csharp_style_unused_value_expression_statement_preference = discard_variable - -# "using" 指令首选项 -csharp_using_directive_placement = outside_namespace - -# 新行首选项 -csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true -csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true -csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true -csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true -csharp_style_allow_embedded_statements_on_same_line_experimental = true - -#### C# 格式规则 #### - -# 新行首选项 -csharp_new_line_before_catch = true -csharp_new_line_before_else = true -csharp_new_line_before_finally = true -csharp_new_line_before_members_in_anonymous_types = true -csharp_new_line_before_members_in_object_initializers = true -csharp_new_line_before_open_brace = all -csharp_new_line_between_query_expression_clauses = true - -# 缩进首选项 -csharp_indent_block_contents = true -csharp_indent_braces = false -csharp_indent_case_contents = true -csharp_indent_case_contents_when_block = true -csharp_indent_labels = one_less_than_current -csharp_indent_switch_labels = true - -# 空格键首选项 -csharp_space_after_cast = false -csharp_space_after_colon_in_inheritance_clause = true -csharp_space_after_comma = true -csharp_space_after_dot = false -csharp_space_after_keywords_in_control_flow_statements = true -csharp_space_after_semicolon_in_for_statement = true -csharp_space_around_binary_operators = before_and_after -csharp_space_around_declaration_statements = false -csharp_space_before_colon_in_inheritance_clause = true -csharp_space_before_comma = false -csharp_space_before_dot = false -csharp_space_before_open_square_brackets = false -csharp_space_before_semicolon_in_for_statement = false -csharp_space_between_empty_square_brackets = false -csharp_space_between_method_call_empty_parameter_list_parentheses = false -csharp_space_between_method_call_name_and_opening_parenthesis = false -csharp_space_between_method_call_parameter_list_parentheses = false -csharp_space_between_method_declaration_empty_parameter_list_parentheses = false -csharp_space_between_method_declaration_name_and_open_parenthesis = false -csharp_space_between_method_declaration_parameter_list_parentheses = false -csharp_space_between_parentheses = false -csharp_space_between_square_brackets = false - -# 包装首选项 -csharp_preserve_single_line_blocks = true -csharp_preserve_single_line_statements = true - -#### 命名样式 #### - -# 命名规则 - -dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion -dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface -dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i - -dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion -dotnet_naming_rule.types_should_be_pascal_case.symbols = types -dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case - -dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion -dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members -dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case - -# 符号规范 - -dotnet_naming_symbols.interface.applicable_kinds = interface -dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.interface.required_modifiers = - -dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum -dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.types.required_modifiers = - -dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method -dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.non_field_members.required_modifiers = - -# 命名样式 - -dotnet_naming_style.pascal_case.required_prefix = -dotnet_naming_style.pascal_case.required_suffix = -dotnet_naming_style.pascal_case.word_separator = -dotnet_naming_style.pascal_case.capitalization = pascal_case - -dotnet_naming_style.begins_with_i.required_prefix = I -dotnet_naming_style.begins_with_i.required_suffix = -dotnet_naming_style.begins_with_i.word_separator = -dotnet_naming_style.begins_with_i.capitalization = pascal_case From 78e7836cbf52e728834e214a521ed3978f66b172 Mon Sep 17 00:00:00 2001 From: wuke32767 <2446214230@qq.com> Date: Fri, 15 Nov 2024 16:44:01 +0800 Subject: [PATCH 3/8] relinked? --- Source/Entities/LockBlocks/BaseLockBlock.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Source/Entities/LockBlocks/BaseLockBlock.cs b/Source/Entities/LockBlocks/BaseLockBlock.cs index 0f83f32..1660087 100644 --- a/Source/Entities/LockBlocks/BaseLockBlock.cs +++ b/Source/Entities/LockBlocks/BaseLockBlock.cs @@ -8,6 +8,14 @@ namespace Celeste.Mod.MoreLockBlocks.Entities { public abstract class BaseLockBlock : Solid + { + public BaseLockBlock(EntityData data, Vector2 offset, EntityID id, string defaultSpriteID = "MoreLockBlocks_generic_lock", string defaultUnlockSfx = "event:/game/03_resort/key_unlock") + : base(data.Position + offset, 32f, 32f, false) + { + Add(new BaseLockBlockComponent(this, data, offset, id, defaultSpriteID, defaultSpriteID)); + } + } + public class BaseLockBlockComponent : Component { public Solid RealEntity; public EntityID ID; @@ -32,8 +40,11 @@ protected struct OpeningSettings protected readonly string unlockSfxName; - public BaseLockBlock(EntityData data, Vector2 offset, EntityID id, string defaultSpriteID = "MoreLockBlocks_generic_lock", string defaultUnlockSfx = "event:/game/03_resort/key_unlock") : base(data.Position + offset, 32f, 32f, false) + public BaseLockBlockComponent(Solid This,EntityData data, Vector2 offset, EntityID id, string defaultSpriteID = "MoreLockBlocks_generic_lock", string defaultUnlockSfx = "event:/game/03_resort/key_unlock") + //: base(data.Position + offset, 32f, 32f, false) + :base(true,true) { + RealEntity = This; ID = id; RealEntity.DisableLightsInside = false; RealEntity.Add(new PlayerCollider(OnPlayer, new Circle(60f, 16f, 16f))); From 20a687c9eced9ac44e494049cdcfdff73d4a66d1 Mon Sep 17 00:00:00 2001 From: wuke32767 <2446214230@qq.com> Date: Fri, 15 Nov 2024 16:54:47 +0800 Subject: [PATCH 4/8] reimplementing virtual --- Source/Entities/LockBlocks/BaseLockBlock.cs | 46 ++++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/Source/Entities/LockBlocks/BaseLockBlock.cs b/Source/Entities/LockBlocks/BaseLockBlock.cs index 1660087..ab04af3 100644 --- a/Source/Entities/LockBlocks/BaseLockBlock.cs +++ b/Source/Entities/LockBlocks/BaseLockBlock.cs @@ -4,6 +4,7 @@ using System.Runtime.CompilerServices; using Celeste.Mod.DzhakeHelper; using Celeste.Mod.DzhakeHelper.Entities; +using System; namespace Celeste.Mod.MoreLockBlocks.Entities { @@ -20,10 +21,10 @@ public class BaseLockBlockComponent : Component public Solid RealEntity; public EntityID ID; - protected readonly string overrideSpritePath; + protected internal readonly string overrideSpritePath; public readonly Sprite Sprite; - protected struct OpeningSettings + protected internal struct OpeningSettings { public bool VanillaKeys; @@ -31,20 +32,27 @@ protected struct OpeningSettings public bool DzhakeHelperKeysAll; public int DzhakeHelperKeyGroup; } - protected OpeningSettings openingSettings; + protected internal OpeningSettings openingSettings; - protected bool opening; + protected internal bool opening; public bool UnlockingRegistered; - protected readonly bool stepMusicProgress; + protected internal readonly bool stepMusicProgress; - protected readonly string unlockSfxName; + protected internal readonly string unlockSfxName; public BaseLockBlockComponent(Solid This,EntityData data, Vector2 offset, EntityID id, string defaultSpriteID = "MoreLockBlocks_generic_lock", string defaultUnlockSfx = "event:/game/03_resort/key_unlock") //: base(data.Position + offset, 32f, 32f, false) :base(true,true) { RealEntity = This; + OnPlayer_DzhakeHelperLoaded=default_OnPlayer_DzhakeHelperLoaded; + OnPlayer_DzhakeHelperUnloaded=default_OnPlayer_DzhakeHelperUnloaded; + TryOpen_DzhakeHelperLoaded=default_TryOpen_DzhakeHelperLoaded; + TryOpen_DzhakeHelperUnloaded=default_TryOpen_DzhakeHelperUnloaded; + UnlockRoutine_DzhakeHelperLoaded=default_UnlockRoutine_DzhakeHelperLoaded; + UnlockRoutine_DzhakeHelperUnloaded= default_UnlockRoutine_DzhakeHelperUnloaded; + ID = id; RealEntity.DisableLightsInside = false; RealEntity.Add(new PlayerCollider(OnPlayer, new Circle(60f, 16f, 16f))); @@ -70,7 +78,7 @@ public BaseLockBlockComponent(Solid This,EntityData data, Vector2 offset, Entity unlockSfxName = SFX.EventnameByHandle(unlockSfxName); } - protected static Sprite BuildCustomSprite(string spritePath) + protected internal static Sprite BuildCustomSprite(string spritePath) { /* @@ -91,7 +99,7 @@ protected static Sprite BuildCustomSprite(string spritePath) #region OnPlayer - protected void OnPlayer(Player player) + protected internal void OnPlayer(Player player) { if (MoreLockBlocksModule.Instance.DzhakeHelperLoaded) { @@ -103,8 +111,9 @@ protected void OnPlayer(Player player) } } + protected internal Action OnPlayer_DzhakeHelperLoaded; [MethodImpl(MethodImplOptions.NoInlining)] - protected virtual void OnPlayer_DzhakeHelperLoaded(Player player) + protected internal virtual void default_OnPlayer_DzhakeHelperLoaded(Player player) { if (opening) { @@ -125,8 +134,9 @@ protected virtual void OnPlayer_DzhakeHelperLoaded(Player player) } } + protected internal Action OnPlayer_DzhakeHelperUnloaded; [MethodImpl(MethodImplOptions.NoInlining)] - protected virtual void OnPlayer_DzhakeHelperUnloaded(Player player) + protected internal virtual void default_OnPlayer_DzhakeHelperUnloaded(Player player) { if (opening) { @@ -145,7 +155,7 @@ protected virtual void OnPlayer_DzhakeHelperUnloaded(Player player) #endregion #region TryOpen - protected void TryOpen(Player player, Follower fol) + protected internal void TryOpen(Player player, Follower fol) { if (MoreLockBlocksModule.Instance.DzhakeHelperLoaded) { @@ -157,8 +167,9 @@ protected void TryOpen(Player player, Follower fol) } } + protected internal Action TryOpen_DzhakeHelperLoaded; [MethodImpl(MethodImplOptions.NoInlining)] - protected virtual void TryOpen_DzhakeHelperLoaded(Player player, Follower fol) + protected internal virtual void default_TryOpen_DzhakeHelperLoaded(Player player, Follower fol) { RealEntity.Collidable = false; if (!RealEntity.Scene.CollideCheck(player.Center, RealEntity.Center)) @@ -177,8 +188,9 @@ protected virtual void TryOpen_DzhakeHelperLoaded(Player player, Follower fol) RealEntity.Collidable = true; } + protected internal Action TryOpen_DzhakeHelperUnloaded; [MethodImpl(MethodImplOptions.NoInlining)] - protected virtual void TryOpen_DzhakeHelperUnloaded(Player player, Follower fol) + protected internal virtual void default_TryOpen_DzhakeHelperUnloaded(Player player, Follower fol) { RealEntity.Collidable = false; if (!RealEntity.Scene.CollideCheck(player.Center, RealEntity.Center)) @@ -196,7 +208,7 @@ protected virtual void TryOpen_DzhakeHelperUnloaded(Player player, Follower fol) #endregion #region UnlockRoutine - protected IEnumerator UnlockRoutine(Follower fol) + protected internal IEnumerator UnlockRoutine(Follower fol) { if (MoreLockBlocksModule.Instance.DzhakeHelperLoaded) { @@ -208,8 +220,9 @@ protected IEnumerator UnlockRoutine(Follower fol) } } + protected internal Func UnlockRoutine_DzhakeHelperLoaded; [MethodImpl(MethodImplOptions.NoInlining)] - protected virtual IEnumerator UnlockRoutine_DzhakeHelperLoaded(Follower fol) + protected internal virtual IEnumerator default_UnlockRoutine_DzhakeHelperLoaded(Follower fol) { SoundEmitter emitter = SoundEmitter.Play(unlockSfxName, RealEntity); emitter.Source.DisposeOnTransition = true; @@ -266,8 +279,9 @@ protected virtual IEnumerator UnlockRoutine_DzhakeHelperLoaded(Follower fol) RealEntity.RemoveSelf(); } + protected internal Func UnlockRoutine_DzhakeHelperUnloaded; [MethodImpl(MethodImplOptions.NoInlining)] - protected virtual IEnumerator UnlockRoutine_DzhakeHelperUnloaded(Follower fol) + protected internal virtual IEnumerator default_UnlockRoutine_DzhakeHelperUnloaded(Follower fol) { SoundEmitter emitter = SoundEmitter.Play(unlockSfxName, RealEntity); emitter.Source.DisposeOnTransition = true; From 9d57d44636a5d55693ace8768c148d76ef16cec0 Mon Sep 17 00:00:00 2001 From: wuke32767 <2446214230@qq.com> Date: Fri, 15 Nov 2024 17:03:41 +0800 Subject: [PATCH 5/8] relink all fields --- Source/Entities/LockBlocks/BaseLockBlock.cs | 52 +++++++++++++------- Source/Entities/LockBlocks/DreamLockBlock.cs | 2 +- Source/Entities/LockBlocks/GlassLockBlock.cs | 2 +- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/Source/Entities/LockBlocks/BaseLockBlock.cs b/Source/Entities/LockBlocks/BaseLockBlock.cs index ab04af3..3bb4563 100644 --- a/Source/Entities/LockBlocks/BaseLockBlock.cs +++ b/Source/Entities/LockBlocks/BaseLockBlock.cs @@ -1,20 +1,34 @@ +using Celeste.Mod.DzhakeHelper; +using Celeste.Mod.DzhakeHelper.Entities; using Microsoft.Xna.Framework; using Monocle; +using System; using System.Collections; using System.Runtime.CompilerServices; -using Celeste.Mod.DzhakeHelper; -using Celeste.Mod.DzhakeHelper.Entities; -using System; namespace Celeste.Mod.MoreLockBlocks.Entities { - public abstract class BaseLockBlock : Solid + public abstract class LegacyBaseLockBlock : Solid { - public BaseLockBlock(EntityData data, Vector2 offset, EntityID id, string defaultSpriteID = "MoreLockBlocks_generic_lock", string defaultUnlockSfx = "event:/game/03_resort/key_unlock") + public EntityID ID => component.ID; + + protected internal string overrideSpritePath => component.overrideSpritePath; + public Sprite Sprite => component.Sprite; + + protected internal BaseLockBlockComponent.OpeningSettings openingSettings { get => component.openingSettings; set => component.openingSettings = value; } + + protected internal bool opening { get => component.opening; set => component.opening = value; } + public bool UnlockingRegistered { get => component.UnlockingRegistered; set => component.UnlockingRegistered = value; } + + protected internal bool stepMusicProgress => component.stepMusicProgress; + + protected internal string unlockSfxName => component.unlockSfxName; + public LegacyBaseLockBlock(EntityData data, Vector2 offset, EntityID id, string defaultSpriteID = "MoreLockBlocks_generic_lock", string defaultUnlockSfx = "event:/game/03_resort/key_unlock") : base(data.Position + offset, 32f, 32f, false) { - Add(new BaseLockBlockComponent(this, data, offset, id, defaultSpriteID, defaultSpriteID)); + Add(component = new BaseLockBlockComponent(this, data, offset, id, defaultSpriteID, defaultSpriteID)); } + readonly BaseLockBlockComponent component; } public class BaseLockBlockComponent : Component { @@ -24,7 +38,7 @@ public class BaseLockBlockComponent : Component protected internal readonly string overrideSpritePath; public readonly Sprite Sprite; - protected internal struct OpeningSettings + public struct OpeningSettings { public bool VanillaKeys; @@ -41,17 +55,17 @@ protected internal struct OpeningSettings protected internal readonly string unlockSfxName; - public BaseLockBlockComponent(Solid This,EntityData data, Vector2 offset, EntityID id, string defaultSpriteID = "MoreLockBlocks_generic_lock", string defaultUnlockSfx = "event:/game/03_resort/key_unlock") + public BaseLockBlockComponent(Solid This, EntityData data, Vector2 offset, EntityID id, string defaultSpriteID = "MoreLockBlocks_generic_lock", string defaultUnlockSfx = "event:/game/03_resort/key_unlock") //: base(data.Position + offset, 32f, 32f, false) - :base(true,true) + : base(true, true) { RealEntity = This; - OnPlayer_DzhakeHelperLoaded=default_OnPlayer_DzhakeHelperLoaded; - OnPlayer_DzhakeHelperUnloaded=default_OnPlayer_DzhakeHelperUnloaded; - TryOpen_DzhakeHelperLoaded=default_TryOpen_DzhakeHelperLoaded; - TryOpen_DzhakeHelperUnloaded=default_TryOpen_DzhakeHelperUnloaded; - UnlockRoutine_DzhakeHelperLoaded=default_UnlockRoutine_DzhakeHelperLoaded; - UnlockRoutine_DzhakeHelperUnloaded= default_UnlockRoutine_DzhakeHelperUnloaded; + OnPlayer_DzhakeHelperLoaded = default_OnPlayer_DzhakeHelperLoaded; + OnPlayer_DzhakeHelperUnloaded = default_OnPlayer_DzhakeHelperUnloaded; + TryOpen_DzhakeHelperLoaded = default_TryOpen_DzhakeHelperLoaded; + TryOpen_DzhakeHelperUnloaded = default_TryOpen_DzhakeHelperUnloaded; + UnlockRoutine_DzhakeHelperLoaded = default_UnlockRoutine_DzhakeHelperLoaded; + UnlockRoutine_DzhakeHelperUnloaded = default_UnlockRoutine_DzhakeHelperUnloaded; ID = id; RealEntity.DisableLightsInside = false; @@ -167,7 +181,7 @@ protected internal void TryOpen(Player player, Follower fol) } } - protected internal Action TryOpen_DzhakeHelperLoaded; + protected internal Action TryOpen_DzhakeHelperLoaded; [MethodImpl(MethodImplOptions.NoInlining)] protected internal virtual void default_TryOpen_DzhakeHelperLoaded(Player player, Follower fol) { @@ -188,7 +202,7 @@ protected internal virtual void default_TryOpen_DzhakeHelperLoaded(Player player RealEntity.Collidable = true; } - protected internal Action TryOpen_DzhakeHelperUnloaded; + protected internal Action TryOpen_DzhakeHelperUnloaded; [MethodImpl(MethodImplOptions.NoInlining)] protected internal virtual void default_TryOpen_DzhakeHelperUnloaded(Player player, Follower fol) { @@ -220,7 +234,7 @@ protected internal IEnumerator UnlockRoutine(Follower fol) } } - protected internal Func UnlockRoutine_DzhakeHelperLoaded; + protected internal Func UnlockRoutine_DzhakeHelperLoaded; [MethodImpl(MethodImplOptions.NoInlining)] protected internal virtual IEnumerator default_UnlockRoutine_DzhakeHelperLoaded(Follower fol) { @@ -279,7 +293,7 @@ protected internal virtual IEnumerator default_UnlockRoutine_DzhakeHelperLoaded( RealEntity.RemoveSelf(); } - protected internal Func UnlockRoutine_DzhakeHelperUnloaded; + protected internal Func UnlockRoutine_DzhakeHelperUnloaded; [MethodImpl(MethodImplOptions.NoInlining)] protected internal virtual IEnumerator default_UnlockRoutine_DzhakeHelperUnloaded(Follower fol) { diff --git a/Source/Entities/LockBlocks/DreamLockBlock.cs b/Source/Entities/LockBlocks/DreamLockBlock.cs index 7ce0157..67dfb51 100644 --- a/Source/Entities/LockBlocks/DreamLockBlock.cs +++ b/Source/Entities/LockBlocks/DreamLockBlock.cs @@ -17,7 +17,7 @@ namespace Celeste.Mod.MoreLockBlocks.Entities { [Tracked] [CustomEntity("MoreLockBlocks/DreamLockBlock")] - public class DreamLockBlock : BaseLockBlock + public class DreamLockBlock : LegacyBaseLockBlock { [TrackedAs(typeof(DreamBlock))] internal class DreamBlockDummy : DreamBlock diff --git a/Source/Entities/LockBlocks/GlassLockBlock.cs b/Source/Entities/LockBlocks/GlassLockBlock.cs index 6df2685..d3493c0 100644 --- a/Source/Entities/LockBlocks/GlassLockBlock.cs +++ b/Source/Entities/LockBlocks/GlassLockBlock.cs @@ -10,7 +10,7 @@ namespace Celeste.Mod.MoreLockBlocks.Entities { [Tracked] [CustomEntity("MoreLockBlocks/GlassLockBlock")] - public class GlassLockBlock : BaseLockBlock + public class GlassLockBlock : LegacyBaseLockBlock { private const string spriteID = "MoreLockBlocks_generic_lock"; From f6c8b75ffeabcecfacf03a02fc4753ac050879e1 Mon Sep 17 00:00:00 2001 From: wuke32767 <2446214230@qq.com> Date: Fri, 15 Nov 2024 19:16:51 +0800 Subject: [PATCH 6/8] fix dream b lock --- Source/Entities/LockBlocks/BaseLockBlock.cs | 2 +- Source/Entities/LockBlocks/DreamLockBlock.cs | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Source/Entities/LockBlocks/BaseLockBlock.cs b/Source/Entities/LockBlocks/BaseLockBlock.cs index 3bb4563..6eaf9f7 100644 --- a/Source/Entities/LockBlocks/BaseLockBlock.cs +++ b/Source/Entities/LockBlocks/BaseLockBlock.cs @@ -28,7 +28,7 @@ public LegacyBaseLockBlock(EntityData data, Vector2 offset, EntityID id, string { Add(component = new BaseLockBlockComponent(this, data, offset, id, defaultSpriteID, defaultSpriteID)); } - readonly BaseLockBlockComponent component; + protected readonly BaseLockBlockComponent component; } public class BaseLockBlockComponent : Component { diff --git a/Source/Entities/LockBlocks/DreamLockBlock.cs b/Source/Entities/LockBlocks/DreamLockBlock.cs index 67dfb51..2803e5a 100644 --- a/Source/Entities/LockBlocks/DreamLockBlock.cs +++ b/Source/Entities/LockBlocks/DreamLockBlock.cs @@ -257,6 +257,10 @@ public DreamLockBlock(EntityData data, Vector2 offset, EntityID id) : base(data, SurfaceSoundIndex = 11; dummyBelow = data.Bool("below", false); dummyIgnoreInventory = data.Bool("ignoreInventory", false); + component.TryOpen_DzhakeHelperLoaded = TryOpen_DzhakeHelperLoaded; + component.TryOpen_DzhakeHelperUnloaded = TryOpen_DzhakeHelperUnloaded; + component.UnlockRoutine_DzhakeHelperLoaded = UnlockRoutine_DzhakeHelperLoaded; + component.UnlockRoutine_DzhakeHelperUnloaded = UnlockRoutine_DzhakeHelperUnloaded; } public override void Added(Scene scene) @@ -274,7 +278,7 @@ public override void Added(Scene scene) #region TryOpen [MethodImpl(MethodImplOptions.NoInlining)] - protected override void TryOpen_DzhakeHelperLoaded(Player player, Follower fol) + protected void TryOpen_DzhakeHelperLoaded(Player player, Follower fol) { Collidable = dummy.Collidable = false; if (!Scene.CollideCheck(player.Center, Center)) @@ -288,13 +292,13 @@ protected override void TryOpen_DzhakeHelperLoaded(Player player, Follower fol) { key2.StartedUsing = true; } - Add(new Coroutine(UnlockRoutine(fol))); + Add(new Coroutine(component.UnlockRoutine(fol))); } Collidable = dummy.Collidable = true; } [MethodImpl(MethodImplOptions.NoInlining)] - protected override void TryOpen_DzhakeHelperUnloaded(Player player, Follower fol) + protected void TryOpen_DzhakeHelperUnloaded(Player player, Follower fol) { Collidable = dummy.Collidable = false; if (!Scene.CollideCheck(player.Center, Center)) @@ -304,7 +308,7 @@ protected override void TryOpen_DzhakeHelperUnloaded(Player player, Follower fol { key.StartedUsing = true; } - Add(new Coroutine(UnlockRoutine(fol))); + Add(new Coroutine(component.UnlockRoutine(fol))); } Collidable = dummy.Collidable = true; } @@ -313,7 +317,7 @@ protected override void TryOpen_DzhakeHelperUnloaded(Player player, Follower fol #region UnlockRoutine [MethodImpl(MethodImplOptions.NoInlining)] - protected override IEnumerator UnlockRoutine_DzhakeHelperLoaded(Follower fol) + protected IEnumerator UnlockRoutine_DzhakeHelperLoaded(Follower fol) { SoundEmitter emitter = SoundEmitter.Play(unlockSfxName, this); emitter.Source.DisposeOnTransition = true; @@ -373,7 +377,7 @@ protected override IEnumerator UnlockRoutine_DzhakeHelperLoaded(Follower fol) } [MethodImpl(MethodImplOptions.NoInlining)] - protected override IEnumerator UnlockRoutine_DzhakeHelperUnloaded(Follower fol) + protected IEnumerator UnlockRoutine_DzhakeHelperUnloaded(Follower fol) { SoundEmitter emitter = SoundEmitter.Play(unlockSfxName, this); emitter.Source.DisposeOnTransition = true; From bca0075c2f48e6dc8b73f1d0846119a6f7aada1a Mon Sep 17 00:00:00 2001 From: wuke32767 <2446214230@qq.com> Date: Fri, 15 Nov 2024 19:16:51 +0800 Subject: [PATCH 7/8] then what's the point of two delegates --- Source/Entities/LockBlocks/BaseLockBlock.cs | 65 +++++--------------- Source/Entities/LockBlocks/DreamLockBlock.cs | 14 +++-- 2 files changed, 27 insertions(+), 52 deletions(-) diff --git a/Source/Entities/LockBlocks/BaseLockBlock.cs b/Source/Entities/LockBlocks/BaseLockBlock.cs index 6eaf9f7..f418ed7 100644 --- a/Source/Entities/LockBlocks/BaseLockBlock.cs +++ b/Source/Entities/LockBlocks/BaseLockBlock.cs @@ -60,12 +60,20 @@ public BaseLockBlockComponent(Solid This, EntityData data, Vector2 offset, Entit : base(true, true) { RealEntity = This; - OnPlayer_DzhakeHelperLoaded = default_OnPlayer_DzhakeHelperLoaded; - OnPlayer_DzhakeHelperUnloaded = default_OnPlayer_DzhakeHelperUnloaded; - TryOpen_DzhakeHelperLoaded = default_TryOpen_DzhakeHelperLoaded; - TryOpen_DzhakeHelperUnloaded = default_TryOpen_DzhakeHelperUnloaded; - UnlockRoutine_DzhakeHelperLoaded = default_UnlockRoutine_DzhakeHelperLoaded; - UnlockRoutine_DzhakeHelperUnloaded = default_UnlockRoutine_DzhakeHelperUnloaded; + if (MoreLockBlocksModule.Instance.DzhakeHelperLoaded) + { + OnPlayer = default_OnPlayer_DzhakeHelperLoaded; + UnlockRoutine = default_UnlockRoutine_DzhakeHelperLoaded; + TryOpen = default_TryOpen_DzhakeHelperLoaded; + } + else + { + OnPlayer = default_OnPlayer_DzhakeHelperUnloaded; + UnlockRoutine = default_UnlockRoutine_DzhakeHelperUnloaded; + TryOpen = default_TryOpen_DzhakeHelperUnloaded; + } + + ID = id; RealEntity.DisableLightsInside = false; @@ -113,19 +121,7 @@ protected internal static Sprite BuildCustomSprite(string spritePath) #region OnPlayer - protected internal void OnPlayer(Player player) - { - if (MoreLockBlocksModule.Instance.DzhakeHelperLoaded) - { - OnPlayer_DzhakeHelperLoaded(player); - } - else - { - OnPlayer_DzhakeHelperUnloaded(player); - } - } - - protected internal Action OnPlayer_DzhakeHelperLoaded; + protected internal Action OnPlayer; [MethodImpl(MethodImplOptions.NoInlining)] protected internal virtual void default_OnPlayer_DzhakeHelperLoaded(Player player) { @@ -148,7 +144,6 @@ protected internal virtual void default_OnPlayer_DzhakeHelperLoaded(Player playe } } - protected internal Action OnPlayer_DzhakeHelperUnloaded; [MethodImpl(MethodImplOptions.NoInlining)] protected internal virtual void default_OnPlayer_DzhakeHelperUnloaded(Player player) { @@ -169,19 +164,7 @@ protected internal virtual void default_OnPlayer_DzhakeHelperUnloaded(Player pla #endregion #region TryOpen - protected internal void TryOpen(Player player, Follower fol) - { - if (MoreLockBlocksModule.Instance.DzhakeHelperLoaded) - { - TryOpen_DzhakeHelperLoaded(player, fol); - } - else - { - TryOpen_DzhakeHelperUnloaded(player, fol); - } - } - - protected internal Action TryOpen_DzhakeHelperLoaded; + protected internal Action TryOpen; [MethodImpl(MethodImplOptions.NoInlining)] protected internal virtual void default_TryOpen_DzhakeHelperLoaded(Player player, Follower fol) { @@ -202,7 +185,6 @@ protected internal virtual void default_TryOpen_DzhakeHelperLoaded(Player player RealEntity.Collidable = true; } - protected internal Action TryOpen_DzhakeHelperUnloaded; [MethodImpl(MethodImplOptions.NoInlining)] protected internal virtual void default_TryOpen_DzhakeHelperUnloaded(Player player, Follower fol) { @@ -222,19 +204,7 @@ protected internal virtual void default_TryOpen_DzhakeHelperUnloaded(Player play #endregion #region UnlockRoutine - protected internal IEnumerator UnlockRoutine(Follower fol) - { - if (MoreLockBlocksModule.Instance.DzhakeHelperLoaded) - { - yield return new SwapImmediately(UnlockRoutine_DzhakeHelperLoaded(fol)); - } - else - { - yield return new SwapImmediately(UnlockRoutine_DzhakeHelperUnloaded(fol)); - } - } - - protected internal Func UnlockRoutine_DzhakeHelperLoaded; + protected internal Func UnlockRoutine; [MethodImpl(MethodImplOptions.NoInlining)] protected internal virtual IEnumerator default_UnlockRoutine_DzhakeHelperLoaded(Follower fol) { @@ -293,7 +263,6 @@ protected internal virtual IEnumerator default_UnlockRoutine_DzhakeHelperLoaded( RealEntity.RemoveSelf(); } - protected internal Func UnlockRoutine_DzhakeHelperUnloaded; [MethodImpl(MethodImplOptions.NoInlining)] protected internal virtual IEnumerator default_UnlockRoutine_DzhakeHelperUnloaded(Follower fol) { diff --git a/Source/Entities/LockBlocks/DreamLockBlock.cs b/Source/Entities/LockBlocks/DreamLockBlock.cs index 2803e5a..5105546 100644 --- a/Source/Entities/LockBlocks/DreamLockBlock.cs +++ b/Source/Entities/LockBlocks/DreamLockBlock.cs @@ -257,10 +257,16 @@ public DreamLockBlock(EntityData data, Vector2 offset, EntityID id) : base(data, SurfaceSoundIndex = 11; dummyBelow = data.Bool("below", false); dummyIgnoreInventory = data.Bool("ignoreInventory", false); - component.TryOpen_DzhakeHelperLoaded = TryOpen_DzhakeHelperLoaded; - component.TryOpen_DzhakeHelperUnloaded = TryOpen_DzhakeHelperUnloaded; - component.UnlockRoutine_DzhakeHelperLoaded = UnlockRoutine_DzhakeHelperLoaded; - component.UnlockRoutine_DzhakeHelperUnloaded = UnlockRoutine_DzhakeHelperUnloaded; + if (MoreLockBlocksModule.Instance.DzhakeHelperLoaded) + { + component.TryOpen = TryOpen_DzhakeHelperLoaded; + component.UnlockRoutine = UnlockRoutine_DzhakeHelperLoaded; + } + else + { + component.TryOpen = TryOpen_DzhakeHelperUnloaded; + component.UnlockRoutine = UnlockRoutine_DzhakeHelperUnloaded; + } } public override void Added(Scene scene) From 0d30d2673b26041b6054be3a8e99e091d8102b9d Mon Sep 17 00:00:00 2001 From: wuke32767 <2446214230@qq.com> Date: Fri, 15 Nov 2024 19:16:51 +0800 Subject: [PATCH 8/8] finished? --- Source/Entities/LockBlocks/BaseLockBlock.cs | 10 +- Source/Entities/LockBlocks/DreamLockBlock.cs | 23 +- .../Entities/LockBlocks/DreamLockBlockV2.cs | 235 ++++++++++++++++++ Source/MoreLockBlocksModule.cs | 2 + 4 files changed, 268 insertions(+), 2 deletions(-) create mode 100644 Source/Entities/LockBlocks/DreamLockBlockV2.cs diff --git a/Source/Entities/LockBlocks/BaseLockBlock.cs b/Source/Entities/LockBlocks/BaseLockBlock.cs index f418ed7..9c3cdb4 100644 --- a/Source/Entities/LockBlocks/BaseLockBlock.cs +++ b/Source/Entities/LockBlocks/BaseLockBlock.cs @@ -55,6 +55,8 @@ public struct OpeningSettings protected internal readonly string unlockSfxName; + private PlayerCollider playerCollider; + public BaseLockBlockComponent(Solid This, EntityData data, Vector2 offset, EntityID id, string defaultSpriteID = "MoreLockBlocks_generic_lock", string defaultUnlockSfx = "event:/game/03_resort/key_unlock") //: base(data.Position + offset, 32f, 32f, false) : base(true, true) @@ -77,7 +79,7 @@ public BaseLockBlockComponent(Solid This, EntityData data, Vector2 offset, Entit ID = id; RealEntity.DisableLightsInside = false; - RealEntity.Add(new PlayerCollider(OnPlayer, new Circle(60f, 16f, 16f))); + RealEntity.Add(playerCollider = new PlayerCollider(OnPlayer, new Circle(60f, 16f, 16f))); RealEntity.Add(Sprite = string.IsNullOrWhiteSpace(overrideSpritePath = data.Attr("spritePath", "")) ? MoreLockBlocksGFX.SpriteBank.Create(defaultSpriteID) : BuildCustomSprite(overrideSpritePath)); Sprite.Play("idle"); @@ -299,6 +301,12 @@ protected internal virtual IEnumerator default_UnlockRoutine_DzhakeHelperUnloade RealEntity.RemoveSelf(); } + internal void Remove() + { + playerCollider.RemoveSelf(); + Sprite.RemoveSelf(); + } + #endregion } } \ No newline at end of file diff --git a/Source/Entities/LockBlocks/DreamLockBlock.cs b/Source/Entities/LockBlocks/DreamLockBlock.cs index 5105546..f3f5cd8 100644 --- a/Source/Entities/LockBlocks/DreamLockBlock.cs +++ b/Source/Entities/LockBlocks/DreamLockBlock.cs @@ -16,9 +16,20 @@ namespace Celeste.Mod.MoreLockBlocks.Entities { [Tracked] - [CustomEntity("MoreLockBlocks/DreamLockBlock")] + [CustomEntity("MoreLockBlocks/DreamLockBlock=Load")] public class DreamLockBlock : LegacyBaseLockBlock { + public static Entity Load(Level level, LevelData levelData, Vector2 offset, EntityData entityData) + { + if (MoreLockBlocksModule.PatchLoaded) + { + return new DreamLockBlockV2(entityData, offset, new EntityID(levelData.Name, entityData.ID)); + } + else + { + return new DreamLockBlock(entityData, offset, new EntityID(levelData.Name, entityData.ID)); + } + } [TrackedAs(typeof(DreamBlock))] internal class DreamBlockDummy : DreamBlock { @@ -121,6 +132,11 @@ public IEnumerator DummyUnlockRoutine() public static void Load() { + if (MoreLockBlocksModule.PatchLoaded) + { + DreamLockBlockV2.Load(); + return; + } IL.Celeste.DreamBlock.Added += DreamBlock_Added; On.Celeste.DreamBlock.Activate += DreamBlock_Activate; On.Celeste.DreamBlock.FastActivate += DreamBlock_FastActivate; @@ -139,6 +155,11 @@ public static void Load() public static void Unload() { + if (MoreLockBlocksModule.PatchLoaded) + { + DreamLockBlockV2.Unload(); + return; + } IL.Celeste.DreamBlock.Added -= DreamBlock_Added; On.Celeste.DreamBlock.Activate -= DreamBlock_Activate; On.Celeste.DreamBlock.FastActivate -= DreamBlock_FastActivate; diff --git a/Source/Entities/LockBlocks/DreamLockBlockV2.cs b/Source/Entities/LockBlocks/DreamLockBlockV2.cs new file mode 100644 index 0000000..a0a7982 --- /dev/null +++ b/Source/Entities/LockBlocks/DreamLockBlockV2.cs @@ -0,0 +1,235 @@ +using Celeste.Mod.DzhakeHelper; +using Celeste.Mod.DzhakeHelper.Entities; +using Celeste.Mod.Entities; +using Microsoft.Xna.Framework; +using Monocle; +using MonoMod; +using MonoMod.RuntimeDetour; +using System; +using System.Collections; + +namespace Celeste.Mod.MoreLockBlocks.Entities +{ + [CustomEntity("MoreLockBlocks/DreamLockBlock")] + [TrackedAs(typeof(DreamBlock))] + internal class DreamLockBlockV2 : DreamBlock + { + readonly bool ignoreInventory; + BaseLockBlockComponent component; + bool unlocked; + public DreamLockBlockV2(EntityData data, Vector2 offset, EntityID id) + : base(data.Position + offset, 32, 32, null, false, false, data.Bool("below", false)) + // : base(data, offset, id, defaultUnlockSfx: MoreLockBlocksSFX.game_lockblocks_dreamlockblock_key_unlock) + { + Add(component = new BaseLockBlockComponent(this, data, offset, id, defaultUnlockSfx: MoreLockBlocksSFX.game_lockblocks_dreamlockblock_key_unlock)); + SurfaceSoundIndex = 11; + ignoreInventory = data.Bool("ignoreInventory", false); + if (MoreLockBlocksModule.Instance.DzhakeHelperLoaded) + { + component.UnlockRoutine = UnlockRoutine_DzhakeHelperLoaded; + } + else + { + component.UnlockRoutine = UnlockRoutine_DzhakeHelperUnloaded; + } + } + public override void Added(Scene scene) + { + if (MoreLockBlocksModule.Session.UnlockedDreamLockBlocks.Contains(component.ID)) + { + unlocked = true; + component.Remove(); + } + base.Added(scene); + } + public override void Render() + { + base.Render(); + //:sobeline: + Entity_Render(this); + } + [MonoModLinkTo("Monocle.Entity", "System.Void Render()")] + private static void Entity_Render(Entity self) + { + throw new NotImplementedException(); + } + + private const float chargeUpDuration = 6f, unlockDuration = 0.25f, chargeDownDuration = 0.1f; + + public IEnumerator DummyUnlockRoutine() + { + if (!Activated) + { + yield break; + } + Level level = SceneAs(); + Input.Rumble(RumbleStrength.Light, RumbleLength.Long); + Add(shaker = new Shaker(true, delegate (Vector2 s) + { + shake = s; + })); + shaker.Interval = 0.02f; + + for (float percent = 0f; percent < 1f; percent += Engine.DeltaTime / chargeUpDuration) + { + whiteFill = Ease.CubeIn(percent); + yield return null; + } + UpdateNoRoutine(); // in some cases, this will not be called. + shaker.On = false; // so better to close it manually. + + whiteHeight = 1f; + whiteFill = 1f; + for (float percent = 1f; percent > 0f; percent -= Engine.DeltaTime / unlockDuration) + { + whiteHeight = percent; + Glitch.Value = percent * 0.2f; + if (level.OnInterval(0.1f)) + { + for (int i = 0; i < Width; i += 4) + { + level.ParticlesFG.Emit(Strawberry.P_WingsBurst, new Vector2(X + i, Y + Height * whiteHeight + 1f)); + } + } + if (level.OnInterval(0.1f)) + { + level.Shake(); + } + Input.Rumble(RumbleStrength.Strong, RumbleLength.Short); + yield return null; + } + whiteHeight = Glitch.Value = 0f; + + while (whiteFill > 0f) + { + whiteFill -= Engine.DeltaTime / chargeDownDuration; + yield return null; + } + } + + IEnumerator UnlockRoutine_DzhakeHelperLoaded(Follower fol) + { + SoundEmitter emitter = SoundEmitter.Play(component.unlockSfxName, this); + emitter.Source.DisposeOnTransition = true; + Level level = SceneAs(); + + Key key = fol.Entity as Key; + CustomKey key2 = fol.Entity as CustomKey; + if (key is not null) + { + Add(new Coroutine(key.UseRoutine(Center + new Vector2(0f, 2f)))); + } + else if (key2 is not null) + { + Add(new Coroutine(key2.UseRoutine(Center + new Vector2(0f, 2f)))); + } + yield return 1.2f; + + component.UnlockingRegistered = true; + if (component.stepMusicProgress) + { + level.Session.Audio.Music.Progress++; + level.Session.Audio.Apply(); + } + MoreLockBlocksModule.Session.UnlockedDreamLockBlocks.Add(component.ID); + if (key is not null) + { + key.RegisterUsed(); + + while (key.Turning) + { + yield return null; + } + } + else if (key2 is not null) + { + key2.RegisterUsed(); + DzhakeHelperModule.Session.CurrentKeys.RemoveAll(info => info.ID.ID == key2.ID.ID); + + while (key2.Turning) + { + yield return null; + } + } + + Tag |= Tags.TransitionUpdate; + //Collidable = false; + unlocked = true; + emitter.Source.DisposeOnTransition = false; + Add(new Coroutine(DummyUnlockRoutine())); + SurfaceSoundIndex = 12; + yield return component.Sprite.PlayRoutine("open"); + + level.Shake(); + Input.Rumble(RumbleStrength.Medium, RumbleLength.Medium); + yield return component.Sprite.PlayRoutine("burst"); + + } + + IEnumerator UnlockRoutine_DzhakeHelperUnloaded(Follower fol) + { + SoundEmitter emitter = SoundEmitter.Play(component.unlockSfxName, this); + emitter.Source.DisposeOnTransition = true; + Level level = SceneAs(); + + Key key = fol.Entity as Key; + Add(new Coroutine(key.UseRoutine(Center + new Vector2(0f, 2f)))); + yield return 1.2f; + + component.UnlockingRegistered = true; + if (component.stepMusicProgress) + { + level.Session.Audio.Music.Progress++; + level.Session.Audio.Apply(); + } + MoreLockBlocksModule.Session.UnlockedDreamLockBlocks.Add(component.ID); + key.RegisterUsed(); + while (key.Turning) + { + yield return null; + } + + Tag |= Tags.TransitionUpdate; + //Collidable = false; + unlocked = true; + emitter.Source.DisposeOnTransition = false; + Add(new Coroutine(DummyUnlockRoutine())); + SurfaceSoundIndex = 12; + yield return component.Sprite.PlayRoutine("open"); + + level.Shake(); + Input.Rumble(RumbleStrength.Medium, RumbleLength.Medium); + yield return component.Sprite.PlayRoutine("burst"); + } + static Hook patch; + internal static void Load() + { + patch = new Hook(typeof(DreamBlock).GetProperty(nameof(DreamBlock.Activated)).GetMethod, static (Func orig, DreamBlock self) => + { + bool o = orig(self); + if (self is DreamLockBlockV2 v2) + { + if (!v2.unlocked) + { + return false; + } + if (v2.ignoreInventory) + { + return v2.unlocked; + } + } + return o; + }); + + } + + internal static void Unload() + { + patch?.Dispose(); + } + } +} + + + + diff --git a/Source/MoreLockBlocksModule.cs b/Source/MoreLockBlocksModule.cs index 3ac43a0..234e335 100644 --- a/Source/MoreLockBlocksModule.cs +++ b/Source/MoreLockBlocksModule.cs @@ -9,6 +9,8 @@ namespace Celeste.Mod.MoreLockBlocks; public class MoreLockBlocksModule : EverestModule { + public static readonly bool PatchLoaded = typeof(DreamBlock).GetField("DreamBlockPatch", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) is not null; + public static MoreLockBlocksModule Instance { get; private set; } public override Type SettingsType => typeof(MoreLockBlocksModuleSettings);