MapColors() takes each pixel and effectively multiplies it by a matrix, like so:
              |rr rg rb ra  0|
              |gr gg gb ga  0|
|r g b a 1| × |br bg bb ba  0|
              |ar ag ab aa  0|
              |cr cg cb ca  1|
The rr through ra correspond to the first color in MapColors(), which says what red is mapped to; the second color argument is what green becomes, then third is what blue becomes, and so on. (cr through ca are a constant color added at the end.)

Calling MapColors() with three color arguments is basically saying what red, green, and blue will each become (before being added together), alpha will be left alone, and nothing else will be added.
Then, am I right in assuming that a pixel which is 23, 196, 45, would be considered "a shade of green", and therefore, only affected by gr, gg, and gb? If so, I'm lost by how your code, which uses the "Red Section" as a way to intensify colour, would work on a icon that doesn't classify as having "shades of red".
The gr, gg, gb values are what green becomes. Think of each number in the matrix as from-to. So br is what the old blue is multiplied by to contribute to the new red.

In the example I gave, col basically becomes rr, rg, rb. The white value is used for gr, gg, gb, and also for br, bg, bb. In the final icon, the red component of each pixel is (red*rr+green*gr+blue*br).
Hmm. I think I get it now, thanks to that final statement. For now, I'll tinker with this a little later today and get back with something to show later.
Okay. So it took me a bit to do this, but that's because I was doing the System from scratch and testing everything all through the process.

I am now however, at the main issue of getting the icons to be coloured in the way I wish.

I developed the following function to colour the object of an icon based on the code provided by Lummox:

obj
proc
SetColour(var/Colour)
var/mob/M = src.Holder
if(Colour == null && src.Colour)
Colour = src.Colour
M << output("No Colour found. New Colour: [src.Colour]", "System Output")
if(Colour)
var/Shine = 1
var/icon/I = src.icon
switch(Colour)
if("Fur", "Oak", "Silk", "Wool", "Ebony", "Linen", "Leather", "Lithium", "Obsidian")
Shine /= 5
if("Yew", "Pine", "Cedar", "Bronze", "Cobalt", "Mercury", "Platinum")
Shine /= 3
if("Iron", "Steel", "Pewter", "Basnium", "Mithril", "Adamantine")
Shine /= 2.25
M << output("Shine (Before Multiplication by 255): [Shine]", "System Output")
Shine = round(Shine * 255, 0.05)
M << output("Shine (After Multiplication by 255): [Shine]", "System Output")
Shine = rgb(Shine, Shine, Shine)
M << output("Shine (After rgb()): [Shine]", "System Output")
M << output("Colour: [Colours[Colour]]", "System Output")
I.MapColors(Colours[Colour], Shine, Shine)
src.Colour = Colour
src.icon = I


The "output" lines are so I can track the values of Shine and Colour to make sure I don't get something weird. Thus far, it seems fine enough. However, my icon is not being updated as intended:

The code where obj.SetColour(Colour) is called:
mob/proc
UpdateCraftingComponent(var/X, var/Component)
var/obj/Recipe = src.Target
if(src.Selection.len > 0)
if(src.ComponentsCheck(src.Selection[Component]))
var/obj/M = src.Selection[Component]
var/obj/Button/B = new (src)
B.SetColour(M.Colour)
B.icon_state = "[Recipe.Type]: [Component]"
src << output(B, "Component #[X]:1,1")
else
var/obj/Button/B = new (src)
B.icon_state = "[Recipe.Type]: [Component]"
src << output(B, "Component #[X]:1,1")
winset(src, "Component #[X]", "cells=1x1")


This function is called any time the Player drags a crafting material into the Component Location. By default, it's to have a picture of the component in it to show Players what's needed for it. That Component is what should be changing colour as a result, but that's not happening.
You showed the 'mob/SetColour()' proc, but you are calling 'obj/SetColour()' in your snippet. Are they the same?
In response to Zasif
Zasif wrote:
Have you tryed Craft Pro it provides all your dreams!

http://www.byond.com/developer/RedHallDev/Craft_Pro

Yoren wrote:
I've only read through the documentation of that link thus far, but I've seen nothing concerning the colouring of an object, and that's my main issue here.

Basically all you'd do is this.. It's not very complicated and probably much quicker than the time it takes to redo a crafting system and make it dynamically assign colors when all the colors are decided on before hand anyway.

obj/Item
Bronze_Ore
icon_state = "Bronze Ore"
stackable = 0
componentof = list(/obj/Item/Bronze_Bar)

Bronze_Bar
icon_state = "Bronze Bar"
stackable = 0

Bronze_Sword
icon_state = "Bronze Sword"
components = list(/obj/Item/Bronze_Bar = 1)
craftedAt = list(/obj/Station/Furnace)


Bronze_Shield
icon_state = "Bronze Shield"
components = list(/obj/Item/Bronze_Bar = 1)
craftedAt = list(/obj/Station/Furnace)


Sure you have to copy paste a few things but it's vastly more simple than colouring objects as you go. Coloring as I go is usually something I reserve for when making that number of icons would either be absurd or impossible or when I'm colouring things randomly.

I think the demo does everything you need unless you want to randomly colour things. Not to mention that once you've got your coloring code... That's just the smallest piece, now you have to build an entire craft system which will take days even if you're a fantastic programmer.

Craft Pro seems more than enough to do this but it's up to you. I didn't write it so that no one would ever have to write a crafting system ever again or anything but what evs.
Flick wrote:
You showed the 'mob/SetColour()' proc, but you are calling 'obj/SetColour()' in your snippet. Are they the same?

Sorry about that, that was meant to be obj.SetColour() in the code snippet. I had typed the "mob proc" part, myself instead of copy & paste by accident.

It's been updated and corrected to reflect the correct thing now.

Zecronious wrote:
Zasif wrote:
Have you tryed Craft Pro it provides all your dreams!

http://www.byond.com/developer/RedHallDev/Craft_Pro

Yoren wrote:
I've only read through the documentation of that link thus far, but I've seen nothing concerning the colouring of an object, and that's my main issue here.

Basically all you'd do is this.. It's not very complicated and probably much quicker than the time it takes to redo a crafting system and make it dynamically assign colors when all the colors are decided on before hand anyway.

> obj/Item
> Bronze_Ore
> icon_state = "Bronze Ore"
> stackable = 0
> componentof = list(/obj/Item/Bronze_Bar)
>
> Bronze_Bar
> icon_state = "Bronze Bar"
> stackable = 0
>
> Bronze_Sword
> icon_state = "Bronze Sword"
> components = list(/obj/Item/Bronze_Bar = 1)
> craftedAt = list(/obj/Station/Furnace)
>
>
> Bronze_Shield
> icon_state = "Bronze Shield"
> components = list(/obj/Item/Bronze_Bar = 1)
> craftedAt = list(/obj/Station/Furnace)
>

Sure you have to copy paste a few things but it's vastly more simple than colouring objects as you go. Coloring as I go is usually something I reserve for when making that number of icons would either be absurd or impossible or when I'm colouring things randomly.

I think the demo does everything you need unless you want to randomly colour things. Not to mention that once you've got your coloring code... That's just the smallest piece, now you have to build an entire craft system which will take days even if you're a fantastic programmer.

Craft Pro seems more than enough to do this but it's up to you. I didn't write it so that no one would ever have to write a crafting system ever again or anything but what evs.

Firstly, the code snippet you've shown me indicates that I'd still have to tweak the the system's "Components" list seems to function more as a "Required Material and Amount" list. Meaning, I'd either need to tweak it or add a new list to work with it or something else anyway.

Secondly, this conflicts with my own system of objects that I've already made, as I've separated between "Items", "Weapons", "Armour", "Clothing", etc, but some of them in each are still craft-able.

Thirdly, making a Crafting System is by no means inherently difficult. It all just depends on what a person wants to do and how well they understand what it is they're trying to do. Also, if you've read my last post before this, you would've seen that I've already made my Crafting System in the last 4/5 days and it all works fine except for colouring.

Fourthly and finally, I'm not going to use this just simply because it's easier. I'm not going to use it simply because it doesn't address my main issues with colouring, and will at its core, still cause me to have to do various things to make it work with everything already built in. There's nothing wrong with making something so people can use it as a library / CotS (Component off the Shelf) in their project, but you can't expect that it will work for / satisfy everyone.
*Bump*

It's been 4 days since I've made my last comment, and I was just trying to make sure I've not been forgotten.

My issue still persists as well.
I'm not at a computer I can test this with at the moment, but I seem to remember having issues trying to set an icon directly like var/icon/I = src.icon. Try, var/icon/I = icon(src.icon) and see if that works.
Yes, this is very incorrect:

var/icon/I = src.icon

You want I to be an /icon datum, but the atom's icon is actually a cache file. So you need to set I to icon(icon) or new(icon) instead.
In response to Yoren
The thing is, I could done all of this with my demo in 1 hour. 4/5 days is just unnecessary. I don't see how your craft system is any different from what I already did. It's possible you just don't understand how mine works and that's why you think it won't do what you want.


In response to Zecronious
You seem to think I spent 4/5 days just religiously working on the one system. Contrary to what you may believe, I have other responsibilities to attend to as well.

Secondly, did you read any of what I posted last in regards to your system, or are you just looking for a fight because someone refused to use your system? Furthermore, I could've very well changed how I've decided to do my own system since posting this originally, or even decided to code it myself so I can become familiar with some of Dream Maker's things; or had none of those possibilities even crossed your mind, simply because you took some blow to your ego for having someone not use your own library?

Finally, the main problem I was facing was (and still is) connected to colouring the crafted object. And like you yourself said, your code doesn't deal with it. So if you've nothing to contribute to solving that problem, I'm not sure why you're here, mate.
Can you store the determined colors before the object is crafted? Harder to modify something after it is already created, easier to store variables for it before it is made.
Lummox JR wrote:
Yes, this is very incorrect:

var/icon/I = src.icon

You want I to be an /icon datum, but the atom's icon is actually a cache file. So you need to set I to icon(icon) or new(icon) instead.

Yeah, after making this change, it works correctly. At least, the "testing phase" is. Now, I'm trying to have the 3 icons be blended together to create a image of how the finished icon will look. I've changed up the code a bit, so I'll be showing those changes in my next post.

AERProductions wrote:
Can you store the determined colors before the object is crafted? Harder to modify something after it is already created, easier to store variables for it before it is made.

Aye, that obj.Colour variable stores the colour of the object I intend for it to have. I then have a list of all colours and their hexadecimal values for use, which is that same list you see being used called, Colours.
The obj.SetColour(Colour) didn't receive any changes really. I just removed the text where I was desk-tracing the function.
obj
proc
SetColour(var/Colour)
if(!Colour && src.Colour)
Colour = src.Colour
if(Colour)
var/Shine = 1
var/icon/I = icon(src.icon)
switch(Colour)
if("Fur", "Oak", "Silk", "Wool", "Ebony", "Linen", "Leather", "Lithium", "Obsidian")
Shine /= 5
if("Yew", "Pine", "Cedar", "Bronze", "Cobalt", "Mercury", "Platinum")
Shine /= 3
if("Iron", "Steel", "Pewter", "Basnium", "Mithril", "Adamantine")
Shine /= 2.25
Shine = round(Shine * 255, 0.05)
Shine = rgb(Shine, Shine, Shine)
I.MapColors(Colours[Colour], Shine, Shine)
src.Colour = Colour
src.icon = I


The mob.UpdateCraftingComponent(X, Component) no longer calls the obj.SetColour(Colour) function. This code snippet is just to show that.
mob/proc
UpdateCraftingComponent(var/X, var/Component)
if(src.ComponentsCheck(src.Selection[Component], "Quantity"))
var/obj/M = src.Selection[Component]
src << output(M, "Component #[X]:1,1")
else
src << output(null, "Component #[X]:1,1")
winset(src, "Component #[X]", "cells=1x1")


The mob.UpdateCraftingObject() is where I'm now calling the obj.SetColour(Colour) function. This should give the Player a preview of the final look of the crafted object, by throwing together the pieces. It currently remains blank, however.
mob/proc
UpdateCraftingObject()
var/obj/O = src.Target
if(src.Selection.len > 0)
var/icon/Object
src << output("Test", "System Output")
for(var/Component in src.Selection)
var/obj/M = src.Selection[Component]
if(M)
var/obj/Button/Piece = new (src)
Piece.icon = 'Miscellaneous.dmi'
Piece.icon_state = "[O.Type]: [Component]"
Piece.SetColour(M.Colour)
var/icon/I = icon(Piece.icon)
if(!Object)
Object = I
else
Object.Blend(I, ICON_OVERLAY)
else
break
if(Object)
O.icon = Object
src << output(O, "Crafting Object:1,1")
winset(src, "Crafting Object", "cells=1x1")
winset(src, "Crafting Object Label", "text=\"[O.Type]\"")
*Bump*

It's been 5 days since I updated the code and displayed my newest problem with this system. Any input towards solving that would be greatly appreciated.
Having reviewed my code recently, I do genuinely believe my issue occurs at the "Object.Blend(I, ICON_OVERLAY)" line. As such, can someone explain to me how the icon.Blend() is supposed to work? I thought I understood it correctly from Lummox's snippet as well as the DM Reference, but I guess that might not be the case?
Actually, I think your issue is here:

var/icon/I = icon(Piece.icon)

It appears the icon you're using is a colored version of Miscellaneous.dmi, which contains multiple icon states. When you create the icon I, you're creating an editable version of that colored icon--but with all of the states.

I believe what you want instead is for I to only contain the one state you're using. Therefore:

var/icon/I = icon(Piece.icon, Piece.icon_state)

The result icon you've been getting is blank because you've been blending all of the states over all of the states, rather than one at a time on top of each other in a specific combination.
Oh!

You were right, cheers mate.

Now, I just need to get the final piece done which would allow for the crafted objects to be coloured across all icon states, so that while using the objects, the colour shows.

Fortunately, I think Lummox might've just touched on it:
Lummox JR wrote:
Actually, I think your issue is here:

var/icon/I = icon(Piece.icon)

It appears the icon you're using is a colored version of Miscellaneous.dmi, which contains multiple icon states. When you create the icon I, you're creating an editable version of that colored icon--but with all of the states.

I believe what you want instead is for I to only contain the one state you're using. Therefore:

var/icon/I = icon(Piece.icon, Piece.icon_state)

The result icon you've been getting is blank because you've been blending all of the states over all of the states, rather than one at a time on top of each other in a specific combination.

If I understand my error correctly, just using
var/icon/I = icon(Piece.icon)

causes each state of Piece.icon to be blended based on my code, correct?

Then, would this not accomplish what I need if it's done specifically for the icon of the crafted object?

EDIT: Actually, now that I've thought about it, that means having to make each icon state for each craftable object, in a very tedious manner:

"Longsword | Blade | Attack 1"
"Longsword | Blade | Attack 2"
"Longsword | Blade | Equipped"
.
.
.
"Longsword | Hilt | Attack 1"
.
.
and so on.

So yeah, I'd wish to avoid that.
Page: 1 2