✨ Switched Pattern.inScope() to Pattern.needs()
This commit is contained in:
parent
f3092a6468
commit
0d0784bb95
3 changed files with 22 additions and 22 deletions
|
@ -248,7 +248,7 @@ Pattern.prototype.pack = function() {
|
|||
let part = this.parts[key];
|
||||
// Avoid multiple render calls to cause stacking of transforms
|
||||
part.attributes.set("transform", "");
|
||||
if (part.render && this.inScope(key)) {
|
||||
if (part.render && this.needs(key)) {
|
||||
part.stack();
|
||||
bins.push({
|
||||
id: key,
|
||||
|
@ -269,18 +269,18 @@ Pattern.prototype.pack = function() {
|
|||
return this;
|
||||
};
|
||||
|
||||
/** Determines whether a part is in scope
|
||||
* Scope depends on the 'only' setting people can pass
|
||||
* with the name of a part, or an array of parts
|
||||
* The absence of only means all parts
|
||||
/** Determines whether a part is needed
|
||||
* This depends on the 'only' setting. People can pass
|
||||
* the name of a part, or an array of parts
|
||||
* The absence of only means all parts are needed.
|
||||
*
|
||||
* If partName is an array of names, any name being in
|
||||
* scope will cause this to return true
|
||||
* If partName is an array of names, any name needed
|
||||
* will cause this to return true
|
||||
*/
|
||||
Pattern.prototype.inScope = function(partName) {
|
||||
Pattern.prototype.needs = function(partName) {
|
||||
if (typeof partName !== "string") {
|
||||
for (let part of partName) {
|
||||
if (this.inScope(part)) return true;
|
||||
if (this.needs(part)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ Svg.prototype.render = function(pattern) {
|
|||
this.svg += this.openGroup("draftContainer");
|
||||
for (let partId in pattern.parts) {
|
||||
let part = pattern.parts[partId];
|
||||
if (part.render && pattern.inScope(partId)) {
|
||||
if (part.render && pattern.needs(partId)) {
|
||||
this.svg += this.openGroup(this.getUid(), part.attributes);
|
||||
this.svg += this.renderPart(part);
|
||||
this.svg += this.closeGroup();
|
||||
|
|
|
@ -139,26 +139,26 @@ it("Should register a hook from a plugin", () => {
|
|||
expect(count).to.equal(1);
|
||||
});
|
||||
|
||||
it("Should check whether a part is in scope", () => {
|
||||
it("Should check whether a part is needed", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.settings.only = "test";
|
||||
expect(pattern.inScope("test")).to.equal(true);
|
||||
expect(pattern.inScope("mist")).to.equal(false);
|
||||
expect(pattern.needs("test")).to.equal(true);
|
||||
expect(pattern.needs("mist")).to.equal(false);
|
||||
});
|
||||
|
||||
it("Should check whether an array of parts is in scope", () => {
|
||||
it("Should check whether an array of parts is needed", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.settings.only = "test";
|
||||
expect(pattern.inScope(["foo", "bar", "test"])).to.equal(true);
|
||||
expect(pattern.inScope(["foo", "bar", "mist"])).to.equal(false);
|
||||
expect(pattern.needs(["foo", "bar", "test"])).to.equal(true);
|
||||
expect(pattern.needs(["foo", "bar", "mist"])).to.equal(false);
|
||||
});
|
||||
|
||||
it("Should check whether a parts is in a scope array", () => {
|
||||
it("Should check whether a parts is needed with array", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.settings.only = ["test", "foo", "bar"];
|
||||
expect(pattern.inScope("foo")).to.equal(true);
|
||||
expect(pattern.inScope(["bar"])).to.equal(true);
|
||||
expect(pattern.inScope(["mest", "foo"])).to.equal(true);
|
||||
expect(pattern.inScope(["mist", "hugs"])).to.equal(false);
|
||||
expect(pattern.inScope("jugs")).to.equal(false);
|
||||
expect(pattern.needs("foo")).to.equal(true);
|
||||
expect(pattern.needs(["bar"])).to.equal(true);
|
||||
expect(pattern.needs(["mest", "foo"])).to.equal(true);
|
||||
expect(pattern.needs(["mist", "hugs"])).to.equal(false);
|
||||
expect(pattern.needs("jugs")).to.equal(false);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue