Skip to content

Support for composite targets in target pipeline #2000

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

Open
pokey opened this issue Nov 5, 2023 · 1 comment
Open

Support for composite targets in target pipeline #2000

pokey opened this issue Nov 5, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@pokey
Copy link
Member

pokey commented Nov 5, 2023

The problem

Every modifier stage in our pipeline takes a single target as input and outputs a list of targets. The pipeline runner performs a flatmap at each stage: each input target is passed separately through the stage, yielding a list of targets, and then we concatenate these output lists corresponding to each input target, giving us a flat output list. That flat list then becomes the input for the next stage

This behaviour is usually what you want. However, there are situations in which it is helpful to maintain a deeper hierarchy. For example:

function aaa() {
   const item = aaaList[0];
   const result = aaaAction(item);
}

function bbb() {
   const item = aaaList[0];
   const result = aaaAction(item);
}

function ccc() {
   const item = aaaList[0];
   const result = aaaAction(item);
}

Notice how the first function has been cloned twice, with only the name changed. For each function, we'd like to bring the function name to every instance of aaa in the given function.

In this case, you might want to say something like "from every funk bring name to every instance air". Unfortunately, the "bring" command will complain that there are 3 sources, but 7 destinations, so they can't be zipped.

The solution

We create a modifier modifier that will cause its modifier not to get flatmapped. One possible approach that might work is to create a composite target that corresponds to a list of targets. Assuming we call this modifier modifier "layered". Then the above command would be "from every funk bring name to layered every instance air". Then "layered every instance" would return one composite target for each of its inputs, rather than returning a list of multiple targets for each input, that would then get flatmapped.

For now these composite targets could just throw an exception if you tried to use them for anything but constructing a destination (is this related to #1631?). When you construct a destination from a composite target, the constructChangeEdit function would just construct an edit that applies the change to all of the constituent targets. Alternately, if for some reason that doesn't work, we could make "bring" aware of this kind of destination, and it could handle the situation in its broadcasting code, where it's basically a broadcast from 1 to 2 dimensions, rather than today's 0 to 1 dimension (scalar to list).

Discussion points

  • Spoken form: "layered"? An alternative is "deep", but I was imagining that "deep every" would be a version of "every" that includes nested scopes
  • What term should we use when discussing modifier modifiers?
@pokey pokey added the enhancement New feature or request label Nov 5, 2023
@rokubop
Copy link

rokubop commented Nov 5, 2023

Additional example (simplified a little from discussion on discord, in the previous example there was "north" on more things):

Goal: bring forth word of the function name to every instance of the second word of the doc string within the respective function

def fps_compass_go_north_relative():
    """Go north relative to current position"""
    global compass_offset, compass_anchor
    delta  = compass_anchor - compass_offset
    win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, delta, 0)
    compass_offset = 0
    set_last_action("compass_north")

def fps_compass_go_west_relative():
    """Go north relative to current position"""
    global compass_offset
    x360 = settings.get("user.fps_calibrate_x_360")
    dx = -int(x360/4)
    compass_offset += dx
    win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, dx, 0)
    set_last_action("compass_north")

def fps_compass_go_east_relative():
    """Go north relative to current position"""
    global compass_offset
    x360 = settings.get("user.fps_calibrate_x_360")
    dx = int(x360/4)
    compass_offset += dx
    win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, dx, 0)
    set_last_action("compass_north")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

No branches or pull requests

2 participants