Skip to content

Conversation

wjt
Copy link
Member

@wjt wjt commented Jan 29, 2025

Commit 87c31b0 ("Warn when Block Code overrides parent script") introduced a warning when a BlockCode node's parent has a script attached. But if the parent is (for example) a Character2D with our SimpleCharacter script attached, this warning is incorrect: the block code script will correctly extend, not override, the parent.

Before issuing this warning, check if the parent's script has a class_name that matches what the generated BlockCode script will extend, and suppress the warning if so.

Fixes #356

@wjt wjt requested a review from manuq January 29, 2025 11:56
@wjt
Copy link
Member Author

wjt commented Jan 29, 2025

I made a test scene with the 4 cases:

  1. BlockCode attached to SimpleCharacter
  2. BlockCode attached to node with custom script with a class_name that the block code plugin doesn't know about
  3. BlockCode attached to node with custom script with no class_name
  4. BlockCode attached to node with no script

Before:

image

After:

image

Commit 87c31b0 ("Warn when Block Code
overrides parent script") introduced a warning when a BlockCode node's
parent has a script attached. But if the parent is (for example) a
Character2D with our SimpleCharacter script attached, this warning is
incorrect: the block code script will correctly extend, not override,
the parent.

Before issuing this warning, check if the parent's script has a
class_name that matches what the generated BlockCode script will extend,
and suppress the warning if so.

Fixes #356
@wjt wjt force-pushed the push-msnptorpnqrl branch from 13caf74 to 055fce7 Compare January 29, 2025 11:58
if get_parent().script:
warnings.append("This BlockCode will override the existing script in the parent node.")
var parent_script_name: StringName = get_parent().script.get_global_name()
if not (parent_script_name and block_script and parent_script_name == block_script.script_inherits):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@manuq manuq merged commit 18c8de5 into main Jan 29, 2025
3 checks passed
@manuq manuq deleted the push-msnptorpnqrl branch January 29, 2025 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A CodeBlock should not be allowed to attach to a node that has a script attached already

2 participants