[A17] CompFX (Tool for Modders)

Started by CannibarRechter, October 02, 2017, 06:59:57 AM

Previous topic - Next topic

CannibarRechter

Hi,

I am releasing a new graphics tool called CompFX. It allows modders, using XML only, to attach a "comp" to any ThingWithComps in order to achieve an overlay effect (including animated overlays). It supports a very wide variety of overlays. It also supports UNDERLAYS. Proper use of the comp usually involves a patch, like this:


<Operation Class="PatchOperationAdd">
<xpath>*/ThingDef[defName = "FueledStove"]/comps</xpath>
<value>
<li Class="CR.CompProperties_FXOverlay">
<fxType>FX_Flash</fxType> <!-- optional, defaults to FX_Flash -->
<fxPath>FX/RedLight</fxPath> <!-- REQUIRED -->
<fxSize>1</fxSize> <!-- optional, defaults to 1 -->
<fxAbove>true</fxAbove>             <!-- optional, defaults to true -->
<fxTicks>10</fxTicks> <!-- optional, defaults to 60 -->
<fxAmount>5</fxAmount> <!-- required for some FX, see individual FX descr -->
<fxOption1>30</fxOption1> <!-- required for some FX, see individual FX descr -->
<fxOption2>0.2</fxOption2> <!-- required for some FX, see individual FX descr -->
<fxDependency>Fueled</fxDependency> <!-- optional, defaults to None -->
<fxOffset>(0,0,0.1)</fxOffset> <!-- optional, defaults to (0,0,0) -->
</li>
</value>
</Operation>


Documentation is included in the Examples/Example.xml directory. However, the basic gist of it is that CompFX supports the following FX types:


fxType (enum, default FX_Overlay):

FX_Overlay, // the effect is just to overlay the thing, that is all
FX_Flash,      // the effect is to appear and dissapear @fxTicks interval
FX_Animate,      // the effect is to overlay images in sequence @fxTicks interval
FX_Flicker, // the effect is random frames @fxTicks interval
FX_Spin,     // the effect is to spin around the middle; spin fxAmount (degrees) @fxTicks rate
FX_SpinJitter, // the effect is to periodically spin in a random direction and portion of @fxAmount (degrees) @fxTicks rate
FX_Pulse, // the effect is to grow and shrink by fxAmount @fxTicks rate
FX_Pop, // the effect is to grow--by fxAmount @fxTicks rate--and then start over
FX_Fade, // the effect is to fade in and out of transparency
FX_Mote         // the effect is animates versions of the frame into the air, like smoke


This is a tool for modders who want to graphically touch up rimworld. This mod makes use of one Harmony call in order to check to see if a work location has been worked at. This helps the tool able to satisfies the "Worked" dependency type. For example, you might have a stove smoke extra if it's been worked at. Currently supported dependencies are Powered, Fueled, Worked, and None.

For additional info see the Examples.xml file.

The download is found by following the link in my sig.

Version 1.1 Release Notes:

-Addressed significant performance defect with FX_Mote
-Added triggered (event based) FX

Version 1.2 Release Notes:

--Addressed an off-by-1 error that prevented the Worked signal from processing until after work stopped
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

swefan

You're a genius of coding, I've tried to create some effects and everything works perfectly.
But I can not create an effect, FX_Fade seems the most suitable for that, but I would that the effect will be repeated only once, starting from the transparency and reached the maximum opacity it should disappear without the transition effect.
Other thing, but maybe I ask for the impossible, I would like to tie the effect to a certain event, for example refueling a machine, or creating an object with that machine, in short a sort of switch. It's possible with your tool?
Thanks

CannibarRechter

#2
The entire system is predicate on an ongoing effect of some sort, not just display it once. That said, it wouldn't really be a big change to allow the FX to be triggered. Thing is, I don't know how to get a hold of game events, and get them to comps.

Looking at ThingWithComps right now, I see it has a BroadcastCompSignal and ReceiveCompSignal methods. I think comps can be programmed to communicate with other comps that way.

As for your FX type (fade in, but not out), that's easily programmed. It's exactly analagous to the logic difference between Pulse (grow and shrink) and Pop (grow and start over).

The Refuelable already broadcasts a signal, and so does Powered. That means all I have to do is implement the Receive, and I'll get it. I need to go read all the other comps now.

Here are all signals broadcast by Rimworld:



RimWorld\CompBreakdownable.cs:77:            this.parent.BroadcastCompSignal("Breakdown");
RimWorld\CompFlickable.cs:61:                    this.parent.BroadcastCompSignal("FlickedOn");
RimWorld\CompFlickable.cs:65:                    this.parent.BroadcastCompSignal("FlickedOff");
RimWorld\CompPowerTrader.cs:85:                    this.parent.BroadcastCompSignal("PowerTurnedOn");
RimWorld\CompPowerTrader.cs:100:                    this.parent.BroadcastCompSignal("PowerTurnedOff");
RimWorld\CompRefuelable.cs:225:                this.parent.BroadcastCompSignal("RanOutOfFuel");
RimWorld\CompRefuelable.cs:242:            this.parent.BroadcastCompSignal("Refueled");
RimWorld\CompRefuelable.cs:284:                        this.<>f__this.parent.BroadcastCompSignal("Refueled");
RimWorld\CompRefuelable.cs:293:                        this.<>f__this.parent.BroadcastCompSignal("Refueled");
RimWorld\CompSchedule.cs:35:                this.parent.BroadcastCompSignal((!this.intAllowed) ? "ScheduledOff" : "ScheduledOn");
RimWorld\CompTemperatureRuinable.cs:65:                    this.parent.BroadcastCompSignal("RuinedByTemperature");
Verse\ThingWithComps.cs:120:        public void BroadcastCompSignal(string signal)
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

CannibarRechter

Hi, I looked over this all last night before going to bed. This should be really easy to implement, and I will get an updated version of it out soon. It was actually helpful to look at, because it will make my "Worked" dependency easier to manage.
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

swefan

#4
Great!! I love your tool, this is what I did today, a custom fire animation for my pyre (PS the refuel icon is horrible)


A question, the textures for the glow effects are still unmoddable or I doing something wrong? The only one thath I tested that shows a new texture is the glow of the fires

CannibarRechter

Check Moddable for the ability to change out the Refuel icon. All you have to do is install Moddable, go to the XML and enable the ModdableUI def. After that, just place the texture you want in $MOD/Textures/UI/Overlays/OutOfFuel.

In any case, all FX should be working, so if you think something's not, post the CompFX XML you used, and tell me how you did it.

BTW, some building types don't draw in real time (they 'paint' instead). To check this, go to the Building or its Base, and see if the drawerType is "MapMeshOnly". For CompFX to render those, I believe you have to change it to something like "MapMeshAndRealtime," but you should verify the spelling on that before trying it.

CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

CannibarRechter

#6
Okay. I have a rudimentary test version up and am debugging it. It currently supports any signal type the game delivers (or any signal type a future modder creates: signals are plain text). The format is as follows:


  <li Class="CR.CompProperties_FXOverlayTriggered">
<fxType>FX_Fade</fxType>
<fxPath>FX/BlastFlame</fxPath>
<fxSize>3</fxSize>
<fxTicks>300</fxTicks>
<fxAmount>1</fxAmount>
<fxOption1>-1</fxOption1>
<fxTriggerDurationTicks>300</fxTriggerDurationTicks>
<fxTriggerDelayTicks>300</fxTriggerDelayTicks>
<fxTriggerSignal>FlickedOn</fxTriggerSignal>
  </li>


You'll see this new def is an extension of the old, with 3 additional attributes.

triggerDuration: how long the signal makes the effect trigger
triggerDelay: how long after the signal the effect should start
signalName: the name of the signal

On a related note, I implemented some new fade types tonite: fade-in and fade-out. They are implemented as options to the FX_FadeEffect, which by default uses a sin curve of simulation ticks.

I have a bug or two so far, so I have to work on that, but you'll have something to play with soon. Any modder who is making a custom comp, all they have to is call their parent Thing with parent.BroadcastCompSignal( "somesignalname" ) and with that, you can trigger any effect of the new signal. Literally 1 line of code.

Pretty neat; surprised signals aren't used more than they are.

In other news, it's pretty funny watching big fireballs blow off anytime a pawn turns on a light switch. LOL.
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

swefan

Great!! This opens at an infinity of possible effects and combinations, I already have many interesting ideas, shame I don't have enough time.
About the glow effect, I can't find it in your tool, it should be a simply effect, an image  that overlaps everything without any animated effect, with the option to choose its rgbA value.
A curiosity, there is a limit on the number of frames for the animations?

CannibarRechter

I see what you mean about glow. That would be a bit tricky to implement, as I assume you mean the glow would follow the shape of the object, which would therefore require detailed calculations for procedural effect. Not sure if I wanna do that.

You can actually create this effect right now. Grab your original art, load it up into Gimp or Photoshop, create your glow, and then put it on your Thing as an FX_Overlay. You might want to set fxAbove to false, depending on how you want the glow to work.

Regarding animations, the answer is 'no,' caveat the amount of memory they consume of course.
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

swefan

QuoteI assume you mean the glow would follow the shape of the object

No no... I know this would be hard to do, and useless since is very easy make custom glow texture

QuoteYou can actually create this effect right now. Grab your original art, load it up into Gimp or Photoshop, create your glow, and then put it on your Thing as an FX_Overlay. You might want to set fxAbove to false, depending on how you want the glow to work.

I thought that FXOverlay was only for call an effect... not an effect itself... , I have to read your descriptions more carefully  :P
so:

<li Class="CR.CompProperties_FXOverlay">
<fxType>FX_Overlay</fxType>
<fxPath>FX/Glowone</fxPath>
<fxSize>1</fxSize>
<fxAbove>false</fxAbove>
                                <fxDependency>Fueled</fxDependency>
<fxOffset>(0,0,0)</fxOffset>
   


CannibarRechter

Yeah, FX_Overlay is a basic static effect. Just display the pixels, and no more. Obviously you can put them over or under the Thing. Note also that the effects are rendered with a shaderType=Transparent, so alpha effects should work just fine.

p.s. FX_Overlay is the effect I started with. ;-P
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

CannibarRechter

#11
Updated to 1.1:

-Fixed a performance defect from FX_Mote
-Added triggered FX
-Updated documentation to explain the new triggers
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

swefan

Hi, I can't get the signal "Worked" to works in a Building_WorkTable with an "animate" overlay,  log always return an error about the "fxSignal" something like "fxsignal is expected Line" (always indicate a position after </li>)
I have tried different solutions but nothing..

for example I have this working effect with a fueled dependency, as I said before I want to replace the fueled dependency with a worked signal, how to convert it properly? Also, maybe the WorkedAt dependency was perfect? I have never tried it but I've read in yours description that you have disabled this dependency, and it seems to me perfect for an effect that must be activated (and last) only when a colonist works in that building

  <li Class="CR.CompProperties_FXOverlay">
<fxType>FX_Animate</fxType>
<fxPath>FX/SatanFire</fxPath>
<fxSize>7</fxSize>
<fxTicks>8</fxTicks>
<fxDependency>Fueled</fxDependency>
<fxOffset>(0.0,0,-0.005)</fxOffset>
  </li>


Thanks     ;)

CannibarRechter

Look in the examples. The overlay Class= type is slightly different. The base class can't accept fxSignal, but the modified class can. BTW, I'm working a bug this weekend which makes the worked signal display a bit late.
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

swefan

Well, as I said I tried different solutions but nothing
The new class overlay is CR.CompProperties_FXOverlayTriggered ? I tried even that
there must be some stupid mistake on my part