//Title: Default Name for Datums
//Contributed by: Jtgibson
//Credit to: Jtgibson
named_datum
var/name
///// DEFAULT NAME CODE /////
//Parses the type path for the node name at the very end, and uses that
// to set the datum's name.
//To use this functionality, set the parent_type for your topmost datum
// that uses this feature to "named_datum". E.g., "parent_type = /named_datum"
New()
..()
DefaultName()
proc/DefaultName()
if(!initial(name))
var/typestring = "[type]"
//If you want objects with names in initial capitals (e.g.,
// "Sword of Lochaber" instead of "sword of lochaber") then download
// my Title Capitalisation Snippet, uncomment the next line, and
// comment out the line above this.
//var/typestring = title_caps("[type]")
var/lastpos = 0
var/found = findtext(typestring,"/")
while(found > 0)
lastpos = found+1
found = findtext(typestring,"/",lastpos)
name = copytext(typestring,lastpos)
found = findtext(name,"_")
while(found > 0)
//Copy the text before and after the underscore and paste it
// on either side of a space, effectively deleting the underscore.
name = "[copytext(name,1,found)] [copytext(name,found+1)]"
found = findtext(name,"_")
return name
///*
//Testing code/sample implementation:
normal_datum
parent_type = /datum //unnecessary line, but here for comparison
special_datum
parent_type = /named_datum
mob/verb/test_named_datum()
var/normal_datum/datum1 = new
usr << "datum1's type: [datum1.type]"
var/special_datum/datum2 = new
usr << "datum2's type: [datum2.type]"
usr << "datum1's name: [datum1]"
usr << "datum2's name: [datum2]"
//Note well: datum1 doesn't have a name variable. I'm relying upon the
// integral BYOND behaviour of displaying the datum's 'type' variable
// as its name whenever the datum is embedded directly into a sentence.
//*/
ID:195115
Nov 21 2006, 7:03 am
|
|