areaspawnr
Advanced tools
Comparing version 0.8.0 to 0.8.1
@@ -1,3 +0,3 @@ | ||
import { IArea, ILocation, IMap, IPreThingsContainers, IPreThingSettings } from "mapscreatr"; | ||
import { IAreaSpawnrSettings } from "./types"; | ||
import { Area, Location, Map, PreActorsContainers, PreActorSettings } from "mapscreatr"; | ||
import { AreaSpawnrSettings } from "./types"; | ||
/** | ||
@@ -20,7 +20,7 @@ * Loads EightBittr maps to spawn and unspawn areas on demand. | ||
/** | ||
* Function for when a PreThing is to be spawned. | ||
* Function for when a PreActor is to be spawned. | ||
*/ | ||
private readonly onSpawn?; | ||
/** | ||
* Function for when a PreThing is to be un-spawned. | ||
* Function for when a PreActor is to be un-spawned. | ||
*/ | ||
@@ -53,5 +53,5 @@ private readonly onUnspawn?; | ||
/** | ||
* The current Area's listing of PreThings. | ||
* The current Area's listing of PreActors. | ||
*/ | ||
private prethings; | ||
private preactors; | ||
/** | ||
@@ -62,3 +62,3 @@ * Initializes a new instance of the AreaSpawnr class. | ||
*/ | ||
constructor(settings: IAreaSpawnrSettings); | ||
constructor(settings: AreaSpawnrSettings); | ||
/** | ||
@@ -79,3 +79,3 @@ * @returns The attribute names to be copied to MapScreener. | ||
*/ | ||
getMap(name?: string): IMap; | ||
getMap(name?: string): Map; | ||
/** | ||
@@ -87,3 +87,3 @@ * Simple getter pipe to the internal MapsCreator.getMaps() function. | ||
getMaps(): { | ||
[i: string]: IMap; | ||
[i: string]: Map; | ||
}; | ||
@@ -93,3 +93,3 @@ /** | ||
*/ | ||
getArea(): IArea; | ||
getArea(): Area; | ||
/** | ||
@@ -103,14 +103,14 @@ * @returns The name of the current Area. | ||
*/ | ||
getLocation(location: string): ILocation; | ||
getLocation(location: string): Location; | ||
/** | ||
* @returns The most recently entered Location in the current Area. | ||
*/ | ||
getLocationEntered(): ILocation; | ||
getLocationEntered(): Location; | ||
/** | ||
* Simple getter function for the internal prethings object. This will be | ||
* Simple getter function for the internal preactors object. This will be | ||
* undefined before the first call to setMap. | ||
* | ||
* @returns A listing of the current area's Prethings. | ||
* @returns A listing of the current area's Preactors. | ||
*/ | ||
getPreThings(): IPreThingsContainers; | ||
getPreActors(): PreActorsContainers; | ||
/** | ||
@@ -126,6 +126,6 @@ * Sets the currently manipulated Map in the handler to be the one under a | ||
*/ | ||
setMap(name: string, location?: string): IMap; | ||
setMap(name: string, location?: string): Map; | ||
/** | ||
* Goes to a particular location in the given map. Area attributes are | ||
* copied to the MapScreener, PreThings are loaded, and stretches and afters | ||
* copied to the MapScreener, PreActors are loaded, and stretches and afters | ||
* are checked. | ||
@@ -136,3 +136,3 @@ * | ||
*/ | ||
setLocation(name: string): ILocation; | ||
setLocation(name: string): Location; | ||
/** | ||
@@ -144,3 +144,3 @@ * Applies the stretchAdd Function to each given "stretch" command and | ||
*/ | ||
setStretches(stretchesRaw: (string | IPreThingSettings)[]): void; | ||
setStretches(stretchesRaw: (string | PreActorSettings)[]): void; | ||
/** | ||
@@ -152,9 +152,9 @@ * Applies the afterAdd Function to each given "after" command and stores | ||
*/ | ||
setAfters(aftersRaw: (string | IPreThingSettings)[]): void; | ||
setAfters(aftersRaw: (string | PreActorSettings)[]): void; | ||
/** | ||
* Calls onSpawn on every PreThing touched by the given bounding box, | ||
* Calls onSpawn on every PreActor touched by the given bounding box, | ||
* determined in order of the given direction. This is a simple wrapper | ||
* around applySpawnAction that also gives it true as the status. | ||
* | ||
* @param direction The direction by which to order PreThings, as "xInc", | ||
* @param direction The direction by which to order PreActors, as "xInc", | ||
* "xDec", "yInc", or "yDec". | ||
@@ -168,7 +168,7 @@ * @param top The upper-most bound to spawn within. | ||
/** | ||
* Calls onUnspawn on every PreThing touched by the given bounding box, | ||
* Calls onUnspawn on every PreActor touched by the given bounding box, | ||
* determined in order of the given direction. This is a simple wrapper | ||
* around applySpawnAction that also gives it false as the status. | ||
* | ||
* @param direction The direction by which to order PreThings, as "xInc", | ||
* @param direction The direction by which to order PreActors, as "xInc", | ||
* "xDec", "yInc", or "yDec". | ||
@@ -182,6 +182,6 @@ * @param top The upper-most bound to spawn within. | ||
/** | ||
* Calls onUnspawn on every PreThing touched by the given bounding box, | ||
* Calls onUnspawn on every PreActor touched by the given bounding box, | ||
* determined in order of the given direction. This is used both to spawn | ||
* and un-spawn PreThings, such as during QuadsKeepr shifting. The given | ||
* status is used as a filter: all PreThings that already have the status | ||
* and un-spawn PreActors, such as during QuadsKeepr shifting. The given | ||
* status is used as a filter: all PreActors that already have the status | ||
* (generally true or false as spawned or unspawned, respectively) will have | ||
@@ -191,6 +191,6 @@ * the callback called on them. | ||
* @param callback The callback to be run whenever a matching matching | ||
* PreThing is found. | ||
* @param status The spawn status to match PreThings against. Only PreThings | ||
* PreActor is found. | ||
* @param status The spawn status to match PreActors against. Only PreActors | ||
* with .spawned === status will have the callback applied. | ||
* @param direction The direction by which to order PreThings, as "xInc", | ||
* @param direction The direction by which to order PreActors, as "xInc", | ||
* "xDec", "yInc", or "yDec". | ||
@@ -197,0 +197,0 @@ * @param top The upper-most bound to apply within. |
@@ -26,5 +26,5 @@ define(["require", "exports"], function (require, exports) { | ||
* given. This is useful for generically finding boundaries when the | ||
* direction isn't known, such as in findPreThingsSpawnStart and -End. | ||
* direction isn't known, such as in findPreActorsSpawnStart and -End. | ||
* | ||
* @param direction The direction by which to order PreThings, as "xInc", | ||
* @param direction The direction by which to order PreActors, as "xInc", | ||
* "xDec", "yInc", or "yDec". | ||
@@ -52,9 +52,9 @@ * @param top The upper-most bound to apply within. | ||
/** | ||
* Finds the index from which PreThings should stop having an action | ||
* Finds the index from which PreActors should stop having an action | ||
* applied to them in applySpawnAction. This is less efficient than the | ||
* unused version below, but is more reliable for slightly unsorted groups. | ||
* | ||
* @param direction The direction by which to order PreThings, as "xInc", | ||
* @param direction The direction by which to order PreActors, as "xInc", | ||
* "xDec", "yInc", or "yDec". | ||
* @param group The group to find a PreThing index within. | ||
* @param group The group to find a PreActor index within. | ||
* @param _mid The middle of the group. This is currently unused. | ||
@@ -65,5 +65,5 @@ * @param top The upper-most bound to apply within. | ||
* @param left The left-most bound to apply within. | ||
* @returns The index to start spawning PreThings from. | ||
* @returns The index to start spawning PreActors from. | ||
*/ | ||
const findPreThingsSpawnStart = (direction, group, top, right, bottom, left) => { | ||
const findPreActorsSpawnStart = (direction, group, top, right, bottom, left) => { | ||
const directionKey = directionKeys[direction]; | ||
@@ -79,9 +79,9 @@ const directionEnd = getDirectionEnd(directionKey, top, right, bottom, left); | ||
/** | ||
* Finds the index from which PreThings should stop having an action | ||
* Finds the index from which PreActors should stop having an action | ||
* applied to them in applySpawnAction. This is less efficient than the | ||
* unused version below, but is more reliable for slightly unsorted groups. | ||
* | ||
* @param direction The direction by which to order PreThings, as "xInc", | ||
* @param direction The direction by which to order PreActors, as "xInc", | ||
* "xDec", "yInc", or "yDec". | ||
* @param group The group to find a PreThing index within. | ||
* @param group The group to find a PreActor index within. | ||
* @param _mid The middle of the group. This is currently unused. | ||
@@ -92,5 +92,5 @@ * @param top The upper-most bound to apply within. | ||
* @param left The left-most bound to apply within. | ||
* @returns The index to stop spawning PreThings from. | ||
* @returns The index to stop spawning PreActors from. | ||
*/ | ||
const findPreThingsSpawnEnd = (direction, group, top, right, bottom, left) => { | ||
const findPreActorsSpawnEnd = (direction, group, top, right, bottom, left) => { | ||
const directionKey = directionKeys[direction]; | ||
@@ -180,9 +180,9 @@ const directionKeyOpposite = directionKeys[directionOpposites[direction]]; | ||
/** | ||
* Simple getter function for the internal prethings object. This will be | ||
* Simple getter function for the internal preactors object. This will be | ||
* undefined before the first call to setMap. | ||
* | ||
* @returns A listing of the current area's Prethings. | ||
* @returns A listing of the current area's Preactors. | ||
*/ | ||
getPreThings() { | ||
return this.prethings; | ||
getPreActors() { | ||
return this.preactors; | ||
} | ||
@@ -214,3 +214,3 @@ /** | ||
* Goes to a particular location in the given map. Area attributes are | ||
* copied to the MapScreener, PreThings are loaded, and stretches and afters | ||
* copied to the MapScreener, PreActors are loaded, and stretches and afters | ||
* are checked. | ||
@@ -238,5 +238,5 @@ * | ||
} | ||
// Reset the prethings object, enabling it to be used as a fresh start | ||
// Reset the preactors object, enabling it to be used as a fresh start | ||
// For the new Area/Location placements | ||
this.prethings = this.mapsCreator.getPreThings(location.area); | ||
this.preactors = this.mapsCreator.getPreActors(location.area); | ||
// Optional: set stretch commands | ||
@@ -281,7 +281,7 @@ if (this.areaCurrent.stretches) { | ||
/** | ||
* Calls onSpawn on every PreThing touched by the given bounding box, | ||
* Calls onSpawn on every PreActor touched by the given bounding box, | ||
* determined in order of the given direction. This is a simple wrapper | ||
* around applySpawnAction that also gives it true as the status. | ||
* | ||
* @param direction The direction by which to order PreThings, as "xInc", | ||
* @param direction The direction by which to order PreActors, as "xInc", | ||
* "xDec", "yInc", or "yDec". | ||
@@ -299,7 +299,7 @@ * @param top The upper-most bound to spawn within. | ||
/** | ||
* Calls onUnspawn on every PreThing touched by the given bounding box, | ||
* Calls onUnspawn on every PreActor touched by the given bounding box, | ||
* determined in order of the given direction. This is a simple wrapper | ||
* around applySpawnAction that also gives it false as the status. | ||
* | ||
* @param direction The direction by which to order PreThings, as "xInc", | ||
* @param direction The direction by which to order PreActors, as "xInc", | ||
* "xDec", "yInc", or "yDec". | ||
@@ -317,6 +317,6 @@ * @param top The upper-most bound to spawn within. | ||
/** | ||
* Calls onUnspawn on every PreThing touched by the given bounding box, | ||
* Calls onUnspawn on every PreActor touched by the given bounding box, | ||
* determined in order of the given direction. This is used both to spawn | ||
* and un-spawn PreThings, such as during QuadsKeepr shifting. The given | ||
* status is used as a filter: all PreThings that already have the status | ||
* and un-spawn PreActors, such as during QuadsKeepr shifting. The given | ||
* status is used as a filter: all PreActors that already have the status | ||
* (generally true or false as spawned or unspawned, respectively) will have | ||
@@ -326,6 +326,6 @@ * the callback called on them. | ||
* @param callback The callback to be run whenever a matching matching | ||
* PreThing is found. | ||
* @param status The spawn status to match PreThings against. Only PreThings | ||
* PreActor is found. | ||
* @param status The spawn status to match PreActors against. Only PreActors | ||
* with .spawned === status will have the callback applied. | ||
* @param direction The direction by which to order PreThings, as "xInc", | ||
* @param direction The direction by which to order PreActors, as "xInc", | ||
* "xDec", "yInc", or "yDec". | ||
@@ -338,24 +338,24 @@ * @param top The upper-most bound to apply within. | ||
applySpawnAction(callback, status, direction, top, right, bottom, left) { | ||
// For each group of PreThings currently able to spawn... | ||
for (const name in this.prethings) { | ||
if (!{}.hasOwnProperty.call(this.prethings, name)) { | ||
// For each group of PreActors currently able to spawn... | ||
for (const name in this.preactors) { | ||
if (!{}.hasOwnProperty.call(this.preactors, name)) { | ||
continue; | ||
} | ||
// Don't bother trying to spawn the group if it has no members | ||
const group = this.prethings[name][direction]; | ||
const group = this.preactors[name][direction]; | ||
if (group.length === 0) { | ||
continue; | ||
} | ||
// Find the start and end points within the PreThings Array | ||
// Find the start and end points within the PreActors Array | ||
// Ex. if direction="xInc", go from .left >= left to .left <= right | ||
const start = findPreThingsSpawnStart(direction, group, top, right, bottom, left); | ||
const end = findPreThingsSpawnEnd(direction, group, top, right, bottom, left); | ||
// Loop through all the directionally valid PreThings, spawning if | ||
const start = findPreActorsSpawnStart(direction, group, top, right, bottom, left); | ||
const end = findPreActorsSpawnEnd(direction, group, top, right, bottom, left); | ||
// Loop through all the directionally valid PreActors, spawning if | ||
// They're within the bounding box | ||
for (let i = start; i <= end; i += 1) { | ||
const prething = group[i]; | ||
// For example: if status is true (spawned), don't spawn again | ||
if (prething.spawned !== status) { | ||
prething.spawned = status; | ||
callback(prething); | ||
const preactor = group[i]; | ||
// For example: f status is true (spawned), don't spawn again | ||
if (preactor.spawned !== status) { | ||
preactor.spawned = status; | ||
callback(preactor); | ||
} | ||
@@ -362,0 +362,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { MapsCreatr, IPreThing, IPreThingSettings } from "mapscreatr"; | ||
import { MapsCreatr, PreActorLike, PreActorSettings } from "mapscreatr"; | ||
import { MapScreenr } from "mapscreenr"; | ||
@@ -6,3 +6,3 @@ /** | ||
* | ||
* @param thing The raw command to create a Thing, as either a title | ||
* @param actor The raw command to create an Actor, as either a title | ||
* or a JSON object. | ||
@@ -12,7 +12,7 @@ * @param index Which command this is, as per Array.forEach. | ||
*/ | ||
export declare type ICommandAdder = (thing: string | IPreThingSettings, index: number, commands: any[]) => void; | ||
export declare type CommandAdder = (actor: string | PreActorSettings, index: number, commands: any[]) => void; | ||
/** | ||
* Settings to initialize a new AreaSpawnr. | ||
*/ | ||
export interface IAreaSpawnrSettings { | ||
export interface AreaSpawnrSettings { | ||
/** | ||
@@ -27,9 +27,9 @@ * MapsCreatr used to store and lazily initialize Maps. | ||
/** | ||
* Function for when a PreThing's Thing should be spawned. | ||
* Function for when a PreActor's Actor should be spawned. | ||
*/ | ||
onSpawn?(prething: IPreThing): void; | ||
onSpawn?(preactor: PreActorLike): void; | ||
/** | ||
* Function for when a PreThing's Thing should be un-spawned. | ||
* Function for when a PreActor's Actor should be un-spawned. | ||
*/ | ||
onUnspawn?(prething: IPreThing): void; | ||
onUnspawn?(preactor: PreActorLike): void; | ||
/** | ||
@@ -43,9 +43,9 @@ * Any property names to copy from Areas to the MapScreenr during setLocation. | ||
*/ | ||
stretchAdd?: ICommandAdder; | ||
stretchAdd?: CommandAdder; | ||
/** | ||
* Function to add an Area provides an "afters" command to add PreThings | ||
* Function to add an Area provides an "afters" command to add PreActors | ||
* to the end of an Area. | ||
*/ | ||
afterAdd?: ICommandAdder; | ||
afterAdd?: CommandAdder; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
{ | ||
"author": { | ||
"email": "joshuakgoldberg@outlook.com", | ||
"email": "me@joshuakgoldberg.com", | ||
"name": "Josh Goldberg" | ||
@@ -11,8 +11,8 @@ }, | ||
"dependencies": { | ||
"mapscreatr": "^0.8.0", | ||
"mapscreenr": "^0.8.0" | ||
"mapscreatr": "^0.8.1", | ||
"mapscreenr": "^0.8.1" | ||
}, | ||
"description": "Loads EightBittr maps to spawn and unspawn areas on demand.", | ||
"devDependencies": { | ||
"shenanigans-manager": "^0.8.0" | ||
"shenanigans-manager": "^0.8.1" | ||
}, | ||
@@ -39,3 +39,3 @@ "license": "MIT", | ||
"types": "./lib/index.d.ts", | ||
"version": "0.8.0" | ||
"version": "0.8.1" | ||
} |
@@ -0,0 +0,0 @@ { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
149321
18
Updatedmapscreatr@^0.8.1
Updatedmapscreenr@^0.8.1