Docs: Difference between revisions
Appearance
→Functions: More functions |
Dat Hack3r (talk | contribs) m Added page to Documentation category. |
||
(6 intermediate revisions by 3 users not shown) | |||
Line 3,009: | Line 3,009: | ||
!Related code | !Related code | ||
|- | |- | ||
|api_chat_send | |api_chat_send(message,opts) | ||
|Sends a chat message from the user running code | |Sends a chat message from the user running code | ||
|<syntaxhighlight lang="js"> | |<syntaxhighlight lang="js"> | ||
api_chat_send("Hello!"); | api_chat_send("Hello!",{nick:"nickname"}); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|<syntaxhighlight lang="js" line="1" start="75"> | |<syntaxhighlight lang="js" line="1" start="75"> | ||
Line 3,059: | Line 3,059: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |- | ||
|clientChatResponse | |clientChatResponse(message) | ||
|Creates a client-side message only visible to you | |Creates a client-side message only visible to you | ||
|<syntaxhighlight lang="js"> | |<syntaxhighlight lang="js"> | ||
Line 3,070: | Line 3,070: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |- | ||
|sendChat | |sendChat() | ||
|Sends whatever is in the chat textbox to chat. | |Sends whatever is in the chat textbox to chat. | ||
|<syntaxhighlight lang="js"> | |<syntaxhighlight lang="js"> | ||
Line 3,087: | Line 3,087: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |- | ||
|updateUnread | |updateUnread() | ||
|Updates the unread messages counter when chat is closed. | |Updates the unread messages counter when chat is closed. | ||
| | | | ||
Line 3,114: | Line 3,114: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |- | ||
|event_on_chat | |event_on_chat(data) | ||
|Updates the unread messages counter for either global chat or the current page. | |Updates the unread messages counter for either global chat or the current page. | ||
| | | | ||
Line 3,131: | Line 3,131: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |- | ||
|moveCaretEnd | |moveCaretEnd(elm) | ||
|Moves the text cursor to the end of the chat message you want to type in the textbox. | |Moves the text cursor to the end of the chat message you want to type in the textbox. | ||
| | | | ||
Line 3,148: | Line 3,148: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |- | ||
|resizable_chat | |resizable_chat() | ||
|Makes the chat resize on grabbing of corners or edges. | |Makes the chat resize on grabbing of corners or edges. | ||
| | | | ||
Line 3,239: | Line 3,239: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|} | |} | ||
=== Variables === | |||
== permissions.js == | |||
=== Variables === | |||
{| class="wikitable" | |||
|+ | |||
!Name | |||
!Description | |||
!Related code | |||
|- | |||
|PERM | |||
|Defines permission numbers for easier use instead of writing "Admin" | |||
|<syntaxhighlight lang="js" line="1" start="1"> | |||
var PERM = { | |||
ADMIN: 2, | |||
MEMBERS: 1, | |||
PUBLIC: 0 | |||
}; | |||
</syntaxhighlight> | |||
|} | |||
==== Permissions ==== | |||
Since <code>Permissions</code> is a very long dictionary variable, this table is divided into specific definitions in it. | |||
{| class="wikitable" | |||
|+ | |||
!Name | |||
!Description | |||
!Related definition | |||
|- | |||
|can_admin | |||
|Checks if user is an admin. | |||
|<syntaxhighlight lang="js" line="1" start="7"> | |||
can_admin: function(user) { | |||
return user.is_owner; | |||
}, | |||
</syntaxhighlight> | |||
|- | |||
|can_coordlink | |||
|Checks if user can create coordinate links in the world they're in. | |||
|<syntaxhighlight lang="js" line="1" start="10"> | |||
can_coordlink: function(user, world) { | |||
return Permissions.user_matches_perm(user, world, world.feature_coord_link); | |||
}, | |||
</syntaxhighlight> | |||
|- | |||
|can_edit_tile | |||
|Checks if user can write in a tile / character (protections). | |||
|<syntaxhighlight lang="js" line="1" start="13"> | |||
can_edit_tile: function(user, world, tile, charX, charY) { | |||
if(!tile) { | |||
throw new Error("Can't check perms on un-initted tile"); | |||
} | |||
if(!Permissions.can_read(user, world)) { | |||
return false; | |||
} | |||
var targetWritability; | |||
if(tile.char) { | |||
targetWritability = tile.char[charY * tileC + charX]; | |||
if(targetWritability == null) targetWritability = tile.writability; // inherit from tile | |||
if(targetWritability == null) targetWritability = world.writability; // inherit from world | |||
} else { | |||
targetWritability = tile.writability; | |||
if(targetWritability == null) targetWritability = world.writability; | |||
} | |||
return Permissions.user_matches_perm(user, world, targetWritability); | |||
}, | |||
</syntaxhighlight> | |||
|- | |||
|can_go_to_coord | |||
|Checks if user can teleport. | |||
|<syntaxhighlight lang="js" line="1" start="31"> | |||
can_go_to_coord: function(user, world) { | |||
return Permissions.user_matches_perm(user, world, world.feature_go_to_coord); | |||
}, | |||
</syntaxhighlight> | |||
|- | |||
|can_paste | |||
|Checks if user can paste. | |||
|<syntaxhighlight lang="js" line="1" start="34"> | |||
can_paste: function(user, world) { | |||
return Permissions.user_matches_perm(user, world, world.feature_paste); | |||
}, | |||
</syntaxhighlight> | |||
|- | |||
|can_copy | |||
|Checks if user can copy. | |||
|<syntaxhighlight lang="js" line="1" start="37"> | |||
can_copy: function(user, world) { | |||
if(user.is_owner || user.is_member) return true; | |||
return !world.no_copy; | |||
}, | |||
</syntaxhighlight> | |||
|- | |||
|can_protect_tiles | |||
|Checks if user can protect tiles. | |||
|<syntaxhighlight lang="js" line="1" start="41"> | |||
can_protect_tiles: function(user, world) { | |||
if(user.is_owner) return true; | |||
return world.feature_membertiles_addremove && user.is_member; | |||
}, | |||
</syntaxhighlight> | |||
|- | |||
|can_erase | |||
|Checks if user can use the built-in eraser. | |||
|<syntaxhighlight lang="js" line="1" start="45"> | |||
can_erase: function(user, world) { | |||
if(user.is_owner) return true; | |||
return Permissions.user_matches_perm(user, world, world.quick_erase); | |||
}, | |||
</syntaxhighlight> | |||
|- | |||
|can_read | |||
|Checks if user can view the world. | |||
|<syntaxhighlight lang="js" line="1" start="49"> | |||
can_read: function(user, world) { | |||
return Permissions.user_matches_perm(user, world, world.readability); | |||
}, | |||
</syntaxhighlight> | |||
|- | |||
|can_urllink | |||
|Checks if user can create links leading to other URL's. | |||
|<syntaxhighlight lang="js" line="1" start="52"> | |||
can_urllink: function(user, world) { | |||
return Permissions.user_matches_perm(user, world, world.feature_url_link); | |||
}, | |||
</syntaxhighlight> | |||
|- | |||
|can_write | |||
|Checks if user can write on the world. | |||
|<syntaxhighlight lang="js" line="1" start="55"> | |||
can_write: function(user, world) { | |||
if(!Permissions.can_read(user, world)) { | |||
return false; | |||
} | |||
return Permissions.user_matches_perm(user, world, world.writability); | |||
}, | |||
</syntaxhighlight> | |||
|- | |||
|can_chat | |||
|Checks if user can chat. | |||
|<syntaxhighlight lang="js" line="1" start="61"> | |||
can_chat: function(user, world) { | |||
return Permissions.user_matches_perm(user, world, world.chat_permission); | |||
}, | |||
</syntaxhighlight> | |||
|- | |||
|can_show_cursor | |||
|Checks if showing cursors is enabled for a user. | |||
|<syntaxhighlight lang="js" line="1" start="64"> | |||
can_show_cursor: function(user, world) { | |||
return Permissions.user_matches_perm(user, world, world.show_cursor); | |||
}, | |||
</syntaxhighlight> | |||
|- | |||
|can_color_text | |||
|Checks if user can change their text colour. | |||
|<syntaxhighlight lang="js" line="1" start="67"> | |||
can_color_text: function(user, world) { | |||
return Permissions.user_matches_perm(user, world, world.color_text); | |||
}, | |||
</syntaxhighlight> | |||
|- | |||
|can_color_cell | |||
|Checks if user can change their cell colour. | |||
|<syntaxhighlight lang="js" line="1" start="70"> | |||
can_color_cell: function(user, world) { | |||
return Permissions.user_matches_perm(user, world, world.color_cell); | |||
}, | |||
</syntaxhighlight> | |||
|- | |||
|user_matches_perm | |||
|Gets users permissions. | |||
|<syntaxhighlight lang="js" line="1" start="73"> | |||
user_matches_perm: function(user, world, perm) { | |||
if(perm == -1) { // no one | |||
return false; | |||
} | |||
if(perm == PERM.PUBLIC) { // anyone | |||
return true; | |||
} | |||
if(user.is_owner) { | |||
return true; | |||
} | |||
if(perm == PERM.ADMIN) { | |||
return false; | |||
} | |||
if(perm == PERM.MEMBERS && user.is_member) { | |||
return true; | |||
} | |||
return false; | |||
} | |||
}; | |||
</syntaxhighlight> | |||
|} | |||
[[Category:Articles nominated by Guest-1052]] | |||
[[Category:Documentation]] |