Skip to content

Commit

Permalink
add generated components
Browse files Browse the repository at this point in the history
  • Loading branch information
kfarr committed Feb 4, 2025
1 parent 5e09443 commit 17f990c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/components/street-generated-clones.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ AFRAME.registerComponent('street-generated-clones', {
},

update: function (oldData) {
// if length is not set, then derive length from the segment
if (!this.data.length) {
this.data.length = this.el.getAttribute('street-segment').length;
}

// If mode is random or randomFacing and seed is 0, generate a random seed and return,
// the update will be called again because of the setAttribute.
if (this.data.mode === 'random' || this.data.randomFacing) {
Expand Down
5 changes: 5 additions & 0 deletions src/components/street-generated-pedestrians.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ AFRAME.registerComponent('street-generated-pedestrians', {
update: function (oldData) {
const data = this.data;

// if length is not set, then derive length from the segment
if (!data.length) {
data.length = this.el.getAttribute('street-segment').length;
}

// Handle seed initialization
if (this.data.seed === 0) {
const newSeed = Math.floor(Math.random() * 1000000) + 1;
Expand Down
5 changes: 5 additions & 0 deletions src/components/street-generated-rail.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ AFRAME.registerComponent('street-generated-rail', {
this.createdEntities.length = 0; // Clear the array
},
update: function (oldData) {
// if length is not set, then derive length from the segment
if (!this.data.length) {
this.data.length = this.el.getAttribute('street-segment').length;
}

// Clean up old entities
this.remove();

Expand Down
7 changes: 6 additions & 1 deletion src/components/street-generated-stencil.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ AFRAME.registerComponent('street-generated-stencil', {
},
spacing: {
// spacing in meters between clones
default: 15,
default: 10,
type: 'number'
},
positionX: {
Expand Down Expand Up @@ -119,6 +119,11 @@ AFRAME.registerComponent('street-generated-stencil', {
update: function (oldData) {
const data = this.data;

// if length is not set, then derive length from the segment
if (!data.length) {
data.length = this.el.getAttribute('street-segment').length;
}

// Clean up old entities
this.remove();

Expand Down
2 changes: 2 additions & 0 deletions src/editor/components/components/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import PropTypes from 'prop-types';
import React from 'react';
import capitalize from 'lodash-es/capitalize';
import classnames from 'classnames';
import AddComponent from './AddComponent';
import {
ArrowRightIcon,
Object24Icon,
Expand Down Expand Up @@ -244,6 +245,7 @@ export default class Sidebar extends React.Component {
{entity.getAttribute('street-segment') && (
<>
<StreetSegmentSidebar entity={entity} />
<AddComponent entity={entity} />
<div className="advancedComponentsContainer">
<AdvancedComponents entity={entity} />
</div>
Expand Down
10 changes: 8 additions & 2 deletions src/editor/components/components/StreetSegmentComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,15 @@ export default class Component extends React.Component {
} else if (componentName.startsWith('street-generated-stencil')) {
return (
<>
<ModelsArrayWidget
entity={this.props.entity}
<PropertyRow
key="modelsArray"
name="modelsArray"
label="Stencils"
schema={schema['modelsArray']}
data={componentData.data['modelsArray']}
componentname={componentName}
entity={this.props.entity}
isSingle={false}
/>
<PropertyRow
key="spacing"
Expand Down

0 comments on commit 17f990c

Please sign in to comment.