Skip to content

added construct_proccode function #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 20, 2025
Merged

added construct_proccode function #457

merged 11 commits into from
Aug 20, 2025

Conversation

itsaethrr
Copy link
Contributor

ive added a build_proccode function. hopefully it works.

btw, im new to github so sorry about all unnecessary changes to files like readme where i added one line. idk how to fix it or not pull request that file but ig ill learn :p

itsaethrr and others added 8 commits August 12, 2025 00:53
Signed-off-by: itsaethrr <[email protected]>
Signed-off-by: itsaethrr <[email protected]>
Signed-off-by: itsaethrr <[email protected]>
Signed-off-by: itsaethrr <[email protected]>
Signed-off-by: itsaethrr <[email protected]>
Signed-off-by: itsaethrr <[email protected]>
Signed-off-by: itsaethrr <[email protected]>
Signed-off-by: faretek <[email protected]>
@FAReTek1
Copy link
Collaborator

FAReTek1 commented Aug 16, 2025

I removed the line from the README.

This still needs:

  • Basic testing
  • Fix comment style/informality

But otherwise yes. For some reason I thought I had implemented this previously, but I appreciate that people are able to build upon scratchattach.editor, as I wanted it to be cleaner that project_json_capabilities.py

@FAReTek1 FAReTek1 changed the title added build_proccode function added construct_proccode function Aug 16, 2025
@itsaethrr
Copy link
Contributor Author

itsaethrr commented Aug 16, 2025

I removed the line from the README.

This still needs:

  • Basic testing
  • Fix comment style/informality

But otherwise yes. For some reason I thought I had implemented this previously, but I appreciate that people are able to build upon scratchattach.editor, as I wanted it to be cleaner that project_json_capabilities.py

I've tested it with dummy classes and it works, but ofc you can test it and make the necessary changes :p thanks

@FAReTek1
Copy link
Collaborator

I'll try this now

- docstring
- use isinstance() not hasattr()
- add support for ArgumentType instance
- caching and defaulting for Argument._type and Argument.mutation
@FAReTek1
Copy link
Collaborator

FAReTek1 commented Aug 20, 2025

I've changed the code a lot. I think that isinstance() checks are a lot better than hasattr() when possible, and I've changed the docstring. And I see now that the mutation code structure is a bit of a mess because there a lot of classes which are not documented, so it is easy to get confused.

I also made construct_proccode use *args, which means you can pass in as many args as you want

I've also fixed a few unrelated bugs, and edited parse_proccode() so that this is a pure inverse of it.

How i tested it

# This loads a project, looks at all procedure 'definition' proccodes, parses them, then constructs a new proccode.
# When I ran this, the original proccode and the new proccode were equivalent, which means that construct_proccode works as an inverse to parse_proccode
# This also constructs a proccode in a different way at the end


from scratchattach import editor

proj = editor.Project.from_sb3("test proj.sb3")
sprite = proj.find_sprite("Sprite1")

for block in sprite.blocks.values():
    if block.opcode == "procedures_prototype":
        parsed = editor.parse_proc_code(block.mutation.proc_code)
        unparsed = editor.construct_proccode(*parsed)

        print(block.mutation.proc_code)
        print(parsed)
        print(unparsed)
        print('-' * 10)


print(
    editor.construct_proccode(
        "say",
        editor.ArgTypes.BOOLEAN,
        editor.Argument("hey", _type=editor.ArgTypes.NUMBER_OR_TEXT.value),
        "aa"
    )
)

@FAReTek1 FAReTek1 self-requested a review August 20, 2025 15:41
@FAReTek1 FAReTek1 merged commit bc36270 into TimMcCool:main Aug 20, 2025
@itsaethrr
Copy link
Contributor Author

alr, I didn't help much but yea lol

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.

2 participants