Constructor
new Cards(dataopt)
- See:
-
- data.CardsData The Cards data schema
- CardStacks The world-level collection of Cards documents
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data |
data.CardsData |
<optional> |
{}
|
Initial data provided to construct the Cards document |
Extends
- abstract.Document
- abstract.BaseCards
- ClientDocumentMixin
Members
apps :Object.<Application>
- Inherited From:
- See:
-
- Document#render
A collection of Application instances which should be re-rendered whenever this document is updated. The keys of this object are the application ids and the values are Application instances. Each Application in this object will have its render method called by Document#render.
Type:
- Object.<Application>
availableCards :Array.<Card>
The Card documents within this stack which are able to be drawn.
Type:
collection :Collection
- Inherited From:
Return a reference to the parent Collection instance which contains this Document.
Type:
collectionName :string
- Inherited From:
The named collection to which this Document belongs.
Type:
- string
compendium :CompendiumCollection
- Inherited From:
A reference to the Compendium Collection which contains this Document, if any, otherwise undefined.
Type:
data :DocumentData
- Inherited From:
The base data object for this Document which persists both the original source and any derived data.
Type:
- DocumentData
documentName :string
- Inherited From:
The canonical name of this Document type, for example "Actor".
Type:
- string
drawnCards :Array.<Card>
The Card documents which belong to this stack but have already been drawn.
Type:
folder :Folder|null
- Inherited From:
Return a reference to the Folder to which this Document belongs, if any.
Type:
- Folder | null
Example
let folder = game.folders.contents[0];
let actor = await Actor.create({name: "New Actor", folder: folder.id});
console.log(actor.data.folder); // folder.id;
console.log(actor.folder); // folder;
hasPlayerOwner :boolean
- Inherited From:
Test whether this Document is owned by any non-Gamemaster User.
Type:
- boolean
id :string|null
- Inherited From:
The canonical identifier for this Document
Type:
- string | null
isEmbedded :boolean
- Inherited From:
Test whether this Document is embedded within a parent Document
Type:
- boolean
isOwner :boolean
- Inherited From:
A boolean indicator for whether or not the current game User has ownership rights for this Document. Different Document types may have more specialized rules for what constitutes ownership.
Type:
- boolean
limited :boolean
- Inherited From:
A boolean indicator for whether the current game User has exactly LIMITED visibility (and no greater).
Type:
- boolean
link
- Inherited From:
Return a string which creates a dynamic link to this Document instance.
name :string|null
- Inherited From:
The name of this Document, if it has one assigned
Type:
- string | null
pack :string|null
- Inherited From:
An immutable reference to a containing Compendium collection to which this Document belongs.
Type:
- string | null
parent :Document|null
- Inherited From:
An immutable reverse-reference to the parent Document to which this embedded Document belongs.
Type:
- Document | null
permission :number
- Inherited From:
Return the permission level that the current game User has over this Document. See the CONST.DOCUMENT_PERMISSION_LEVELS object for an enumeration of these levels.
Type:
- number
Example
game.user.id; // "dkasjkkj23kjf"
actor.data.permission; // {default: 1, "dkasjkkj23kjf": 2};
actor.permission; // 2
sheet :FormApplication|null
- Inherited From:
Lazily obtain a FormApplication instance used to configure this Document, or null if no sheet is available.
Type:
- FormApplication | null
thumbnail :string
Provide a thumbnail image path used to represent this document.
Type:
- string
uuid :string
- Inherited From:
A Universally Unique Identifier (uuid) for this Document instance.
Type:
- string
visible :boolean
- Inherited From:
A boolean indicator for whether or not the current game User has at least limited visibility for this Document. Different Document types may have more specialized rules for what determines visibility.
Type:
- boolean
Methods
(async, static) createDialog()
(async, static) createDocuments()
(async, static) deleteDocuments()
(protected) _drawCards(number, how) → {Array.<Card>}
An internal helper method for drawing a certain number of Card documents from this Cards stack.
Parameters:
Name | Type | Description |
---|---|---|
number |
number | The number of cards to draw |
how |
number | A draw mode from CONST.CARD_DRAW_MODES |
Returns:
An array of drawn Card documents
(protected) _initialize()
- Overrides:
Perform one-time initialization tasks which only occur when the Document is first constructed.
(protected) _onCreate(data, options, userId)
- Overrides:
Perform follow-up operations after a Document of this type is created. Post-creation operations occur for all clients after the creation is broadcast.
Parameters:
Name | Type | Description |
---|---|---|
data |
object | The initial data object provided to the document creation request |
options |
object | Additional options which modify the creation request |
userId |
string | The id of the User requesting the document update |
_onCreateEmbeddedDocuments(embeddedName, documents, result, options, userId)
- Inherited From:
Follow-up actions taken after a set of embedded Documents in this parent Document are created.
Parameters:
Name | Type | Description |
---|---|---|
embeddedName |
string | The name of the embedded Document type |
documents |
Array.<Document> | An Array of created Documents |
result |
Array.<object> | An Array of created data objects |
options |
object | Options which modified the creation operation |
userId |
string | The ID of the User who triggered the operation |
(protected) _onDelete(options, userId)
- Overrides:
Perform follow-up operations after a Document of this type is deleted. Post-deletion operations occur for all clients after the deletion is broadcast.
Parameters:
Name | Type | Description |
---|---|---|
options |
object | Additional options which modify the deletion request |
userId |
string | The id of the User requesting the document update |
_onDeleteEmbeddedDocuments(embeddedName, documents, result, options, userId)
- Inherited From:
Follow-up actions taken after a set of embedded Documents in this parent Document are deleted.
Parameters:
Name | Type | Description |
---|---|---|
embeddedName |
string | The name of the embedded Document type |
documents |
Array.<Document> | An Array of deleted Documents |
result |
Array.<object> | An Array of document IDs being deleted |
options |
object | Options which modified the deletion operation |
userId |
string | The ID of the User who triggered the operation |
(protected) _onUpdate(changed, options, userId)
- Overrides:
- See:
Perform follow-up operations after a Document of this type is updated. Post-update operations occur for all clients after the update is broadcast.
Parameters:
Name | Type | Description |
---|---|---|
changed |
object | The differential data that was changed relative to the documents prior values |
options |
object | Additional options which modify the update request |
userId |
string | The id of the User requesting the document update |
_onUpdateEmbeddedDocuments(embeddedName, documents, result, options, userId)
- Inherited From:
Follow-up actions taken after a set of embedded Documents in this parent Document are updated.
Parameters:
Name | Type | Description |
---|---|---|
embeddedName |
string | The name of the embedded Document type |
documents |
Array.<Document> | An Array of updated Documents |
result |
Array.<object> | An Array of incremental data objects |
options |
object | Options which modified the update operation |
userId |
string | The ID of the User who triggered the operation |
(async, protected) _preCreate(data, options, user)
- Inherited From:
Perform preliminary operations before a Document of this type is created. Pre-creation operations only occur for the client which requested the operation.
Parameters:
Name | Type | Description |
---|---|---|
data |
object | The initial data object provided to the document creation request |
options |
object | Additional options which modify the creation request |
user |
documents.BaseUser | The User requesting the document creation |
_preCreateEmbeddedDocuments(embeddedName, result, options, userId)
- Inherited From:
Preliminary actions taken before a set of embedded Documents in this parent Document are created.
Parameters:
Name | Type | Description |
---|---|---|
embeddedName |
string | The name of the embedded Document type |
result |
Array.<object> | An Array of created data objects |
options |
object | Options which modified the creation operation |
userId |
string | The ID of the User who triggered the operation |
(async, protected) _preDelete(options, user)
- Inherited From:
Perform preliminary operations before a Document of this type is deleted. Pre-delete operations only occur for the client which requested the operation.
Parameters:
Name | Type | Description |
---|---|---|
options |
object | Additional options which modify the deletion request |
user |
documents.BaseUser | The User requesting the document deletion |
_preDeleteEmbeddedDocuments(embeddedName, result, options, userId)
- Inherited From:
Preliminary actions taken before a set of embedded Documents in this parent Document are deleted.
Parameters:
Name | Type | Description |
---|---|---|
embeddedName |
string | The name of the embedded Document type |
result |
Array.<object> | An Array of document IDs being deleted |
options |
object | Options which modified the deletion operation |
userId |
string | The ID of the User who triggered the operation |
(async, protected) _preUpdate(changed, options, user)
- Inherited From:
Perform preliminary operations before a Document of this type is updated. Pre-update operations only occur for the client which requested the operation.
Parameters:
Name | Type | Description |
---|---|---|
changed |
object | The differential data that is changed relative to the documents prior values |
options |
object | Additional options which modify the update request |
user |
documents.BaseUser | The User requesting the document update |
_preUpdateEmbeddedDocuments(embeddedName, result, options, userId)
- Inherited From:
Preliminary actions taken before a set of embedded Documents in this parent Document are updated.
Parameters:
Name | Type | Description |
---|---|---|
embeddedName |
string | The name of the embedded Document type |
result |
Array.<object> | An Array of incremental data objects |
options |
object | Options which modified the update operation |
userId |
string | The ID of the User who triggered the operation |
canUserModify(user, action, dataopt) → {boolean}
- Inherited From:
Test whether a given User has permission to perform some action on this Document
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
user |
documents.BaseUser | The User attempting modification |
|
action |
string | The attempted action |
|
data |
object |
<optional> |
Data involved in the attempted action |
Returns:
Does the User have permission?
- Type
- boolean
clone(dataopt, saveopt, contextopt) → {Document|Promise.<Document>}
- Inherited From:
Clone a document, creating a new document by combining current data with provided overrides. The cloned document is ephemeral and not yet saved to the database.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data |
Object |
<optional> |
{}
|
Additional data which overrides current document data at the time of creation |
save |
boolean |
<optional> |
false
|
Save the clone to the World database? |
context |
DocumentModificationContext |
<optional> |
{}
|
Additional context options passed to the create method |
Returns:
The cloned Document instance
- Type
- Document | Promise.<Document>
(async) createEmbeddedDocuments(embeddedName, data, contextopt) → {Promise.<Array.<Document>>}
- Inherited From:
- See:
-
- Document.createDocuments
Create multiple embedded Document instances within this parent Document using provided input data.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
embeddedName |
string | The name of the embedded Document type |
||
data |
Array.<object> | An array of data objects used to create multiple documents |
||
context |
DocumentModificationContext |
<optional> |
{}
|
Additional context which customizes the creation workflow |
Returns:
An array of created Document instances
- Type
- Promise.<Array.<Document>>
(async) deal(to, numberopt, howopt, updateDataopt, actionopt, chatNotificationopt) → {Promise.<Cards>}
Deal one or more cards from this Cards document to each of a provided array of Cards destinations. Cards are allocated from the top of the deck in cyclical order until the required number of Cards have been dealt.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
to |
Array.<Cards> | An array of other Cards documents to which cards are dealt |
||
number |
number |
<optional> |
1
|
The number of cards to deal to each other document |
how |
number |
<optional> |
0
|
How to draw, a value from CONST.CARD_DRAW_MODES |
updateData |
object |
<optional> |
{}
|
Modifications to make to each Card as part of the deal operation, for example the displayed face |
action |
string |
<optional> |
deal
|
The name of the action being performed, used as part of the dispatched Hook event |
chatNotification |
boolean |
<optional> |
true
|
Create a ChatMessage which notifies that this action has occurred |
Returns:
This Cards document after the deal operation has completed
- Type
- Promise.<Cards>
(async) dealDialog() → {Promise.<(Cards|null)>}
- See:
Display a dialog which prompts the user to deal cards to some number of hand-type Cards documents.
Returns:
- Type
- Promise.<(Cards|null)>
(async) delete(contextopt) → {Promise.<Document>}
- Inherited From:
- See:
-
- Document.deleteDocuments
Delete this Document, removing it from the database.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
context |
DocumentModificationContext |
<optional> |
{}
|
Additional context which customizes the deletion workflow |
Returns:
The deleted Document instance
- Type
- Promise.<Document>
(async) deleteDialog()
(async) deleteEmbeddedDocuments(embeddedName, ids, contextopt) → {Promise.<Array.<Document>>}
- Inherited From:
- See:
-
- Document.deleteDocuments
Delete multiple embedded Document instances within a parent Document using provided string ids.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
embeddedName |
string | The name of the embedded Document type |
||
ids |
Array.<string> | An array of string ids for each Document to be deleted |
||
context |
DocumentModificationContext |
<optional> |
{}
|
Additional context which customizes the deletion workflow |
Returns:
An array of deleted Document instances
- Type
- Promise.<Array.<Document>>
(async) draw(from, numberopt, optionsopt, howopt, updateDataopt) → {Promise.<Array.<Card>>}
Draw one or more cards from some other Cards document.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
from |
Cards | Some other Cards document from which to draw |
||
number |
number |
<optional> |
1
|
The number of cards to draw |
options |
object |
<optional> |
{}
|
Options which modify the draw operation |
how |
number |
<optional> |
0
|
How to draw, a value from CONST.CARD_DRAW_MODES |
updateData |
object |
<optional> |
{}
|
Modifications to make to each Card as part of the draw operation, for example the displayed face |
Returns:
An array of the Card documents which were drawn
(async) drawDialog() → {Promise.<(Array.<Card>|null)>}
- See:
Display a dialog which prompts the user to draw cards from some other deck-type Cards documents.
Returns:
exportToJSON(optionsopt)
- Inherited From:
Export document data to a JSON file which can be saved by the client and later imported into a different session.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
object |
<optional> |
Additional options passed to the ClientDocumentMixin#toCompendium method |
getEmbeddedCollection(embeddedName) → {Collection}
- Inherited From:
Obtain a reference to the Array of source data within the data object for a certain embedded Document name
Parameters:
Name | Type | Description |
---|---|---|
embeddedName |
string | The name of the embedded Document type |
Returns:
The Collection instance of embedded Documents of the requested type
- Type
- Collection
getEmbeddedDocument(embeddedName, id, optionsopt) → {Document}
- Inherited From:
Get an embedded document by it's id from a named collection in the parent document.
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
embeddedName |
string | The name of the embedded Document type |
|||||||||||
id |
string | The id of the child document to retrieve |
|||||||||||
options |
object |
<optional> |
Additional options which modify how embedded documents are retrieved Properties
|
Returns:
The retrieved embedded Document instance, or undefined
- Type
- Document
getFlag(scope, key) → {*}
- Inherited From:
Get the value of a "flag" for this document See the setFlag method for more details on flags
Parameters:
Name | Type | Description |
---|---|---|
scope |
string | The flag scope which namespaces the key |
key |
string | The flag key |
Returns:
The flag value
- Type
- *
getUserLevel(user) → {number|null}
- Inherited From:
Get the permission level that a specific User has over this Document, a value in CONST.DOCUMENT_PERMISSION_LEVELS.
Parameters:
Name | Type | Description |
---|---|---|
user |
documents.BaseUser | The User being tested |
Returns:
A numeric permission level from CONST.DOCUMENT_PERMISSION_LEVELS or null
- Type
- number | null
(async) importFromJSON(json) → {Promise.<Document>}
- Inherited From:
Update this Document using a provided JSON string.
Parameters:
Name | Type | Description |
---|---|---|
json |
string | JSON data string |
Returns:
The updated Document
- Type
- Promise.<Document>
(async) importFromJSONDialog() → {Promise.<void>}
- Inherited From:
Render an import dialog for updating the data related to this Document through an exported JSON file
Returns:
- Type
- Promise.<void>
migrateSystemData() → {object}
- Inherited From:
For Documents which include game system data, migrate the system data object to conform to its latest data model. The data model is defined by the template.json specification included by the game system.
Returns:
The migrated system data object
- Type
- object
(async) pass(to, ids, optionsopt) → {Promise.<Array.<Card>>}
Pass an array of specific Card documents from this document to some other Cards stack.
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
to |
Cards | Some other Cards document that is the destination for the pass operation |
||||||||||||||||||||||
ids |
Array.<string> | The embedded Card ids which should be passed |
||||||||||||||||||||||
options |
object |
<optional> |
{}
|
Additional options which modify the pass operation Properties
|
Returns:
An array of the Card embedded documents created within the destination stack
(async) passDialog() → {Promise.<(Cards|null)>}
- See:
Display a dialog which prompts the user to pass cards from this document to some other Cards document.
Returns:
- Type
- Promise.<(Cards|null)>
(async) playDialog(card) → {Promise.<(Array.<Card>|null)>}
- See:
Display a dialog which prompts the user to play a specific Card to some other Cards document
Parameters:
Name | Type | Description |
---|---|---|
card |
Card | The specific card being played as part of this dialog |
Returns:
prepareBaseData()
- Inherited From:
Prepare data related to this Document itself, before any embedded Documents or derived data is computed.
prepareData()
- Inherited From:
Prepare data for the Document. Begin by resetting the prepared data back to its source state. Next prepare any embedded Documents and compute any derived data elements.
prepareDerivedData()
- Inherited From:
Apply transformations or derivations to the values of the source data object. Compute data fields whose values are not stored to the database.
prepareEmbeddedDocuments()
- Inherited From:
Prepare all embedded Document instances which exist within this primary Document.
render(forceopt, contextopt)
- Inherited From:
- See:
Render all of the Application instances which are connected to this document by calling their respective
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
force |
boolean |
<optional> |
false
|
Force rendering |
context |
object |
<optional> |
{}
|
Optional context |
(async) reset(optionsopt) → {Promise.<Cards>}
Reset the Cards stack, retrieving all original cards from other stacks where they may have been drawn if this is a deck, otherwise returning all the cards in this stack to the decks where they originated.
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
{}
|
Options which modify the reset operation Properties
|
Returns:
The Cards document after the reset operation has completed.
- Type
- Promise.<Cards>
(async) resetDialog() → {Promise.<(Cards|false|null)>}
- See:
Display a confirmation dialog for whether or not the user wishes to reset a Cards stack
Returns:
- Type
- Promise.<(Cards|false|null)>
(async) setFlag(scope, key, value) → {Promise.<Document>}
- Inherited From:
Assign a "flag" to this document. Flags represent key-value type data which can be used to store flexible or arbitrary data required by either the core software, game systems, or user-created modules.
Each flag should be set using a scope which provides a namespace for the flag to help prevent collisions.
Flags set by the core software use the "core" scope. Flags set by game systems or modules should use the canonical name attribute for the module Flags set by an individual world should "world" as the scope.
Flag values can assume almost any data type. Setting a flag value to null will delete that flag.
Parameters:
Name | Type | Description |
---|---|---|
scope |
string | The flag scope which namespaces the key |
key |
string | The flag key |
value |
* | The flag value |
Returns:
A Promise resolving to the updated document
- Type
- Promise.<Document>
(async) shuffle(updateDataopt, chatNotificationopt) → {Promise.<Cards>}
Shuffle this Cards stack, randomizing the sort order of all the cards it contains.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
updateData |
object |
<optional> |
{}
|
Modifications to make to each Card as part of the shuffle operation, for example the displayed face. |
chatNotification |
boolean |
<optional> |
true
|
Create a ChatMessage which notifies that this action has occurred |
Returns:
The Cards document after the shuffle operation has completed
- Type
- Promise.<Cards>
(async) sortRelative(optionsopt) → {Promise.<Document>}
- Inherited From:
Determine the sort order for this Document by positioning it relative a target sibling. See SortingHelper.performIntegerSort for more details
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
object |
<optional> |
Sorting options provided to SortingHelper.performIntegerSort |
Returns:
The Document after it has been re-sorted
- Type
- Promise.<Document>
(protected) sortShuffled(a, b) → {number}
A sorting function that is used to determine the order of Card documents within a shuffled stack.
Parameters:
Name | Type | Description |
---|---|---|
a |
data.CardData | The card being sorted |
b |
data.CardData | Another card being sorted against |
Returns:
- Type
- number
(protected) sortStandard(a, b) → {number}
A sorting function that is used to determine the standard order of Card documents within an un-shuffled stack.
Parameters:
Name | Type | Description |
---|---|---|
a |
data.CardData | The card being sorted |
b |
data.CardData | Another card being sorted against |
Returns:
- Type
- number
testUserPermission(user, permission, options) → {boolean}
- Inherited From:
Test whether a certain User has a requested permission level (or greater) over the Document
Parameters:
Name | Type | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
user |
documents.BaseUser | The User being tested |
||||||||||
permission |
string | number | The permission level from DOCUMENT_PERMISSION_LEVELS to test |
||||||||||
options |
object | Additional options involved in the permission test Properties
|
Returns:
Does the user have this permission level over the Document?
- Type
- boolean
toCompendium(packopt, optionsopt) → {object}
- Inherited From:
Transform the Document data to be stored in a Compendium pack. Remove any features of the data which are world-specific.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
pack |
CompendiumCollection |
<optional> |
A specific pack being exported to |
||||||||||||||||||||||||||||||
options |
object |
<optional> |
Additional options which modify how the document is converted Properties
|
Returns:
A data object of cleaned data suitable for compendium import
- Type
- object
toJSON() → {object}
- Inherited From:
Convert the Document instance to a primitive object which can be serialized. See DocumentData#toJSON
Returns:
The document data expressed as a plain object
- Type
- object
toObject(sourceopt) → {object}
- Inherited From:
Transform the Document instance into a plain object. The created object is an independent copy of the original data. See DocumentData#toObject
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
source |
boolean |
<optional> |
true
|
Draw values from the underlying data source rather than transformed values |
Returns:
The extracted primitive object
- Type
- object
(async) unsetFlag(scope, key) → {Promise.<Document>}
- Inherited From:
Remove a flag assigned to the document
Parameters:
Name | Type | Description |
---|---|---|
scope |
string | The flag scope which namespaces the key |
key |
string | The flag key |
Returns:
The updated document instance
- Type
- Promise.<Document>
(async) update(dataopt, contextopt) → {Promise.<Document>}
- Inherited From:
- See:
-
- Document.updateDocuments
Update this Document using incremental data, saving it to the database.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data |
object |
<optional> |
{}
|
Differential update data which modifies the existing values of this document data |
context |
DocumentModificationContext |
<optional> |
{}
|
Additional context which customizes the update workflow |
Returns:
The updated Document instance
- Type
- Promise.<Document>
(async) updateEmbeddedDocuments(embeddedName, updates, contextopt) → {Promise.<Array.<Document>>}
- Inherited From:
- See:
-
- Document.updateDocuments
Update multiple embedded Document instances within a parent Document using provided differential data.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
embeddedName |
string | The name of the embedded Document type |
||
updates |
Array.<object> | An array of differential data objects, each used to update a single Document |
||
context |
DocumentModificationContext |
<optional> |
{}
|
Additional context which customizes the update workflow |
Returns:
An array of updated Document instances
- Type
- Promise.<Array.<Document>>