Reading colors of elements externally

  • F03K
    20th May 2015 Member 0 Permalink

    I'm not sure if this goes here, and I'm very new to this C++ thing. (Doesn't everyone say that as their first post in a forum?)

     

    I have been attempting to read the colors of elements externally in C#. I have the basics of the element colors down: Element default colors, as well as support for PROP_HOT_GLOW.

     

    I apologize for anything that sounds odd or doesn't make sense (And my lack of common sense), I am more tired than I have been in a very long time. I honestly can't think straight. It would be miraculous if someone comes up with an answer I can understand before my meds wear off (so I can sleep).

     

    All I want to do is, given an element and the properties, determine the resulting color. (Assuming the "No Special Effects" box is ticked)

     

    So I am wondering how to get element-specific coloring rules, such as how WOOD turns blue when it is cold, and how ACID changes color based on its LIFE property.

    I could copy and convert the element-specific rules for every element over to C#, but that sounds like a lot of work. I could learn C++ (I do want to learn it, after all), but I can imagine that taking more effort than copying and converting to C#.

     

    Is there a way to do it without code?

     

    Is there a way to run C++ code through a C# program? Googling this shows I can make a wrapper for it, but I think I might need to know C++ to do this, and I don't understand how TPT's source works.

     

    Do any of you have advice or ideas?

  • Lord_Bowserinator
    20th May 2015 Member 0 Permalink

    @F03K (View Post) The element specific coloring rules are controlled through it's graphics update function. Are you reading the code or the exe? 

     

  • F03K
    20th May 2015 Member 0 Permalink

    I'm reading the code. That's probably the problem. I need to be running the code, or interpreting it. I don't know how to do either. Sure, compiling is a piece of cake, but I don't know how I should access the element-specific coloring rules. I have minimal experience with C++.

     

    For example, in ACID.cpp, it gives this:

     

    //#TPT-Directive ElementHeader Element_ACID static int graphics(GRAPHICS_FUNC_ARGS)
    int Element_ACID::graphics(GRAPHICS_FUNC_ARGS)
    {
    int s = cpart->life;
    if (s>75) s = 75; //These two should not be here.
    if (s<49) s = 49;
    s = (s-49)*3;
    if (s==0) s = 1;
    *colr += s*4;
    *colg += s*1;
    *colb += s*2;
    *pixel_mode |= PMODE_BLUR;
    return 0;
    }

     

    That means the ACID element has its color also based on its LIFE value.

    Externally, (Currently through C#), I need a way to get these sets of rules so my external program can determine the color output color based on the element and the properties I give it.

     

    The easiest way is probably to do something with C++, but then I need to learn it. I'm planning on learning it anyways, but I am impatient and obstinate.

  • Lord_Bowserinator
    20th May 2015 Member 0 Permalink

    It would be very hard to do programmiticlly with C#. You should learn C++, it's similar to C# (it just has somethings that are diffrent and it's a bit more complex) and you don't need to know too much to change/do whatever you want with this code. 

  • F03K
    20th May 2015 Member 0 Permalink

    Yeah, I figured as much. Thanks!

     

    The only problem is that I am so tired that I feel quite helpless to do anything. It is NOT a good feeling.

    Okay, I'll learn C++. 

     

    (Maybe for now I will just do the copy-paste-convert strategy though)

  • boxmein
    21st May 2015 Former Staff 0 Permalink
    There's two ways to do what you wanted to read the element parameters: the first being simple text search (eg a regex like /Colou?r\s*=\s*0x([0-9A-Fa-f]);\s*$/) will give you the first Colour = 0xFF0000 line, and the second somehow again compiling the constructor to observe the element instances' values.

    However, to take into account the graphics function, you would need to somehow compile the code (eg with tcc) and call the graphics function with different valid parameters.

    You could also do manual analysis of the color ranges each element can be in, writing down the changes to colr/g/b/a and firer/g/b/a throughout the execution of the program.
    Edited once by boxmein. Last: 21st May 2015
  • F03K
    22nd May 2015 Member 0 Permalink

    Yeah, I am using regular expressions for this. It doesn't well work will all the colors though.