Example of Usage:
PHP Code:
function onCreated()
{
join("managedobjectcontext");
this.entities = null;
// Setting up Party Variables
temp.eparty = loadEntity( "Party" );
if ( temp.eparty == null )
{
temp.eparty = createEntity( "Party" );
// Setting up variable configurations... { inverseRelationship, Multiple Items?, Delete Rule }
temp.eparty.setValueForKey( {null, false, null }, "configName" );
temp.eparty.setValueForKey( {null, false, null }, "configLeader" );
temp.eparty.setValueForKey( {"Party", true, "Cascade" }, "configRanks" );
temp.eparty.setValueForKey( "Party", "customClass" ); // Maybe you have special implementations! This joins class "Party" when creating a new instance!
// Adding a bind to a key... Members now is Ranks.Members
temp.eparty.addValueForKey( {"Members", "Ranks.Members"}, "binds" );
// There is also dependencies... But those are still a little complicated.
// They'll be further elaborated in future releases.
// temp.eparty.addDependency( "Members", "Ranks.Members" ); // It'll be something like that.
}
temp.erank = loadEntity( "Rank" );
if ( temp.erank == null )
{
temp.erank = createEntity( "Rank" );
temp.erank.setValueForKey( {null, true, null}, "configMembers" );
temp.erank.setValueForKey( {null, null, null}, "configRankSyntax" );
temp.erank.setValueForKey( {null, null, null}, "configRankName" );
temp.erank.setValueForKey( {null, true, null}, "configRankRights" );
temp.erank.setValueForKey( {"Ranks", false, null}, "configParty" );
}
// Creating New Party and add two ranks, three members...
// Please Note that each time this is executed, a new party of the same name is created.
temp.mparty = temp.eparty.createManagedObject();
temp.mparty.setValueForKey( "Pluffy's Gang", "Name" );
temp.mparty.setValueForKey( "Pluffy", "Leader" );
temp.mrank = temp.erank.createManagedObject();
temp.mrank.setValueForKey( "Leader", "RankName" );
temp.mrank.setValueForKey( "King %s", "RankSyntax" );
temp.mrank.setValueForKey( {"add", "remove"}, "RankRights" );
temp.mrank.setValueForKey( null, "Members" );
temp.mrank.addValueForKey( "Pluffy", "Members" );
temp.mrank.addValueForKey( "Gerami", "Members" );
temp.mrank.setValueForKey( temp.mparty, "Party" );
temp.mrank = temp.erank.createManagedObject();
temp.mrank.setValueForKey( "Humble Servant", "RankName" );
temp.mrank.setValueForKey( "Slave %s", "RankSyntax" );
temp.mrank.setValueForKey( null, "RankRights" );
temp.mrank.setValueForKey( null, "Members" );
temp.mrank.addValueForKey( "Novo", "Members" );
temp.mrank.setValueForKey( temp.mparty, "Party" );
// Now lets use it!
// Showing Ranks
temp.ranks = temp.mparty.valueForKeyPath( "Ranks.RankName" );
echo( temp.ranks ); // returns: {"Leader", "Humble Servant"};
// Showing Members Divided By Rank
temp.membersByRank = temp.mparty.valueForKeyPath( "Members" );
echo( temp.membersByRank ); // returns {{"Pluffy", "Gerami"}, {"Novo"}};
// Showing all Members
temp.allMembers = null;
for ( temp.rank: temp.membersByRank )
temp.allMembers.addarray( temp.rank );
echo( temp.allMembers ); // returns {"Pluffy", "Gerami", "Novo" };
echo("===");
// Delete a Rank!
for ( temp.rank: temp.mparty.valueForKey( "Ranks" ) )
{
if ( temp.rank.valueForKey("RankName") != "Humble Servant" )
continue;
temp.erank.deleteManagedObject( temp.rank );
}
// Showing Ranks
temp.ranks = temp.mparty.valueForKeyPath( "Ranks.RankName" );
echo( temp.ranks ); // returns: {"Leader"};
// Showing Members Divided By Rank
temp.membersByRank = temp.mparty.valueForKey( "Members" );
echo( temp.membersByRank ); // returns {{"Pluffy", "Gerami"}};
// Showing all Members
temp.allMembers = null;
for ( temp.rank: temp.membersByRank )
temp.allMembers.addarray( temp.rank );
echo( temp.allMembers ); // returns {"Pluffy", "Gerami" };
// Please note that thus far, it doesn't support saving / loading.
// This will be implemented at a later date.
// In the meantime -- avoid resetting NPC-Server!
}
Requires
http://forums.graalonline.com/forums...ad.php?t=73780
For those who are interested in what I was replicating... The original concept comes from...
http://developer.apple.com/documenta...ata/index.html
For the most part, things are very similar. How you set it up, however, isn't. The terminology, if you want further reference, can be found in the link above.
I hope the globals appreciate my links or else they can just remove it: Ignorance is Bliss, afterall.