-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43d668b
commit d3810fd
Showing
7 changed files
with
84 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,41 @@ | ||
// Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. | ||
|
||
import { GeometryNode, IDocument, Property, VisualNode } from "chili-core"; | ||
import { IConverter, IDocument, Logger, Property, Texture } from "chili-core"; | ||
import { CheckProperty } from "./check"; | ||
import { ColorProperty } from "./colorProperty"; | ||
import { InputProperty } from "./input"; | ||
import { TextureProperty } from "./material/textureEditor"; | ||
import { MaterialProperty } from "./materialProperty"; | ||
|
||
export function appendProperty(container: HTMLElement, document: IDocument, objs: any[], prop?: Property) { | ||
if (prop === undefined || objs.length === 0) return; | ||
if (!(prop.name in objs[0])) { | ||
alert(`Property ${prop.name} not found in ${Object.getPrototypeOf(objs[0]).constructor.name}`); | ||
return; | ||
export function findPropertyControl( | ||
document: IDocument, | ||
objs: any[], | ||
prop: Property, | ||
converter?: IConverter, | ||
) { | ||
if (prop === undefined || objs.length === 0) return ""; | ||
|
||
if (prop.type === "color") { | ||
return new ColorProperty(document, objs, prop); | ||
} | ||
|
||
const propValue = (objs[0] as unknown as any)[prop.name]; | ||
const type = typeof propValue; | ||
if (prop.type === "materialId") { | ||
return new MaterialProperty(document, objs, prop); | ||
} | ||
|
||
if (prop.type === "color") { | ||
container.append(new ColorProperty(document, objs, prop)); | ||
} else if (prop.type === "materialId") { | ||
container.append( | ||
new MaterialProperty( | ||
document, | ||
objs.filter((x) => "materialId" in x), | ||
prop, | ||
), | ||
); | ||
} else if (type === "object" || type === "string" || type === "number") { | ||
container.append(new InputProperty(document, objs, prop)); | ||
} else if (type === "boolean") { | ||
container.append(new CheckProperty(objs, prop)); | ||
const value = objs[0][prop.name]; | ||
if (value instanceof Texture) { | ||
return new TextureProperty(document, prop.display, value); | ||
} | ||
|
||
if (["object", "string", "number"].includes(typeof value)) { | ||
return new InputProperty(document, objs, prop, converter); | ||
} | ||
|
||
if (typeof value === "boolean") { | ||
return new CheckProperty(objs, prop); | ||
} | ||
|
||
Logger.warn(`Property ${prop.name} not found in ${Object.getPrototypeOf(objs[0]).constructor.name}`); | ||
return ""; | ||
} |