ID:1845070
 
I was playing around on a project and came across a problem that needed me to hide/remove individual objects from clients on a per-client basis (kind of like roofs). Here is what I came up with.

Any comments/critiques are more than welcome! :)

atom/movable
var
mask/mask

proc/HideMask(client/c) // Hides the mask image, making the object visible to a certain client

// debug info to make testing and bug fixing easier if we screw up implementation
if(!istype(c, /client)) CRASH("Invalid client([c]) in [src].HideMask()")

c.RemoveMask(mask.mask_image)

proc/ShowMask(client/c) // Create a mask if it doesn't exist, making the object invisible to a certain client

// debug info to make testing and bug fixing easier if we screw up implementation
if(!istype(c, /client)) CRASH("Invalid client([c]) in [src].ShowMask()")

// recycle the image for multiple clients
if(!mask)
mask = new/mask(src, c)

c.AddMask(mask.mask_image)

image/mask

mask

var/image/mask/mask_image // a unique path to make synching client.images easier

New(atom/movable/am, client/c)

// debug info to make testing and bug fixing easier if we screw up implementation
if(!istype(c, /client)) CRASH("Invalid client([c]) in new /mask([am], [c])")

// create a new mask image, this lets us 'cover up' or 'hide' each object individually
mask_image = new(icon = null, loc = am)
mask_image.override = 1


client
var masks[]

New()
..()
masks = new

// Various client procs to handle the masks

proc/SyncMasks() // Synchs the masks list with images list and cleans up un-needed masks
images.Remove(masks)
for(var/image/mask/i in images)
images.Remove(i)
images.Add(masks)


proc/AddMask(image/i) // Adds a mask to masks list and synchs images
if(!(i in masks))
masks.Add(i)
SyncMasks()

proc/RemoveMask(image/i) // Removes a mask to masks list and synchs images
if(masks.Remove(i))
SyncMasks()

proc/ClearMasks() // Clears all masks from the client and synchs
masks = list()
SyncMasks()



mob
verb
// Some verbs to test implementation
Mask_Item(atom/movable/m in view())

m.ShowMask(client)


Unmask(atom/movable/m in view())

m.HideMask(client)

ClearMasks()

client.ClearMasks()


Disclaimer: I'm not much of a programmer, but there you have it! haha
kind of like roofs

Nice shoutout. ;P
The concept is basically the same as yours, although this is a very simple implementation I came up with.

On the project I'm working on, this is being used to hide different levels of a house, to allow for the visibility of multiple floors.

I still have to add in a fade effect for it (which I'll probably skim your example for ideas on). :P

If you're looking for gratification: Thanks to Ter13 for the inspiration for this idea!!!
If you're looking for gratification

I was actually just joking around.
I wasn't. Thanks for the legwork. I probably wouldn't have come up with this on my own.
if(!locate(i in masks)) should be if(!(i in masks)).

The former shouldn't work at all, always evaluating to true.

locate(x, y, z)
locate(tag)
locate(ref)
locate(path) in container
Thanks for pointing that out! I changed the code up top.