Where to place new graphic images...

Started by jabbamonkey, November 05, 2014, 10:39:47 AM

Previous topic - Next topic

skullywag

Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

jabbamonkey

Quote from: skullywag on February 19, 2015, 03:00:38 AM
what graphic class you using?
<graphicClass>Graphic_Random</graphicClass>

I just copied the Items_Resources.xml and Various_Stone.xml from the core, and changed the path. So it "should" theoretically be working. Below is PART of the Items_Resources.xml file that mentions steel...

<ThingDef ParentName="ResourceBase">
    <defName>Steel</defName>
    <label>steel</label>
    <description>An iron-carbon metal alloy used for building structures, tools, and weapons.</description>
    <graphicPath>Things/Item/Resource/Metal/Steel</graphicPath>
    <graphicClass>Graphic_Random</graphicClass>
    <soundInteract>Metal_Drop</soundInteract>
    <soundDrop>Metal_Drop</soundDrop>
    <statBases>
      <MarketValue>2.0</MarketValue>
    </statBases>
    <useStandardHealth>false</useStandardHealth>
    <defaultColor>(255,255,255)</defaultColor>
    <thingCategories>
      <li>ResourcesRaw</li>
    </thingCategories>
    <stuffProps>
      <categories>
        <li>Metallic</li>
      </categories>
      <constructEffect>ConstructMetal</constructEffect>
      <color>(102,102,105)</color>
      <soundImpactStuff>BulletImpactMetal</soundImpactStuff>
      <statFactors>
        <MaxHealth>1</MaxHealth>
        <Beauty>1</Beauty>
        <Flammability>0.2</Flammability>
        <MeleeWeapon_SharpDamageMultiplier>1</MeleeWeapon_SharpDamageMultiplier>
        <MeleeWeapon_BluntDamageMultiplier>1</MeleeWeapon_BluntDamageMultiplier>
        <MeleeWeapon_Agility>1</MeleeWeapon_Agility>
      </statFactors>
    </stuffProps>
  </ThingDef>

skullywag

Deffo got the folder structure and letter casing right?
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

Wastelander

#33
Same exact thing happened to me, I have a graphic_random Filth object that can't find it's images since the update to A9 - worked fine in A8.

I think the change might be in the graphic_random class as graphic_single finds (any one) of the images just fine... I'll compare the two classes tonight and see if I can find what changed. If something did change there we should just be able to define our own graphic_random and use that (or just use the one from A8)

skullywag

Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

Wastelander

yeaaaah there's a bug here, graphic_collection queries the ContentFinder:

QuoteList<Texture2D> list = Enumerable.ToList<Texture2D>(ContentFinder<Texture2D>.GetAllInFolder(req.path));

That's returning a list, that's getting used a bit further down:

Quotethis.subGraphics = new Graphic[list.Count];
        for (int index = 0; index < list.Count; ++index)
        {
          string path = req.path + "/" + list[index].name;
          this.subGraphics[index] = GraphicDatabase.Get<Graphic_Single>(path, this.shader, this.drawSize, this.color);
        }

The problem is that it's not writing the filename to the Texture2D list, so it can never actually find the files in the mod... Not sure why this isn't affecting core, the actual bug is probably somewhere down in the mod content manager, but my eyes cross when I try to go too far into that with a decompiler.

I'm attaching a fix here, include this DLL side-by-side with your DLL and reference the BugFix version of the class:

Quote<graphicClass>BugFix.Graphic_Random</graphicClass>

To use this, have graphics named the same thing as the folder they're in, plus A, B, etc., because this patch will look for files under this naming scheme. For example, I have the following files:

Things/Filth/Graffiti/GraffitiA
Things/Filth/Graffiti/GraffitiB
Things/Filth/Graffiti/GraffitiC

And I'm referencing them from this XML:

Quote<ThingDef Name="BaseFilth" Abstract="True">
    <label>unspecified filth</label>
    <thingClass>Filth</thingClass>
    <eType>Filth</eType>
    <category>Filth</category>
    <altitudeLayer>Filth</altitudeLayer>
    <useStandardHealth>false</useStandardHealth>
    <drawerType>MapMeshOnly</drawerType>
    <shaderType>Transparent</shaderType>
    <graphicClass>BugFix.Graphic_Random</graphicClass>
  </ThingDef>


  <ThingDef ParentName="BaseFilth">
     <defName>FilthGraffiti</defName>
     <label>Graffiti</label>
      <statBases>
        <Beauty>-40</Beauty>
      </statBases>
     <graphicPath>Things/Filth/Graffiti</graphicPath>
    <filth>
           <cleaningWorkToReduceThickness>300</cleaningWorkToReduceThickness>
           <canFilthAttach>true</canFilthAttach>
        </filth>
  </ThingDef>
 

And it's working again in my mod. It will also print out at warning level on startup, telling you what files it's looking for, so you can adjust if you're unsure.

We'll probably also want to get this on Tynan's radar, anybody know how to raise a bug? :)

[attachment deleted due to age]

jabbamonkey

#36
Wow. This is definitely more advanced than I am. Thanks Wastelander for pointing this out. I created a post in the BUG forum referring to this thread - hopefully Tynan will look into correctly it.

Should I post the mod with the correction?  If Tynan fixes the issue, will it break the new "corrected" mod?


Also, please forgive my programming ignorance (as I'm a designer), but where do I place the dll file exactly?  And the "source.zip" is what you used to compile the dll, right? I don't need to add that to the mod, right?


Wastelander

Yeah, the source zip isn't necessary, to use this:
1) Create a folder named Assemblies in your mod folder
2) put the bugfix.dll there
3) In your XML, where you're using Graphic_Random, replace that with BugFix.Graphic_Random


jabbamonkey

Quote from: Wastelander on February 19, 2015, 11:14:31 PM
Yeah, the source zip isn't necessary, to use this:
1) Create a folder named Assemblies in your mod folder
2) put the bugfix.dll there
3) In your XML, where you're using Graphic_Random, replace that with BugFix.Graphic_Random

Hmmmmm ... I followed the instructions above, and still getting errors and red X boxes for the image...

The latest version of the mod can be download here (not working):
http://www.amazingdg.com/clients/SteelRockSlag2.zip

skullywag

Will have a look when im home in a few hours.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

Wastelander

If you use my little bugfix, you have to name the image files the same as the folder that contains them, so try renaming SteelA, SteelB, etc. to MetalA, MetalB.

You'll also want to change the paths in your XML if you do this.

When you start the game, the bug fix should print out what paths it's looking for image files in to the console (view the console by hitting ~, debug mode might have to be enabled in the game settings too).

Tynan

#42
Thanks greatly for the report, explanation, and example fix code. Clearly it's a bug deeper in the mod content loader. I'm investigating this now.

EDIT: It's fixed now (it was a bug in the content loader which didn't name assets coming from mods). I'm not sure there will be another hotfix but this'll be fixed for A10 at least. Thanks again.
Tynan Sylvester - @TynanSylvester - Tynan's Blog

jabbamonkey

Thanks Tynan.

I'm going to stop working on this until Alpha 10 then. It's too frustrating, and if I do fix it for Alpha 9, I only see myself having to fix it for Alpha 10.

Igabod

Thanks for the fix Tynan. And I see that you did indeed release the hotfix for it. Thanks for being so quick about it too. I can get back to work on updating my 2 mods that were affected by this.