Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: [MODDING] Flip Weapon Sprites  (Read 1835 times)

Armithaig

  • Lieutenant
  • **
  • Posts: 54
    • View Profile
    • Amaranth
[MODDING] Flip Weapon Sprites
« on: August 28, 2019, 10:38:32 AM »

'Ello!

Would it be entirely outta the realm of possibility to add an option for flipping/mirroring weapon sprites to ship files, thinkin' something like this.
Code
"weaponSlots": [{
        "angle": 0,
        "arc": 0,
        "id": "WS 001",
        "locations": [
            -6,
            14
        ],
        "mount": "HARDPOINT",
        "size": "SMALL",
        "type": "UNIVERSAL",
        "flip": "HORIZONTAL" <----
}]

Example use-case fighter.

Snagged the hardpoint sprite for the left weapon, turret sprite for the right, borked coordinates be damned. Alternatively'd have merged 'em into a single multi-barrel weapon, ignoring the paltry "1x Plasma Bomb Launcher" in the codex/tooltip. Last option's making two entirely separate weapons just for the changed sprite, skewed only slightly too far towards lazy for that (maybe a weapon .skin system).
But neither'll fly for anything the player can remount.

Thank you for your seemingly unceasing hard work!

Edit: test if edits broken
« Last Edit: November 19, 2019, 07:48:49 AM by Armithaig »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: [MODDING] Flip Weapon Sprites
« Reply #1 on: August 28, 2019, 11:44:55 AM »

IIRC someone wrote a script that did this either for specific weapons or mounts, but I'm not sure where to find it.
Logged

Wyvern

  • Admiral
  • *****
  • Posts: 3786
    • View Profile
Re: [MODDING] Flip Weapon Sprites
« Reply #2 on: August 28, 2019, 07:26:53 PM »

That was me, it doesn't work perfectly, and you can find the details here: http://fractalsoftworks.com/forum/index.php?topic=15118
Logged
Wyvern is 100% correct about the math.

Wyvern

  • Admiral
  • *****
  • Posts: 3786
    • View Profile
Re: [MODDING] Flip Weapon Sprites
« Reply #3 on: August 28, 2019, 09:19:48 PM »

Actually - Alex, would it help de-complicate the needed fix if I pointed out that this script doesn't need a non-null CombatEngineAPI?  (I mean, okay, the way I wrote it it does, but that was because I copied someone else's boilerplate.  The actual operation of the script doesn't reference the combat engine at all.)
Logged
Wyvern is 100% correct about the math.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: [MODDING] Flip Weapon Sprites
« Reply #4 on: August 29, 2019, 01:14:52 PM »

Hmm. Couple of things there: first off, it should already work in the refit screen, no? The ship's advance() method gets called with an "amount" of 0.0001f from the refit screen. Maybe the engine.isPaused() check in the script is preventing it.

Also: it seems like you could do this from the constructor of the script, since by the time that's created, the weapon sprites already exist.
Logged

Wyvern

  • Admiral
  • *****
  • Posts: 3786
    • View Profile
Re: [MODDING] Flip Weapon Sprites
« Reply #5 on: August 29, 2019, 01:19:12 PM »

As for the refit screen: It doesn't work in the ship list to the left, but it does work in the main display of the selected ship.  There and in combat are the only places it does work.

That said, I am curious to try putting it in the script constructor - I hadn't thought to try that.
Logged
Wyvern is 100% correct about the math.

Wyvern

  • Admiral
  • *****
  • Posts: 3786
    • View Profile
Re: [MODDING] Flip Weapon Sprites
« Reply #6 on: August 29, 2019, 05:11:45 PM »

Ah, no, putting it in the constructor isn't workable - there's no reference to the WeaponAPI object there.
Logged
Wyvern is 100% correct about the math.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: [MODDING] Flip Weapon Sprites
« Reply #7 on: August 29, 2019, 08:34:51 PM »

Ah, right, makes sense. Let me see if I can maybe add an init() method... no promises though :)
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: [MODDING] Flip Weapon Sprites
« Reply #8 on: August 30, 2019, 01:21:30 PM »

IIRC, I ran into two problems with this concept, which I implemented in Vacuum a long time ago.  I think it's kind of curious how my code got referred to, "as somebody's boilerplate", rather than crediting the source, but I suppose I was "naively breaking things" at the time, rather than boldly demonstrating a concept.  Ahem.

So, the problems with the concept code, as they existed then, were serious, and remain unaddressed.

1.  It wasn't possible to move the firepoints via code.  This screwed up anything where the weapons were offset in the Y or X (i.e., most multi-barrel setups).

2.  Centerlines obviously have the problem that there is no, "right answer".  A weapon should therefore have mirrored right/left setups, ideally, and a centerline setup as well.

3.  Off-center firepoints, not being mobile, also meant serious problems.

Now, some of that could actually be worked around, with some fancy code rebuilding the offsets, perhaps, and instantly removing / rebuilding projectiles on birth, perhaps.  I think that would cause various troubles.

Anyhow, the code has no issues with frames as written:

Code
public class weaponSide implements EveryFrameWeaponEffectPlugin {
    private boolean runOnce = false;
   
    @Override
    public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon){
        if(runOnce == false){
            if (weapon.getShip().getOwner() == 0 && weapon.getLocation().getX() < weapon.getShip().getLocation().getX()
                || weapon.getShip().getOwner() == 1 && weapon.getLocation().getX() > weapon.getShip().getLocation().getX()){
                SpriteAPI theSprite = weapon.getSprite();
                theSprite.setWidth(-theSprite.getWidth());
                theSprite.setCenter(-theSprite.getCenterX(),theSprite.getCenterY());
            }
            runOnce = true;
        }
    }
}

The issues are purely functional, frankly.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Wyvern

  • Admiral
  • *****
  • Posts: 3786
    • View Profile
Re: [MODDING] Flip Weapon Sprites
« Reply #9 on: August 30, 2019, 02:33:38 PM »

Lol?  No, the boilerplate I referenced was the return if combat engine paused bit, that the script absolutely didn't need.

Sorry, Xeno, but the reason I didn't credit you is that, in point of fact, nothing of yours was referenced.  Credit for the starting point I was working from goes to Tecrys and Tartiflette.
Edit: Apparently Tecrys' work on this was, in fact, based on code originally written by Xenoargh.

Besides, we can move firing points now (though the code I posted didn't bother - I wanted just the visual component to demonstrate the flaws there).  Also, your code is wrong - it doesn't mirror all of the sprites and its method of determining what side of the ship a weapon is on is buggy.  Perhaps you'd benefit from actually looking at the thread I linked earlier rather than leaping to assumptions?  Here's the link again, in case you missed it: http://fractalsoftworks.com/forum/index.php?topic=15118

As such, the only remaining issue with weapon mirroring is that it only works in combat or in the refit main screen, but not in any ship list - such as the fleet screen, or when looking over enemy ships on an encounter screen.

Hopefully if Alex adds an init() method, that will fix that?
« Last Edit: September 14, 2023, 09:00:52 AM by Wyvern »
Logged
Wyvern is 100% correct about the math.

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: [MODDING] Flip Weapon Sprites
« Reply #10 on: August 30, 2019, 07:35:23 PM »

Quote
we can move firing points now (though the code I posted didn't bother
How, though?  There's no method in WeaponAPI to do that, so far as I know. 

WeaponSpecAPI returns the list of Vector2's, but you can't change them; that's just telling us what's in the static data.

That's why I abandoned this, ages ago; being able to change the static point positions (and angles, in really odd cases) was necessary.  So it was never more than a "yeah, kind of works but..." kind of thing, back then.
« Last Edit: August 30, 2019, 07:39:05 PM by xenoargh »
Logged
Please check out my SS projects :)
Xeno's Mod Pack

MesoTroniK

  • Admiral
  • *****
  • Posts: 1731
  • I am going to destroy your ships
    • View Profile
Re: [MODDING] Flip Weapon Sprites
« Reply #11 on: August 30, 2019, 07:54:16 PM »

But we can change fire and angle offsets...

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: [MODDING] Flip Weapon Sprites
« Reply #12 on: January 20, 2021, 04:22:45 PM »

Another necro as I dig deeper into the TODO stack - added a WeaponEffectPluginWithInit interface; if an EveryFrameWeaponEffectPlugin also implements this, the init() method will get called when the weapon is created.
Logged

Wyvern

  • Admiral
  • *****
  • Posts: 3786
    • View Profile
Re: [MODDING] Flip Weapon Sprites
« Reply #13 on: January 20, 2021, 07:01:02 PM »

Marvelous! Much appreciated.
Logged
Wyvern is 100% correct about the math.