r/ProgrammerHumor • • Apr 10 '23

Meme god why is coding chess so hard

Post image
67.4k Upvotes

1.8k comments sorted by

View all comments

Show parent comments

4

u/RuneLFox Apr 10 '23

Interestingly with that one, I think I have a good guess at what the point of it is. I imagine it's to do with layering and having certain hairstyles over or under pieces of the uniform. That said...there's got to be better ways of doing it...

3

u/remind_me_later Apr 11 '23 edited Apr 25 '23

Just the code given allows for some improvements:

If the order is critical (which it likely is):

int femaleUniform = StudentGlobals.FemaleUniform;
var femaleUniformTexture = this.FemaleUniformTextures[femaleUniform];
this.MyRenderer.sharedMesh = this.FemaleUniforms[femaleUniform];
var textureOrderMap = femaleUniform switch
{
    1             => (true,  false, false, true),
    2 or 6        => (true,  true,  false, false),
    3 or 4 or 5   => (false, false, true,  true),
    _             => (false, false, false, false),
};
this.MyRenderer.materials[0].mainTexture = textureOrderMap.Item1 ? femaleUniformTexture : this.HairTexture;
this.MyRenderer.materials[1].mainTexture = textureOrderMap.Item2 ? femaleUniformTexture : this.HairTexture;
this.MyRenderer.materials[2].mainTexture = textureOrderMap.Item3 ? femaleUniformTexture : this.HairTexture;
this.MyRenderer.materials[3].mainTexture = textureOrderMap.Item4 ? femaleUniformTexture : this.HairTexture;

The last 4 lines could be swapped out for a single 3-line for loop if you want to use an array instead of a tuple for textureOrderMap:

for (int i = 0; i < textureOrderMap.Length; i++){
    this.MyRenderer.materials[i].mainTexture = textureOrderMap[i] ? femaleUniformTexture : this.HairTexture;
}

If older C# versions can only be used, the translation from the above to the older versions is trivial. I only wrote like this because I'm too lazy to use the older versions of C#.

Edit: more eye-pleasing code formatting for textureOrderMap switch.