ID:1886957
 
Code:
WriteToOlay(var/atom/m,var/a="Huh",var/lc=0,var/uc=0,var/b as color,var/scale=0,var/fontie='FiraMono8pt_AA2.dmi',var/out=0)
var/g=a
var/leftspot=round((length(g)/2)*-3.65)
for(var/i=1,i<=length(g),i++)
var/obj/N=new/obj/name
N.icon=fontie
N.layer=m.layer+1
N.pixel_x=leftspot+lc
N.pixel_y+=uc
N.icon_state="[copytext(g,i,i+1)]"
if(scale)
var/matrix/z=new
z.Scale(0.5,0.5)
N.transform=z
N.color=b
if(out)
outline_textX(N)
m.overlays+=N
leftspot+=N:wid
//version 2 is...?
ImgToOlay(var/atom/m,var/atom/v,var/a="Huh",var/lc=0,var/uc=0,var/b as color,var/scale=0,var/fontie='FiraMono8pt_AA2.dmi',var/out=0)
var/g=a
var/leftspot=round((length(g)/2)*-3.65)
var/obj/x=new
for(var/i=1,i<=length(g),i++)
var/obj/N=new/obj/name
N.icon=fontie
N.layer=m.layer+1
N.pixel_x=leftspot+lc
N.pixel_y+=uc
N.icon_state="[copytext(g,i,i+1)]"
if(scale)
var/matrix/z=new
z.Scale(0.5,0.5)
N.transform=z
N.color=b
if(out)
outline_textX(N)

leftspot+=N:wid
var/image/h=image(x,m)
m.overlays+=h
v<<h//this doesn't seem to work.


Problem description:
I'm trying to convert this proc *which writes to an atom's overlay* into a proc that converts all text into a single image which can then be applied for only the intended viewer.

Basically this is used similiar to how NESTALIA does their screen objects *one object for all to use, but info that is player specific*.


You never actually mentioned the problem.

But a few pointers anyway:

icon_text
parent_type = /image
New(loc,text,icon,scale)
var/obj/letter = new()
letter.icon = icon
letter.layer = FLOAT_LAYER
var/matrix/M = matrix()
for(var/count=1;count<=length(text);count++)
letter.icon_state = text2ascii(text,count) //not sure if this works entirely.
M.c += LETTER_WIDTH
letter.transform = M
overlays += letter
M = matrix(scale,0,-scale*M.c/2-HALF_ICON_WIDTH,0,scale,0)
transform = M


A lot of your stuff could be moved outside of the loop, rather than inside. outline_text should be done after all the letters are added, not for each letter. That way you only have to duplicate the appearance 4 times rather than 4*N times.

Further, scaling should be done after the construction of the overlays, not during.

Also there's no need to create an object per letter every iteration. We can recycle the same object for each letter because the objects won't persist, only their appearance will be used.
In response to Ter13
Y u so smart?
Thanks for the pointers. What I'm having trouble with is 1 making the icon an image and applying that image to the object i want to apply it to. For some reason it's not working as I'd like.
1 making the icon an image and applying that image to the object i want to apply it to.

Images aren't icons. Icons aren't images. These are entirely different concepts.

An image is assigned to an object by setting the image's location to the object that you want to show the image on, or override instead.

Further, to see an image, it has to be output to a client. (Thereby adding it to the client's images list.)

For this reason, I really don't recommend using images at all, but instead using regular old atoms in the client's screen.
In response to Ter13
I'm using images for an efficiency "thing".
Basically what I'm trying to do is instead of having an atom generated for each menu in the game, to just have one menu then apply an image to it.

I'm pretty aware that icons and images are different. I don't really think you understood fully what I meant.
I want to apply an image to an object-that's basically what the image proc does.

Nothing more nothing less. I just can't seem to get it to show up properly.
Images actually incur a performance hit compared to normal atoms.

You save nothing, and actually cost yourself performance and complicate your reference maintenance by using images. My advice would be only to use images for what images were designed for: Differentiating the view at the client level in the world.

If it goes on the client's screen, it shouldn't ever be an image, because images fundamentally don't make sense if they already belong to a specified client.

I want to apply an image to an object-that's basically what the image proc does.

Yes and no. You are suffering a misapprehension of how the image() function works. Images are movable atoms. Whatever their loc is, is what the image appears on/in place of. Image() is just a shorthand override for image creation with specified data, and part of that specified data is the location of the image.

If you are using images, you need to explicitly show that image to the client you want the effect to show up for by using either:

client.images += image_ref


or:

client << image_ref


Again, though, this severely complicates reference maintenance, and in your specific case, you very probably don't need these to be images at all.
Originally I just applied it to the overlay-but I found some of the techniques I've been using a bit wasteful.

I had 4 objects per menu and approximately 6 menus per player so one player had 24 some odd objects at their disposal that were only used occasionally.

The idea was to just have the world create one set, then let all players use that, then apply an image for the text that needed to be displayed upon that object *or overlay of the object* which seemed less wasteful and hopefully also faster which was the end goal.

BUT considering all you've told me I may just..allow the players to have one extra object called TxtDescription or something, and update that the way I've been doing it. Either way I've significantly decreased the number of stray objects I have floating around.
The idea was to just have the world create one set, then let all players use that, then apply an image for the text that needed to be displayed upon that object *or overlay of the object* which seemed less wasteful and hopefully also faster which was the end goal.

Actually, that sounds like a fairly reasonable use for images. Though, it's going to restrict you from having differently sized viewports per player.
In response to Ter13
I decided to just go with objects due to your advice + it turned out to be more hassle than it's worth-and I limited a great number of the objects I had to create as well. I think I'm down to perhaps 2-3 per player, the rest are generated once by the game on world.New()

I think that's pretty acceptable!