Add missing scripting documentation

This commit is contained in:
Marcus Huderle 2020-05-16 10:14:34 -05:00
parent b8c2fa41ee
commit c20b2c91a1
20 changed files with 11441 additions and 38 deletions

View file

@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 9e8b58068fa2090b104690bfc9c25e35
config: e41613e939dfe6ab7008de864b4e64a8
tags: 645f666f9bcd5a90fca523b33c5a78b7

234
docs/README.html Normal file
View file

@ -0,0 +1,234 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Setup &mdash; porymap documentation</title>
<script type="text/javascript" src="_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/language_data.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/custom.css" type="text/css" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" style="background: linear-gradient(180deg, #08ACD5 50%, #FF6262 0%);" >
<a href="index.html" class="icon icon-home"> porymap
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">User Manual</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="manual/introduction.html">Introduction</a><ul>
<li class="toctree-l2"><a class="reference internal" href="manual/introduction.html#about-porymap">About Porymap</a></li>
<li class="toctree-l2"><a class="reference internal" href="manual/introduction.html#getting-started">Getting Started</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="manual/navigation.html">Navigation</a><ul>
<li class="toctree-l2"><a class="reference internal" href="manual/navigation.html#map-list">Map List</a></li>
<li class="toctree-l2"><a class="reference internal" href="manual/navigation.html#main-window">Main Window</a></li>
<li class="toctree-l2"><a class="reference internal" href="manual/navigation.html#tileset-editor">Tileset Editor</a></li>
<li class="toctree-l2"><a class="reference internal" href="manual/navigation.html#region-map-editor">Region Map Editor</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="manual/editing-map-tiles.html">Editing Map Tiles</a><ul>
<li class="toctree-l2"><a class="reference internal" href="manual/editing-map-tiles.html#visual-options">Visual Options</a></li>
<li class="toctree-l2"><a class="reference internal" href="manual/editing-map-tiles.html#selecting-metatiles">Selecting Metatiles</a></li>
<li class="toctree-l2"><a class="reference internal" href="manual/editing-map-tiles.html#pencil-tool">Pencil Tool</a></li>
<li class="toctree-l2"><a class="reference internal" href="manual/editing-map-tiles.html#pointer-tool">Pointer Tool</a></li>
<li class="toctree-l2"><a class="reference internal" href="manual/editing-map-tiles.html#bucket-fill-tool">Bucket Fill Tool</a></li>
<li class="toctree-l2"><a class="reference internal" href="manual/editing-map-tiles.html#map-shift-tool">Map Shift Tool</a></li>
<li class="toctree-l2"><a class="reference internal" href="manual/editing-map-tiles.html#smart-paths">Smart Paths</a></li>
<li class="toctree-l2"><a class="reference internal" href="manual/editing-map-tiles.html#change-map-border">Change Map Border</a></li>
<li class="toctree-l2"><a class="reference internal" href="manual/editing-map-tiles.html#change-map-tilesets">Change Map Tilesets</a></li>
<li class="toctree-l2"><a class="reference internal" href="manual/editing-map-tiles.html#undo-redo">Undo &amp; Redo</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="manual/editing-map-events.html">Editing Map Events</a></li>
</ul>
<p class="caption"><span class="caption-text">Reference</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="reference/related-projects.html">Related Projects</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">porymap</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> &raquo;</li>
<li>Setup</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/README.md.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<p>This directory holds the sources that build the porymap documentation website. It uses Sphinx to build a static website, and copy the results to the <code class="docutils literal notranslate"><span class="pre">docs/</span></code> directory for GitHub Pages.</p>
<div class="section" id="setup">
<h1>Setup<a class="headerlink" href="#setup" title="Permalink to this headline"></a></h1>
<p>Sphinx uses Python, so you can use <code class="docutils literal notranslate"><span class="pre">pip</span></code> to install the dependencies:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">pip</span> <span class="n">install</span> <span class="o">-</span><span class="n">r</span> <span class="n">requirements</span><span class="o">.</span><span class="n">txt</span>
</pre></div>
</div>
</div>
<div class="section" id="build">
<h1>Build<a class="headerlink" href="#build" title="Permalink to this headline"></a></h1>
<p>This will build the static site and copy the files to the root-level <code class="docutils literal notranslate"><span class="pre">docs/</span></code> directory. The GitHub Pages site will automatically update when the commit is merged to porymaps <code class="docutils literal notranslate"><span class="pre">master</span></code> branch.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">make</span> <span class="n">github</span>
</pre></div>
</div>
</div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2019, huderlem
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View file

@ -0,0 +1,13 @@
This directory holds the sources that build the porymap documentation website. It uses Sphinx to build a static website, and copy the results to the `docs/` directory for GitHub Pages.
## Setup
Sphinx uses Python, so you can use `pip` to install the dependencies:
```
pip install -r requirements.txt
```
## Build
This will build the static site and copy the files to the root-level `docs/` directory. The GitHub Pages site will automatically update when the commit is merged to porymap's `master` branch.
```
make github
```

View file

@ -68,12 +68,12 @@ Let's test the script out by re-launching Porymap. If we try to paint grass on t
Registering Script Actions
--------------------------
The grass-randomizer script above happens implicitly when the user paints on the map. However, other times we probably want to call the custom script on demand. One of the API function Porymap provides is the ability to trigger scripting functions from the ``Tools`` menu, or a keyboard shortcut. To do this, we will usually want to register the action when the project loads. Here is an example script where a couple custom actions are registered.
The grass-randomizer script above happens implicitly when the user paints on the map. However, other times we probably want to call the custom script on demand. One of the API functions Porymap provides is the ability to trigger scripting functions from the ``Tools`` menu, or a keyboard shortcut. To do this, we will usually want to register the action when the project loads. Here is an example script where some custom actions are registered.
.. code-block:: js
function applyNightTint() {
// Apply night palette tinting...
// Apply night palette tinting...
}
// Porymap callback when project is opened.
@ -136,7 +136,7 @@ The following functions are related to editing the map's blocks or retrieving in
:param number y: y coordinate of the block
:returns {metatileId, collision, elevation, rawValue}: the block object
.. js:function:: map.setBlock(x, y, metatileId, collision, elevation)
.. js:function:: map.setBlock(x, y, metatileId, collision, elevation, forceRedraw = true, commitChanges = true)
Sets a block in the currently-opened map.
@ -145,6 +145,8 @@ The following functions are related to editing the map's blocks or retrieving in
:param number metatileId: the metatile id of the block
:param number collision: the collision of the block (``0`` = passable, ``1`` = impassable)
:param number elevation: the elevation of the block
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.getMetatileId(x, y)
@ -154,13 +156,15 @@ The following functions are related to editing the map's blocks or retrieving in
:param number y: y coordinate of the block
:returns number: the metatile id of the block
.. js:function:: map.setMetatileId(x, y, metatileId)
.. js:function:: map.setMetatileId(x, y, metatileId, forceRedraw = true, commitChanges = true)
Sets the metatile id of a block in the currently-opened map.
:param number x: x coordinate of the block
:param number y: y coordinate of the block
:param number metatileId: the metatile id of the block
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.getCollision(x, y)
@ -170,13 +174,15 @@ The following functions are related to editing the map's blocks or retrieving in
:param number y: y coordinate of the block
:returns number: the collision of the block
.. js:function:: map.setCollision(x, y, collision)
.. js:function:: map.setCollision(x, y, collision, forceRedraw = true, commitChanges = true)
Sets the collision of a block in the currently-opened map. (``0`` = passable, ``1`` = impassable)
:param number x: x coordinate of the block
:param number y: y coordinate of the block
:param number collision: the collision of the block
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.getElevation(x, y)
@ -186,57 +192,71 @@ The following functions are related to editing the map's blocks or retrieving in
:param number y: y coordinate of the block
:returns number: the elevation of the block
.. js:function:: map.setElevation(x, y, elevation)
.. js:function:: map.setElevation(x, y, elevation, forceRedraw = true, commitChanges = true)
Sets the elevation of a block in the currently-opened map.
:param number x: x coordinate of the block
:param number y: y coordinate of the block
:param number elevation: the elevation of the block
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.setBlocksFromSelection(x, y)
.. js:function:: map.setBlocksFromSelection(x, y, forceRedraw = true, commitChanges = true)
Sets blocks on the map using the user's current metatile selection.
:param number x: initial x coordinate
:param number y: initial y coordinate
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.bucketFill(x, y, metatileId)
.. js:function:: map.bucketFill(x, y, metatileId, forceRedraw = true, commitChanges = true)
Performs a bucket fill of a metatile id, starting at the given coordinates.
:param number x: initial x coordinate
:param number y: initial y coordinate
:param number metatileId: metatile id to fill
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.bucketFillFromSelection(x, y)
.. js:function:: map.bucketFillFromSelection(x, y, forceRedraw = true, commitChanges = true)
Performs a bucket fill using the user's current metatile selection, starting at the given coordinates.
:param number x: initial x coordinate
:param number y: initial y coordinate
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.magicFill(x, y, metatileId)
.. js:function:: map.magicFill(x, y, metatileId, forceRedraw = true, commitChanges = true)
Performs a magic fill of a metatile id, starting at the given coordinates.
:param number x: initial x coordinate
:param number y: initial y coordinate
:param number metatileId: metatile id to magic fill
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.magicFillFromSelection(x, y)
.. js:function:: map.magicFillFromSelection(x, y, forceRedraw = true, commitChanges = true)
Performs a magic fill using the user's current metatile selection, starting at the given coordinates.
:param number x: initial x coordinate
:param number y: initial y coordinate
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.shift(xDelta, yDelta)
.. js:function:: map.shift(xDelta, yDelta, forceRedraw = true, commitChanges = true)
Performs a shift on the map's blocks.
:param number xDelta: number of blocks to shift horizontally
:param number yDelta: number of blocks to shift vertically
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.getDimensions()
@ -275,6 +295,14 @@ The following functions are related to editing the map's blocks or retrieving in
:param number height: height in blocks
.. js:function:: map.redraw()
Redraws the entire map area. Useful when delaying map redraws using ``forceRedraw = false`` in certain map editing functions.
.. js:function:: map.commit()
Commits any uncommitted changes to the map's edit/undo history. Useful when delaying commits using ``commitChanges = false`` in certain map editing functions.
Map Overlay Functions
^^^^^^^^^^^^^^^^^^^^^

View file

@ -0,0 +1,3 @@
***********
Changelog
***********

BIN
docs/_static/ajax-loader.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 673 B

BIN
docs/_static/comment-bright.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 756 B

BIN
docs/_static/comment-close.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 829 B

BIN
docs/_static/comment.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 641 B

BIN
docs/_static/down-pressed.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

BIN
docs/_static/down.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

10253
docs/_static/jquery-3.2.1.js vendored Normal file

File diff suppressed because it is too large Load diff

BIN
docs/_static/up-pressed.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 B

BIN
docs/_static/up.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 B

808
docs/_static/websupport.js vendored Normal file
View file

@ -0,0 +1,808 @@
/*
* websupport.js
* ~~~~~~~~~~~~~
*
* sphinx.websupport utilities for all documentation.
*
* :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
(function($) {
$.fn.autogrow = function() {
return this.each(function() {
var textarea = this;
$.fn.autogrow.resize(textarea);
$(textarea)
.focus(function() {
textarea.interval = setInterval(function() {
$.fn.autogrow.resize(textarea);
}, 500);
})
.blur(function() {
clearInterval(textarea.interval);
});
});
};
$.fn.autogrow.resize = function(textarea) {
var lineHeight = parseInt($(textarea).css('line-height'), 10);
var lines = textarea.value.split('\n');
var columns = textarea.cols;
var lineCount = 0;
$.each(lines, function() {
lineCount += Math.ceil(this.length / columns) || 1;
});
var height = lineHeight * (lineCount + 1);
$(textarea).css('height', height);
};
})(jQuery);
(function($) {
var comp, by;
function init() {
initEvents();
initComparator();
}
function initEvents() {
$(document).on("click", 'a.comment-close', function(event) {
event.preventDefault();
hide($(this).attr('id').substring(2));
});
$(document).on("click", 'a.vote', function(event) {
event.preventDefault();
handleVote($(this));
});
$(document).on("click", 'a.reply', function(event) {
event.preventDefault();
openReply($(this).attr('id').substring(2));
});
$(document).on("click", 'a.close-reply', function(event) {
event.preventDefault();
closeReply($(this).attr('id').substring(2));
});
$(document).on("click", 'a.sort-option', function(event) {
event.preventDefault();
handleReSort($(this));
});
$(document).on("click", 'a.show-proposal', function(event) {
event.preventDefault();
showProposal($(this).attr('id').substring(2));
});
$(document).on("click", 'a.hide-proposal', function(event) {
event.preventDefault();
hideProposal($(this).attr('id').substring(2));
});
$(document).on("click", 'a.show-propose-change', function(event) {
event.preventDefault();
showProposeChange($(this).attr('id').substring(2));
});
$(document).on("click", 'a.hide-propose-change', function(event) {
event.preventDefault();
hideProposeChange($(this).attr('id').substring(2));
});
$(document).on("click", 'a.accept-comment', function(event) {
event.preventDefault();
acceptComment($(this).attr('id').substring(2));
});
$(document).on("click", 'a.delete-comment', function(event) {
event.preventDefault();
deleteComment($(this).attr('id').substring(2));
});
$(document).on("click", 'a.comment-markup', function(event) {
event.preventDefault();
toggleCommentMarkupBox($(this).attr('id').substring(2));
});
}
/**
* Set comp, which is a comparator function used for sorting and
* inserting comments into the list.
*/
function setComparator() {
// If the first three letters are "asc", sort in ascending order
// and remove the prefix.
if (by.substring(0,3) == 'asc') {
var i = by.substring(3);
comp = function(a, b) { return a[i] - b[i]; };
} else {
// Otherwise sort in descending order.
comp = function(a, b) { return b[by] - a[by]; };
}
// Reset link styles and format the selected sort option.
$('a.sel').attr('href', '#').removeClass('sel');
$('a.by' + by).removeAttr('href').addClass('sel');
}
/**
* Create a comp function. If the user has preferences stored in
* the sortBy cookie, use those, otherwise use the default.
*/
function initComparator() {
by = 'rating'; // Default to sort by rating.
// If the sortBy cookie is set, use that instead.
if (document.cookie.length > 0) {
var start = document.cookie.indexOf('sortBy=');
if (start != -1) {
start = start + 7;
var end = document.cookie.indexOf(";", start);
if (end == -1) {
end = document.cookie.length;
by = unescape(document.cookie.substring(start, end));
}
}
}
setComparator();
}
/**
* Show a comment div.
*/
function show(id) {
$('#ao' + id).hide();
$('#ah' + id).show();
var context = $.extend({id: id}, opts);
var popup = $(renderTemplate(popupTemplate, context)).hide();
popup.find('textarea[name="proposal"]').hide();
popup.find('a.by' + by).addClass('sel');
var form = popup.find('#cf' + id);
form.submit(function(event) {
event.preventDefault();
addComment(form);
});
$('#s' + id).after(popup);
popup.slideDown('fast', function() {
getComments(id);
});
}
/**
* Hide a comment div.
*/
function hide(id) {
$('#ah' + id).hide();
$('#ao' + id).show();
var div = $('#sc' + id);
div.slideUp('fast', function() {
div.remove();
});
}
/**
* Perform an ajax request to get comments for a node
* and insert the comments into the comments tree.
*/
function getComments(id) {
$.ajax({
type: 'GET',
url: opts.getCommentsURL,
data: {node: id},
success: function(data, textStatus, request) {
var ul = $('#cl' + id);
var speed = 100;
$('#cf' + id)
.find('textarea[name="proposal"]')
.data('source', data.source);
if (data.comments.length === 0) {
ul.html('<li>No comments yet.</li>');
ul.data('empty', true);
} else {
// If there are comments, sort them and put them in the list.
var comments = sortComments(data.comments);
speed = data.comments.length * 100;
appendComments(comments, ul);
ul.data('empty', false);
}
$('#cn' + id).slideUp(speed + 200);
ul.slideDown(speed);
},
error: function(request, textStatus, error) {
showError('Oops, there was a problem retrieving the comments.');
},
dataType: 'json'
});
}
/**
* Add a comment via ajax and insert the comment into the comment tree.
*/
function addComment(form) {
var node_id = form.find('input[name="node"]').val();
var parent_id = form.find('input[name="parent"]').val();
var text = form.find('textarea[name="comment"]').val();
var proposal = form.find('textarea[name="proposal"]').val();
if (text == '') {
showError('Please enter a comment.');
return;
}
// Disable the form that is being submitted.
form.find('textarea,input').attr('disabled', 'disabled');
// Send the comment to the server.
$.ajax({
type: "POST",
url: opts.addCommentURL,
dataType: 'json',
data: {
node: node_id,
parent: parent_id,
text: text,
proposal: proposal
},
success: function(data, textStatus, error) {
// Reset the form.
if (node_id) {
hideProposeChange(node_id);
}
form.find('textarea')
.val('')
.add(form.find('input'))
.removeAttr('disabled');
var ul = $('#cl' + (node_id || parent_id));
if (ul.data('empty')) {
$(ul).empty();
ul.data('empty', false);
}
insertComment(data.comment);
var ao = $('#ao' + node_id);
ao.find('img').attr({'src': opts.commentBrightImage});
if (node_id) {
// if this was a "root" comment, remove the commenting box
// (the user can get it back by reopening the comment popup)
$('#ca' + node_id).slideUp();
}
},
error: function(request, textStatus, error) {
form.find('textarea,input').removeAttr('disabled');
showError('Oops, there was a problem adding the comment.');
}
});
}
/**
* Recursively append comments to the main comment list and children
* lists, creating the comment tree.
*/
function appendComments(comments, ul) {
$.each(comments, function() {
var div = createCommentDiv(this);
ul.append($(document.createElement('li')).html(div));
appendComments(this.children, div.find('ul.comment-children'));
// To avoid stagnating data, don't store the comments children in data.
this.children = null;
div.data('comment', this);
});
}
/**
* After adding a new comment, it must be inserted in the correct
* location in the comment tree.
*/
function insertComment(comment) {
var div = createCommentDiv(comment);
// To avoid stagnating data, don't store the comments children in data.
comment.children = null;
div.data('comment', comment);
var ul = $('#cl' + (comment.node || comment.parent));
var siblings = getChildren(ul);
var li = $(document.createElement('li'));
li.hide();
// Determine where in the parents children list to insert this comment.
for(var i=0; i < siblings.length; i++) {
if (comp(comment, siblings[i]) <= 0) {
$('#cd' + siblings[i].id)
.parent()
.before(li.html(div));
li.slideDown('fast');
return;
}
}
// If we get here, this comment rates lower than all the others,
// or it is the only comment in the list.
ul.append(li.html(div));
li.slideDown('fast');
}
function acceptComment(id) {
$.ajax({
type: 'POST',
url: opts.acceptCommentURL,
data: {id: id},
success: function(data, textStatus, request) {
$('#cm' + id).fadeOut('fast');
$('#cd' + id).removeClass('moderate');
},
error: function(request, textStatus, error) {
showError('Oops, there was a problem accepting the comment.');
}
});
}
function deleteComment(id) {
$.ajax({
type: 'POST',
url: opts.deleteCommentURL,
data: {id: id},
success: function(data, textStatus, request) {
var div = $('#cd' + id);
if (data == 'delete') {
// Moderator mode: remove the comment and all children immediately
div.slideUp('fast', function() {
div.remove();
});
return;
}
// User mode: only mark the comment as deleted
div
.find('span.user-id:first')
.text('[deleted]').end()
.find('div.comment-text:first')
.text('[deleted]').end()
.find('#cm' + id + ', #dc' + id + ', #ac' + id + ', #rc' + id +
', #sp' + id + ', #hp' + id + ', #cr' + id + ', #rl' + id)
.remove();
var comment = div.data('comment');
comment.username = '[deleted]';
comment.text = '[deleted]';
div.data('comment', comment);
},
error: function(request, textStatus, error) {
showError('Oops, there was a problem deleting the comment.');
}
});
}
function showProposal(id) {
$('#sp' + id).hide();
$('#hp' + id).show();
$('#pr' + id).slideDown('fast');
}
function hideProposal(id) {
$('#hp' + id).hide();
$('#sp' + id).show();
$('#pr' + id).slideUp('fast');
}
function showProposeChange(id) {
$('#pc' + id).hide();
$('#hc' + id).show();
var textarea = $('#pt' + id);
textarea.val(textarea.data('source'));
$.fn.autogrow.resize(textarea[0]);
textarea.slideDown('fast');
}
function hideProposeChange(id) {
$('#hc' + id).hide();
$('#pc' + id).show();
var textarea = $('#pt' + id);
textarea.val('').removeAttr('disabled');
textarea.slideUp('fast');
}
function toggleCommentMarkupBox(id) {
$('#mb' + id).toggle();
}
/** Handle when the user clicks on a sort by link. */
function handleReSort(link) {
var classes = link.attr('class').split(/\s+/);
for (var i=0; i<classes.length; i++) {
if (classes[i] != 'sort-option') {
by = classes[i].substring(2);
}
}
setComparator();
// Save/update the sortBy cookie.
var expiration = new Date();
expiration.setDate(expiration.getDate() + 365);
document.cookie= 'sortBy=' + escape(by) +
';expires=' + expiration.toUTCString();
$('ul.comment-ul').each(function(index, ul) {
var comments = getChildren($(ul), true);
comments = sortComments(comments);
appendComments(comments, $(ul).empty());
});
}
/**
* Function to process a vote when a user clicks an arrow.
*/
function handleVote(link) {
if (!opts.voting) {
showError("You'll need to login to vote.");
return;
}
var id = link.attr('id');
if (!id) {
// Didn't click on one of the voting arrows.
return;
}
// If it is an unvote, the new vote value is 0,
// Otherwise it's 1 for an upvote, or -1 for a downvote.
var value = 0;
if (id.charAt(1) != 'u') {
value = id.charAt(0) == 'u' ? 1 : -1;
}
// The data to be sent to the server.
var d = {
comment_id: id.substring(2),
value: value
};
// Swap the vote and unvote links.
link.hide();
$('#' + id.charAt(0) + (id.charAt(1) == 'u' ? 'v' : 'u') + d.comment_id)
.show();
// The div the comment is displayed in.
var div = $('div#cd' + d.comment_id);
var data = div.data('comment');
// If this is not an unvote, and the other vote arrow has
// already been pressed, unpress it.
if ((d.value !== 0) && (data.vote === d.value * -1)) {
$('#' + (d.value == 1 ? 'd' : 'u') + 'u' + d.comment_id).hide();
$('#' + (d.value == 1 ? 'd' : 'u') + 'v' + d.comment_id).show();
}
// Update the comments rating in the local data.
data.rating += (data.vote === 0) ? d.value : (d.value - data.vote);
data.vote = d.value;
div.data('comment', data);
// Change the rating text.
div.find('.rating:first')
.text(data.rating + ' point' + (data.rating == 1 ? '' : 's'));
// Send the vote information to the server.
$.ajax({
type: "POST",
url: opts.processVoteURL,
data: d,
error: function(request, textStatus, error) {
showError('Oops, there was a problem casting that vote.');
}
});
}
/**
* Open a reply form used to reply to an existing comment.
*/
function openReply(id) {
// Swap out the reply link for the hide link
$('#rl' + id).hide();
$('#cr' + id).show();
// Add the reply li to the children ul.
var div = $(renderTemplate(replyTemplate, {id: id})).hide();
$('#cl' + id)
.prepend(div)
// Setup the submit handler for the reply form.
.find('#rf' + id)
.submit(function(event) {
event.preventDefault();
addComment($('#rf' + id));
closeReply(id);
})
.find('input[type=button]')
.click(function() {
closeReply(id);
});
div.slideDown('fast', function() {
$('#rf' + id).find('textarea').focus();
});
}
/**
* Close the reply form opened with openReply.
*/
function closeReply(id) {
// Remove the reply div from the DOM.
$('#rd' + id).slideUp('fast', function() {
$(this).remove();
});
// Swap out the hide link for the reply link
$('#cr' + id).hide();
$('#rl' + id).show();
}
/**
* Recursively sort a tree of comments using the comp comparator.
*/
function sortComments(comments) {
comments.sort(comp);
$.each(comments, function() {
this.children = sortComments(this.children);
});
return comments;
}
/**
* Get the children comments from a ul. If recursive is true,
* recursively include childrens' children.
*/
function getChildren(ul, recursive) {
var children = [];
ul.children().children("[id^='cd']")
.each(function() {
var comment = $(this).data('comment');
if (recursive)
comment.children = getChildren($(this).find('#cl' + comment.id), true);
children.push(comment);
});
return children;
}
/** Create a div to display a comment in. */
function createCommentDiv(comment) {
if (!comment.displayed && !opts.moderator) {
return $('<div class="moderate">Thank you! Your comment will show up '
+ 'once it is has been approved by a moderator.</div>');
}
// Prettify the comment rating.
comment.pretty_rating = comment.rating + ' point' +
(comment.rating == 1 ? '' : 's');
// Make a class (for displaying not yet moderated comments differently)
comment.css_class = comment.displayed ? '' : ' moderate';
// Create a div for this comment.
var context = $.extend({}, opts, comment);
var div = $(renderTemplate(commentTemplate, context));
// If the user has voted on this comment, highlight the correct arrow.
if (comment.vote) {
var direction = (comment.vote == 1) ? 'u' : 'd';
div.find('#' + direction + 'v' + comment.id).hide();
div.find('#' + direction + 'u' + comment.id).show();
}
if (opts.moderator || comment.text != '[deleted]') {
div.find('a.reply').show();
if (comment.proposal_diff)
div.find('#sp' + comment.id).show();
if (opts.moderator && !comment.displayed)
div.find('#cm' + comment.id).show();
if (opts.moderator || (opts.username == comment.username))
div.find('#dc' + comment.id).show();
}
return div;
}
/**
* A simple template renderer. Placeholders such as <%id%> are replaced
* by context['id'] with items being escaped. Placeholders such as <#id#>
* are not escaped.
*/
function renderTemplate(template, context) {
var esc = $(document.createElement('div'));
function handle(ph, escape) {
var cur = context;
$.each(ph.split('.'), function() {
cur = cur[this];
});
return escape ? esc.text(cur || "").html() : cur;
}
return template.replace(/<([%#])([\w\.]*)\1>/g, function() {
return handle(arguments[2], arguments[1] == '%' ? true : false);
});
}
/** Flash an error message briefly. */
function showError(message) {
$(document.createElement('div')).attr({'class': 'popup-error'})
.append($(document.createElement('div'))
.attr({'class': 'error-message'}).text(message))
.appendTo('body')
.fadeIn("slow")
.delay(2000)
.fadeOut("slow");
}
/** Add a link the user uses to open the comments popup. */
$.fn.comment = function() {
return this.each(function() {
var id = $(this).attr('id').substring(1);
var count = COMMENT_METADATA[id];
var title = count + ' comment' + (count == 1 ? '' : 's');
var image = count > 0 ? opts.commentBrightImage : opts.commentImage;
var addcls = count == 0 ? ' nocomment' : '';
$(this)
.append(
$(document.createElement('a')).attr({
href: '#',
'class': 'sphinx-comment-open' + addcls,
id: 'ao' + id
})
.append($(document.createElement('img')).attr({
src: image,
alt: 'comment',
title: title
}))
.click(function(event) {
event.preventDefault();
show($(this).attr('id').substring(2));
})
)
.append(
$(document.createElement('a')).attr({
href: '#',
'class': 'sphinx-comment-close hidden',
id: 'ah' + id
})
.append($(document.createElement('img')).attr({
src: opts.closeCommentImage,
alt: 'close',
title: 'close'
}))
.click(function(event) {
event.preventDefault();
hide($(this).attr('id').substring(2));
})
);
});
};
var opts = {
processVoteURL: '/_process_vote',
addCommentURL: '/_add_comment',
getCommentsURL: '/_get_comments',
acceptCommentURL: '/_accept_comment',
deleteCommentURL: '/_delete_comment',
commentImage: '/static/_static/comment.png',
closeCommentImage: '/static/_static/comment-close.png',
loadingImage: '/static/_static/ajax-loader.gif',
commentBrightImage: '/static/_static/comment-bright.png',
upArrow: '/static/_static/up.png',
downArrow: '/static/_static/down.png',
upArrowPressed: '/static/_static/up-pressed.png',
downArrowPressed: '/static/_static/down-pressed.png',
voting: false,
moderator: false
};
if (typeof COMMENT_OPTIONS != "undefined") {
opts = jQuery.extend(opts, COMMENT_OPTIONS);
}
var popupTemplate = '\
<div class="sphinx-comments" id="sc<%id%>">\
<p class="sort-options">\
Sort by:\
<a href="#" class="sort-option byrating">best rated</a>\
<a href="#" class="sort-option byascage">newest</a>\
<a href="#" class="sort-option byage">oldest</a>\
</p>\
<div class="comment-header">Comments</div>\
<div class="comment-loading" id="cn<%id%>">\
loading comments... <img src="<%loadingImage%>" alt="" /></div>\
<ul id="cl<%id%>" class="comment-ul"></ul>\
<div id="ca<%id%>">\
<p class="add-a-comment">Add a comment\
(<a href="#" class="comment-markup" id="ab<%id%>">markup</a>):</p>\
<div class="comment-markup-box" id="mb<%id%>">\
reStructured text markup: <i>*emph*</i>, <b>**strong**</b>, \
<code>``code``</code>, \
code blocks: <code>::</code> and an indented block after blank line</div>\
<form method="post" id="cf<%id%>" class="comment-form" action="">\
<textarea name="comment" cols="80"></textarea>\
<p class="propose-button">\
<a href="#" id="pc<%id%>" class="show-propose-change">\
Propose a change &#9657;\
</a>\
<a href="#" id="hc<%id%>" class="hide-propose-change">\
Propose a change &#9663;\
</a>\
</p>\
<textarea name="proposal" id="pt<%id%>" cols="80"\
spellcheck="false"></textarea>\
<input type="submit" value="Add comment" />\
<input type="hidden" name="node" value="<%id%>" />\
<input type="hidden" name="parent" value="" />\
</form>\
</div>\
</div>';
var commentTemplate = '\
<div id="cd<%id%>" class="sphinx-comment<%css_class%>">\
<div class="vote">\
<div class="arrow">\
<a href="#" id="uv<%id%>" class="vote" title="vote up">\
<img src="<%upArrow%>" />\
</a>\
<a href="#" id="uu<%id%>" class="un vote" title="vote up">\
<img src="<%upArrowPressed%>" />\
</a>\
</div>\
<div class="arrow">\
<a href="#" id="dv<%id%>" class="vote" title="vote down">\
<img src="<%downArrow%>" id="da<%id%>" />\
</a>\
<a href="#" id="du<%id%>" class="un vote" title="vote down">\
<img src="<%downArrowPressed%>" />\
</a>\
</div>\
</div>\
<div class="comment-content">\
<p class="tagline comment">\
<span class="user-id"><%username%></span>\
<span class="rating"><%pretty_rating%></span>\
<span class="delta"><%time.delta%></span>\
</p>\
<div class="comment-text comment"><#text#></div>\
<p class="comment-opts comment">\
<a href="#" class="reply hidden" id="rl<%id%>">reply &#9657;</a>\
<a href="#" class="close-reply" id="cr<%id%>">reply &#9663;</a>\
<a href="#" id="sp<%id%>" class="show-proposal">proposal &#9657;</a>\
<a href="#" id="hp<%id%>" class="hide-proposal">proposal &#9663;</a>\
<a href="#" id="dc<%id%>" class="delete-comment hidden">delete</a>\
<span id="cm<%id%>" class="moderation hidden">\
<a href="#" id="ac<%id%>" class="accept-comment">accept</a>\
</span>\
</p>\
<pre class="proposal" id="pr<%id%>">\
<#proposal_diff#>\
</pre>\
<ul class="comment-children" id="cl<%id%>"></ul>\
</div>\
<div class="clearleft"></div>\
</div>\
</div>';
var replyTemplate = '\
<li>\
<div class="reply-div" id="rd<%id%>">\
<form id="rf<%id%>">\
<textarea name="comment" cols="80"></textarea>\
<input type="submit" value="Add reply" />\
<input type="button" value="Cancel" />\
<input type="hidden" name="parent" value="<%id%>" />\
<input type="hidden" name="node" value="" />\
</form>\
</div>\
</li>';
$(document).ready(function() {
init();
});
})(jQuery);
$(document).ready(function() {
// add comment anchors for all paragraphs that are commentable
$('.sphinx-has-comment').comment();
// highlight search words in search results
$("div.context").each(function() {
var params = $.getQueryParameters();
var terms = (params.q) ? params.q[0].split(/\s+/) : [];
var result = $(this);
$.each(terms, function() {
result.highlightText(this.toLowerCase(), 'highlighted');
});
});
// directly open comment window if requested
var anchor = document.location.hash;
if (anchor.substring(0, 9) == '#comment-') {
$('#ao' + anchor.substring(9)).click();
document.location.hash = '#s' + anchor.substring(9);
}
});

View file

@ -321,6 +321,8 @@
<li><a href="manual/scripting-capabilities.html#map.bucketFillFromSelection">map.bucketFillFromSelection() (map method)</a>
</li>
<li><a href="manual/scripting-capabilities.html#map.clearOverlay">map.clearOverlay() (map method)</a>
</li>
<li><a href="manual/scripting-capabilities.html#map.commit">map.commit() (map method)</a>
</li>
<li><a href="manual/scripting-capabilities.html#map.getBlock">map.getBlock() (map method)</a>
</li>
@ -369,6 +371,8 @@
<li><a href="manual/scripting-capabilities.html#map.magicFill">map.magicFill() (map method)</a>
</li>
<li><a href="manual/scripting-capabilities.html#map.magicFillFromSelection">map.magicFillFromSelection() (map method)</a>
</li>
<li><a href="manual/scripting-capabilities.html#map.redraw">map.redraw() (map method)</a>
</li>
<li><a href="manual/scripting-capabilities.html#map.registerAction">map.registerAction() (map method)</a>
</li>

View file

@ -354,9 +354,9 @@
</div>
<div class="section" id="registering-script-actions">
<h2>Registering Script Actions<a class="headerlink" href="#registering-script-actions" title="Permalink to this headline"></a></h2>
<p>The grass-randomizer script above happens implicitly when the user paints on the map. However, other times we probably want to call the custom script on demand. One of the API function Porymap provides is the ability to trigger scripting functions from the <code class="docutils literal notranslate"><span class="pre">Tools</span></code> menu, or a keyboard shortcut. To do this, we will usually want to register the action when the project loads. Here is an example script where a couple custom actions are registered.</p>
<p>The grass-randomizer script above happens implicitly when the user paints on the map. However, other times we probably want to call the custom script on demand. One of the API functions Porymap provides is the ability to trigger scripting functions from the <code class="docutils literal notranslate"><span class="pre">Tools</span></code> menu, or a keyboard shortcut. To do this, we will usually want to register the action when the project loads. Here is an example script where some custom actions are registered.</p>
<div class="highlight-js notranslate"><div class="highlight"><pre><span></span><span class="kd">function</span> <span class="nx">applyNightTint</span><span class="p">()</span> <span class="p">{</span>
<span class="c1">// Apply night palette tinting...</span>
<span class="c1">// Apply night palette tinting...</span>
<span class="p">}</span>
<span class="c1">// Porymap callback when project is opened.</span>
@ -453,7 +453,7 @@
<dl class="js function">
<dt id="map.setBlock">
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">setBlock</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em>, <em class="sig-param">metatileId</em>, <em class="sig-param">collision</em>, <em class="sig-param">elevation</em><span class="sig-paren">)</span><a class="headerlink" href="#map.setBlock" title="Permalink to this definition"></a></dt>
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">setBlock</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em>, <em class="sig-param">metatileId</em>, <em class="sig-param">collision</em>, <em class="sig-param">elevation</em>, <em class="sig-param">forceRedraw = true</em>, <em class="sig-param">commitChanges = true</em><span class="sig-paren">)</span><a class="headerlink" href="#map.setBlock" title="Permalink to this definition"></a></dt>
<dd><p>Sets a block in the currently-opened map.</p>
<dl class="field-list simple">
<dt class="field-odd">Arguments</dt>
@ -463,6 +463,8 @@
<li><p><strong>metatileId</strong> (<em>number</em>) the metatile id of the block</p></li>
<li><p><strong>collision</strong> (<em>number</em>) the collision of the block (<code class="docutils literal notranslate"><span class="pre">0</span></code> = passable, <code class="docutils literal notranslate"><span class="pre">1</span></code> = impassable)</p></li>
<li><p><strong>elevation</strong> (<em>number</em>) the elevation of the block</p></li>
<li><p><strong>forceRedraw</strong> (<em>boolean</em>) Force the map view to refresh. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. Redrawing the map view is expensive, so set to <code class="docutils literal notranslate"><span class="pre">false</span></code> when making many consecutive map edits, and then redraw the map once using <code class="docutils literal notranslate"><span class="pre">map.redraw()</span></code>.</p></li>
<li><p><strong>commitChanges</strong> (<em>boolean</em>) Commit the changes to the maps edit/undo history. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. When making many related map edits, it can be useful to set this to <code class="docutils literal notranslate"><span class="pre">false</span></code>, and then commit all of them together with <code class="docutils literal notranslate"><span class="pre">map.commit()</span></code>.</p></li>
</ul>
</dd>
</dl>
@ -487,7 +489,7 @@
<dl class="js function">
<dt id="map.setMetatileId">
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">setMetatileId</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em>, <em class="sig-param">metatileId</em><span class="sig-paren">)</span><a class="headerlink" href="#map.setMetatileId" title="Permalink to this definition"></a></dt>
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">setMetatileId</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em>, <em class="sig-param">metatileId</em>, <em class="sig-param">forceRedraw = true</em>, <em class="sig-param">commitChanges = true</em><span class="sig-paren">)</span><a class="headerlink" href="#map.setMetatileId" title="Permalink to this definition"></a></dt>
<dd><p>Sets the metatile id of a block in the currently-opened map.</p>
<dl class="field-list simple">
<dt class="field-odd">Arguments</dt>
@ -495,6 +497,8 @@
<li><p><strong>x</strong> (<em>number</em>) x coordinate of the block</p></li>
<li><p><strong>y</strong> (<em>number</em>) y coordinate of the block</p></li>
<li><p><strong>metatileId</strong> (<em>number</em>) the metatile id of the block</p></li>
<li><p><strong>forceRedraw</strong> (<em>boolean</em>) Force the map view to refresh. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. Redrawing the map view is expensive, so set to <code class="docutils literal notranslate"><span class="pre">false</span></code> when making many consecutive map edits, and then redraw the map once using <code class="docutils literal notranslate"><span class="pre">map.redraw()</span></code>.</p></li>
<li><p><strong>commitChanges</strong> (<em>boolean</em>) Commit the changes to the maps edit/undo history. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. When making many related map edits, it can be useful to set this to <code class="docutils literal notranslate"><span class="pre">false</span></code>, and then commit all of them together with <code class="docutils literal notranslate"><span class="pre">map.commit()</span></code>.</p></li>
</ul>
</dd>
</dl>
@ -519,7 +523,7 @@
<dl class="js function">
<dt id="map.setCollision">
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">setCollision</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em>, <em class="sig-param">collision</em><span class="sig-paren">)</span><a class="headerlink" href="#map.setCollision" title="Permalink to this definition"></a></dt>
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">setCollision</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em>, <em class="sig-param">collision</em>, <em class="sig-param">forceRedraw = true</em>, <em class="sig-param">commitChanges = true</em><span class="sig-paren">)</span><a class="headerlink" href="#map.setCollision" title="Permalink to this definition"></a></dt>
<dd><p>Sets the collision of a block in the currently-opened map. (<code class="docutils literal notranslate"><span class="pre">0</span></code> = passable, <code class="docutils literal notranslate"><span class="pre">1</span></code> = impassable)</p>
<dl class="field-list simple">
<dt class="field-odd">Arguments</dt>
@ -527,6 +531,8 @@
<li><p><strong>x</strong> (<em>number</em>) x coordinate of the block</p></li>
<li><p><strong>y</strong> (<em>number</em>) y coordinate of the block</p></li>
<li><p><strong>collision</strong> (<em>number</em>) the collision of the block</p></li>
<li><p><strong>forceRedraw</strong> (<em>boolean</em>) Force the map view to refresh. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. Redrawing the map view is expensive, so set to <code class="docutils literal notranslate"><span class="pre">false</span></code> when making many consecutive map edits, and then redraw the map once using <code class="docutils literal notranslate"><span class="pre">map.redraw()</span></code>.</p></li>
<li><p><strong>commitChanges</strong> (<em>boolean</em>) Commit the changes to the maps edit/undo history. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. When making many related map edits, it can be useful to set this to <code class="docutils literal notranslate"><span class="pre">false</span></code>, and then commit all of them together with <code class="docutils literal notranslate"><span class="pre">map.commit()</span></code>.</p></li>
</ul>
</dd>
</dl>
@ -551,7 +557,7 @@
<dl class="js function">
<dt id="map.setElevation">
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">setElevation</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em>, <em class="sig-param">elevation</em><span class="sig-paren">)</span><a class="headerlink" href="#map.setElevation" title="Permalink to this definition"></a></dt>
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">setElevation</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em>, <em class="sig-param">elevation</em>, <em class="sig-param">forceRedraw = true</em>, <em class="sig-param">commitChanges = true</em><span class="sig-paren">)</span><a class="headerlink" href="#map.setElevation" title="Permalink to this definition"></a></dt>
<dd><p>Sets the elevation of a block in the currently-opened map.</p>
<dl class="field-list simple">
<dt class="field-odd">Arguments</dt>
@ -559,6 +565,8 @@
<li><p><strong>x</strong> (<em>number</em>) x coordinate of the block</p></li>
<li><p><strong>y</strong> (<em>number</em>) y coordinate of the block</p></li>
<li><p><strong>elevation</strong> (<em>number</em>) the elevation of the block</p></li>
<li><p><strong>forceRedraw</strong> (<em>boolean</em>) Force the map view to refresh. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. Redrawing the map view is expensive, so set to <code class="docutils literal notranslate"><span class="pre">false</span></code> when making many consecutive map edits, and then redraw the map once using <code class="docutils literal notranslate"><span class="pre">map.redraw()</span></code>.</p></li>
<li><p><strong>commitChanges</strong> (<em>boolean</em>) Commit the changes to the maps edit/undo history. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. When making many related map edits, it can be useful to set this to <code class="docutils literal notranslate"><span class="pre">false</span></code>, and then commit all of them together with <code class="docutils literal notranslate"><span class="pre">map.commit()</span></code>.</p></li>
</ul>
</dd>
</dl>
@ -566,13 +574,15 @@
<dl class="js function">
<dt id="map.setBlocksFromSelection">
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">setBlocksFromSelection</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em><span class="sig-paren">)</span><a class="headerlink" href="#map.setBlocksFromSelection" title="Permalink to this definition"></a></dt>
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">setBlocksFromSelection</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em>, <em class="sig-param">forceRedraw = true</em>, <em class="sig-param">commitChanges = true</em><span class="sig-paren">)</span><a class="headerlink" href="#map.setBlocksFromSelection" title="Permalink to this definition"></a></dt>
<dd><p>Sets blocks on the map using the users current metatile selection.</p>
<dl class="field-list simple">
<dt class="field-odd">Arguments</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> (<em>number</em>) initial x coordinate</p></li>
<li><p><strong>y</strong> (<em>number</em>) initial y coordinate</p></li>
<li><p><strong>forceRedraw</strong> (<em>boolean</em>) Force the map view to refresh. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. Redrawing the map view is expensive, so set to <code class="docutils literal notranslate"><span class="pre">false</span></code> when making many consecutive map edits, and then redraw the map once using <code class="docutils literal notranslate"><span class="pre">map.redraw()</span></code>.</p></li>
<li><p><strong>commitChanges</strong> (<em>boolean</em>) Commit the changes to the maps edit/undo history. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. When making many related map edits, it can be useful to set this to <code class="docutils literal notranslate"><span class="pre">false</span></code>, and then commit all of them together with <code class="docutils literal notranslate"><span class="pre">map.commit()</span></code>.</p></li>
</ul>
</dd>
</dl>
@ -580,7 +590,7 @@
<dl class="js function">
<dt id="map.bucketFill">
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">bucketFill</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em>, <em class="sig-param">metatileId</em><span class="sig-paren">)</span><a class="headerlink" href="#map.bucketFill" title="Permalink to this definition"></a></dt>
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">bucketFill</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em>, <em class="sig-param">metatileId</em>, <em class="sig-param">forceRedraw = true</em>, <em class="sig-param">commitChanges = true</em><span class="sig-paren">)</span><a class="headerlink" href="#map.bucketFill" title="Permalink to this definition"></a></dt>
<dd><p>Performs a bucket fill of a metatile id, starting at the given coordinates.</p>
<dl class="field-list simple">
<dt class="field-odd">Arguments</dt>
@ -588,6 +598,8 @@
<li><p><strong>x</strong> (<em>number</em>) initial x coordinate</p></li>
<li><p><strong>y</strong> (<em>number</em>) initial y coordinate</p></li>
<li><p><strong>metatileId</strong> (<em>number</em>) metatile id to fill</p></li>
<li><p><strong>forceRedraw</strong> (<em>boolean</em>) Force the map view to refresh. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. Redrawing the map view is expensive, so set to <code class="docutils literal notranslate"><span class="pre">false</span></code> when making many consecutive map edits, and then redraw the map once using <code class="docutils literal notranslate"><span class="pre">map.redraw()</span></code>.</p></li>
<li><p><strong>commitChanges</strong> (<em>boolean</em>) Commit the changes to the maps edit/undo history. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. When making many related map edits, it can be useful to set this to <code class="docutils literal notranslate"><span class="pre">false</span></code>, and then commit all of them together with <code class="docutils literal notranslate"><span class="pre">map.commit()</span></code>.</p></li>
</ul>
</dd>
</dl>
@ -595,13 +607,15 @@
<dl class="js function">
<dt id="map.bucketFillFromSelection">
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">bucketFillFromSelection</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em><span class="sig-paren">)</span><a class="headerlink" href="#map.bucketFillFromSelection" title="Permalink to this definition"></a></dt>
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">bucketFillFromSelection</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em>, <em class="sig-param">forceRedraw = true</em>, <em class="sig-param">commitChanges = true</em><span class="sig-paren">)</span><a class="headerlink" href="#map.bucketFillFromSelection" title="Permalink to this definition"></a></dt>
<dd><p>Performs a bucket fill using the users current metatile selection, starting at the given coordinates.</p>
<dl class="field-list simple">
<dt class="field-odd">Arguments</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> (<em>number</em>) initial x coordinate</p></li>
<li><p><strong>y</strong> (<em>number</em>) initial y coordinate</p></li>
<li><p><strong>forceRedraw</strong> (<em>boolean</em>) Force the map view to refresh. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. Redrawing the map view is expensive, so set to <code class="docutils literal notranslate"><span class="pre">false</span></code> when making many consecutive map edits, and then redraw the map once using <code class="docutils literal notranslate"><span class="pre">map.redraw()</span></code>.</p></li>
<li><p><strong>commitChanges</strong> (<em>boolean</em>) Commit the changes to the maps edit/undo history. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. When making many related map edits, it can be useful to set this to <code class="docutils literal notranslate"><span class="pre">false</span></code>, and then commit all of them together with <code class="docutils literal notranslate"><span class="pre">map.commit()</span></code>.</p></li>
</ul>
</dd>
</dl>
@ -609,7 +623,7 @@
<dl class="js function">
<dt id="map.magicFill">
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">magicFill</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em>, <em class="sig-param">metatileId</em><span class="sig-paren">)</span><a class="headerlink" href="#map.magicFill" title="Permalink to this definition"></a></dt>
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">magicFill</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em>, <em class="sig-param">metatileId</em>, <em class="sig-param">forceRedraw = true</em>, <em class="sig-param">commitChanges = true</em><span class="sig-paren">)</span><a class="headerlink" href="#map.magicFill" title="Permalink to this definition"></a></dt>
<dd><p>Performs a magic fill of a metatile id, starting at the given coordinates.</p>
<dl class="field-list simple">
<dt class="field-odd">Arguments</dt>
@ -617,6 +631,8 @@
<li><p><strong>x</strong> (<em>number</em>) initial x coordinate</p></li>
<li><p><strong>y</strong> (<em>number</em>) initial y coordinate</p></li>
<li><p><strong>metatileId</strong> (<em>number</em>) metatile id to magic fill</p></li>
<li><p><strong>forceRedraw</strong> (<em>boolean</em>) Force the map view to refresh. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. Redrawing the map view is expensive, so set to <code class="docutils literal notranslate"><span class="pre">false</span></code> when making many consecutive map edits, and then redraw the map once using <code class="docutils literal notranslate"><span class="pre">map.redraw()</span></code>.</p></li>
<li><p><strong>commitChanges</strong> (<em>boolean</em>) Commit the changes to the maps edit/undo history. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. When making many related map edits, it can be useful to set this to <code class="docutils literal notranslate"><span class="pre">false</span></code>, and then commit all of them together with <code class="docutils literal notranslate"><span class="pre">map.commit()</span></code>.</p></li>
</ul>
</dd>
</dl>
@ -624,13 +640,15 @@
<dl class="js function">
<dt id="map.magicFillFromSelection">
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">magicFillFromSelection</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em><span class="sig-paren">)</span><a class="headerlink" href="#map.magicFillFromSelection" title="Permalink to this definition"></a></dt>
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">magicFillFromSelection</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em>, <em class="sig-param">forceRedraw = true</em>, <em class="sig-param">commitChanges = true</em><span class="sig-paren">)</span><a class="headerlink" href="#map.magicFillFromSelection" title="Permalink to this definition"></a></dt>
<dd><p>Performs a magic fill using the users current metatile selection, starting at the given coordinates.</p>
<dl class="field-list simple">
<dt class="field-odd">Arguments</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> (<em>number</em>) initial x coordinate</p></li>
<li><p><strong>y</strong> (<em>number</em>) initial y coordinate</p></li>
<li><p><strong>forceRedraw</strong> (<em>boolean</em>) Force the map view to refresh. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. Redrawing the map view is expensive, so set to <code class="docutils literal notranslate"><span class="pre">false</span></code> when making many consecutive map edits, and then redraw the map once using <code class="docutils literal notranslate"><span class="pre">map.redraw()</span></code>.</p></li>
<li><p><strong>commitChanges</strong> (<em>boolean</em>) Commit the changes to the maps edit/undo history. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. When making many related map edits, it can be useful to set this to <code class="docutils literal notranslate"><span class="pre">false</span></code>, and then commit all of them together with <code class="docutils literal notranslate"><span class="pre">map.commit()</span></code>.</p></li>
</ul>
</dd>
</dl>
@ -638,13 +656,15 @@
<dl class="js function">
<dt id="map.shift">
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">shift</code><span class="sig-paren">(</span><em class="sig-param">xDelta</em>, <em class="sig-param">yDelta</em><span class="sig-paren">)</span><a class="headerlink" href="#map.shift" title="Permalink to this definition"></a></dt>
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">shift</code><span class="sig-paren">(</span><em class="sig-param">xDelta</em>, <em class="sig-param">yDelta</em>, <em class="sig-param">forceRedraw = true</em>, <em class="sig-param">commitChanges = true</em><span class="sig-paren">)</span><a class="headerlink" href="#map.shift" title="Permalink to this definition"></a></dt>
<dd><p>Performs a shift on the maps blocks.</p>
<dl class="field-list simple">
<dt class="field-odd">Arguments</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>xDelta</strong> (<em>number</em>) number of blocks to shift horizontally</p></li>
<li><p><strong>yDelta</strong> (<em>number</em>) number of blocks to shift vertically</p></li>
<li><p><strong>forceRedraw</strong> (<em>boolean</em>) Force the map view to refresh. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. Redrawing the map view is expensive, so set to <code class="docutils literal notranslate"><span class="pre">false</span></code> when making many consecutive map edits, and then redraw the map once using <code class="docutils literal notranslate"><span class="pre">map.redraw()</span></code>.</p></li>
<li><p><strong>commitChanges</strong> (<em>boolean</em>) Commit the changes to the maps edit/undo history. Defaults to <code class="docutils literal notranslate"><span class="pre">true</span></code>. When making many related map edits, it can be useful to set this to <code class="docutils literal notranslate"><span class="pre">false</span></code>, and then commit all of them together with <code class="docutils literal notranslate"><span class="pre">map.commit()</span></code>.</p></li>
</ul>
</dd>
</dl>
@ -723,6 +743,18 @@
</dl>
</dd></dl>
<dl class="js function">
<dt id="map.redraw">
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">redraw</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#map.redraw" title="Permalink to this definition"></a></dt>
<dd><p>Redraws the entire map area. Useful when delaying map redraws using <code class="docutils literal notranslate"><span class="pre">forceRedraw</span> <span class="pre">=</span> <span class="pre">false</span></code> in certain map editing functions.</p>
</dd></dl>
<dl class="js function">
<dt id="map.commit">
<code class="sig-prename descclassname">map.</code><code class="sig-name descname">commit</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#map.commit" title="Permalink to this definition"></a></dt>
<dd><p>Commits any uncommitted changes to the maps edit/undo history. Useful when delaying commits using <code class="docutils literal notranslate"><span class="pre">commitChanges</span> <span class="pre">=</span> <span class="pre">false</span></code> in certain map editing functions.</p>
</dd></dl>
</div>
<div class="section" id="map-overlay-functions">
<h4>Map Overlay Functions<a class="headerlink" href="#map-overlay-functions" title="Permalink to this headline"></a></h4>

Binary file not shown.

File diff suppressed because one or more lines are too long

View file

@ -68,12 +68,12 @@ Let's test the script out by re-launching Porymap. If we try to paint grass on t
Registering Script Actions
--------------------------
The grass-randomizer script above happens implicitly when the user paints on the map. However, other times we probably want to call the custom script on demand. One of the API function Porymap provides is the ability to trigger scripting functions from the ``Tools`` menu, or a keyboard shortcut. To do this, we will usually want to register the action when the project loads. Here is an example script where a couple custom actions are registered.
The grass-randomizer script above happens implicitly when the user paints on the map. However, other times we probably want to call the custom script on demand. One of the API functions Porymap provides is the ability to trigger scripting functions from the ``Tools`` menu, or a keyboard shortcut. To do this, we will usually want to register the action when the project loads. Here is an example script where some custom actions are registered.
.. code-block:: js
function applyNightTint() {
// Apply night palette tinting...
// Apply night palette tinting...
}
// Porymap callback when project is opened.
@ -136,7 +136,7 @@ The following functions are related to editing the map's blocks or retrieving in
:param number y: y coordinate of the block
:returns {metatileId, collision, elevation, rawValue}: the block object
.. js:function:: map.setBlock(x, y, metatileId, collision, elevation)
.. js:function:: map.setBlock(x, y, metatileId, collision, elevation, forceRedraw = true, commitChanges = true)
Sets a block in the currently-opened map.
@ -145,6 +145,8 @@ The following functions are related to editing the map's blocks or retrieving in
:param number metatileId: the metatile id of the block
:param number collision: the collision of the block (``0`` = passable, ``1`` = impassable)
:param number elevation: the elevation of the block
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.getMetatileId(x, y)
@ -154,13 +156,15 @@ The following functions are related to editing the map's blocks or retrieving in
:param number y: y coordinate of the block
:returns number: the metatile id of the block
.. js:function:: map.setMetatileId(x, y, metatileId)
.. js:function:: map.setMetatileId(x, y, metatileId, forceRedraw = true, commitChanges = true)
Sets the metatile id of a block in the currently-opened map.
:param number x: x coordinate of the block
:param number y: y coordinate of the block
:param number metatileId: the metatile id of the block
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.getCollision(x, y)
@ -170,13 +174,15 @@ The following functions are related to editing the map's blocks or retrieving in
:param number y: y coordinate of the block
:returns number: the collision of the block
.. js:function:: map.setCollision(x, y, collision)
.. js:function:: map.setCollision(x, y, collision, forceRedraw = true, commitChanges = true)
Sets the collision of a block in the currently-opened map. (``0`` = passable, ``1`` = impassable)
:param number x: x coordinate of the block
:param number y: y coordinate of the block
:param number collision: the collision of the block
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.getElevation(x, y)
@ -186,57 +192,71 @@ The following functions are related to editing the map's blocks or retrieving in
:param number y: y coordinate of the block
:returns number: the elevation of the block
.. js:function:: map.setElevation(x, y, elevation)
.. js:function:: map.setElevation(x, y, elevation, forceRedraw = true, commitChanges = true)
Sets the elevation of a block in the currently-opened map.
:param number x: x coordinate of the block
:param number y: y coordinate of the block
:param number elevation: the elevation of the block
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.setBlocksFromSelection(x, y)
.. js:function:: map.setBlocksFromSelection(x, y, forceRedraw = true, commitChanges = true)
Sets blocks on the map using the user's current metatile selection.
:param number x: initial x coordinate
:param number y: initial y coordinate
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.bucketFill(x, y, metatileId)
.. js:function:: map.bucketFill(x, y, metatileId, forceRedraw = true, commitChanges = true)
Performs a bucket fill of a metatile id, starting at the given coordinates.
:param number x: initial x coordinate
:param number y: initial y coordinate
:param number metatileId: metatile id to fill
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.bucketFillFromSelection(x, y)
.. js:function:: map.bucketFillFromSelection(x, y, forceRedraw = true, commitChanges = true)
Performs a bucket fill using the user's current metatile selection, starting at the given coordinates.
:param number x: initial x coordinate
:param number y: initial y coordinate
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.magicFill(x, y, metatileId)
.. js:function:: map.magicFill(x, y, metatileId, forceRedraw = true, commitChanges = true)
Performs a magic fill of a metatile id, starting at the given coordinates.
:param number x: initial x coordinate
:param number y: initial y coordinate
:param number metatileId: metatile id to magic fill
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.magicFillFromSelection(x, y)
.. js:function:: map.magicFillFromSelection(x, y, forceRedraw = true, commitChanges = true)
Performs a magic fill using the user's current metatile selection, starting at the given coordinates.
:param number x: initial x coordinate
:param number y: initial y coordinate
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.shift(xDelta, yDelta)
.. js:function:: map.shift(xDelta, yDelta, forceRedraw = true, commitChanges = true)
Performs a shift on the map's blocks.
:param number xDelta: number of blocks to shift horizontally
:param number yDelta: number of blocks to shift vertically
:param boolean forceRedraw: Force the map view to refresh. Defaults to ``true``. Redrawing the map view is expensive, so set to ``false`` when making many consecutive map edits, and then redraw the map once using ``map.redraw()``.
:param boolean commitChanges: Commit the changes to the map's edit/undo history. Defaults to ``true``. When making many related map edits, it can be useful to set this to ``false``, and then commit all of them together with ``map.commit()``.
.. js:function:: map.getDimensions()
@ -275,6 +295,14 @@ The following functions are related to editing the map's blocks or retrieving in
:param number height: height in blocks
.. js:function:: map.redraw()
Redraws the entire map area. Useful when delaying map redraws using ``forceRedraw = false`` in certain map editing functions.
.. js:function:: map.commit()
Commits any uncommitted changes to the map's edit/undo history. Useful when delaying commits using ``commitChanges = false`` in certain map editing functions.
Map Overlay Functions
^^^^^^^^^^^^^^^^^^^^^