Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: window type changes #73

Draft
wants to merge 11 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
wip breakthru
  • Loading branch information
Thomas O'Neill committed Oct 20, 2023
commit 28671b759ee1edf592e3d30adc4605a07b887e09
30 changes: 15 additions & 15 deletions app/db/layouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type PositionedRow = {
levelType: string
y: number
positionedModules: Array<PositionedModule>
length: number
rowLength: number
}

export type RowLayout = Array<PositionedRow>
Expand All @@ -22,7 +22,7 @@ export type PositionedColumn = {
positionedRows: Array<PositionedRow>
z: number
columnIndex: number
length: number
columnLength: number
}

export type ColumnLayout = Array<PositionedColumn>
Expand All @@ -33,14 +33,14 @@ export const validatePositionedRow = (row: PositionedRow): void => {
(acc, mod) => acc + mod.module.length,
0
)
if (row.length !== totalModulesLength) {
if (row.rowLength !== totalModulesLength) {
console.log(`Row Length Mismatch: `, {
rowLength: row.length,
rowLength: row.rowLength,
totalModulesLength,
positionedModules: row.positionedModules,
})
throw new Error(
`Invalid PositionedRow length. Expected ${totalModulesLength} but got ${row.length}`
`Invalid PositionedRow length. Expected ${totalModulesLength} but got ${row.rowLength}`
)
}

Expand Down Expand Up @@ -109,21 +109,21 @@ export const validatePositionedColumn = (column: PositionedColumn): void => {
})

// Get the length of the first row to compare with the others and with the column's length
const firstRowLength = column.positionedRows[0].length
const firstRowLength = column.positionedRows[0].rowLength

if (column.length !== firstRowLength) {
if (column.columnLength !== firstRowLength) {
console.log("Column Length Mismatch:", {
columnLength: column.length,
columnLength: column.columnLength,
expectedLength: firstRowLength,
})
throw new Error(
`Invalid PositionedColumn length. Expected ${firstRowLength} but got ${column.length}`
`Invalid PositionedColumn length. Expected ${firstRowLength} but got ${column.columnLength}`
)
}

// Ensure all rows have the same length as the first row
for (let i = 1; i < column.positionedRows.length; i++) {
const rowLength = column.positionedRows[i].length
const rowLength = column.positionedRows[i].rowLength
if (rowLength !== firstRowLength) {
console.log(`Row Length Mismatch at Row Index ${i}:`, {
rowLength,
Expand Down Expand Up @@ -175,7 +175,7 @@ export const addModuleToRow = (
}

// 4. Update the length
const updatedLength = row.length + moduleToAdd.length
const updatedLength = row.rowLength + moduleToAdd.length

// 5. Update the gridUnits by extracting gridUnits from moduleToAdd's structuredDna
const additionalGridUnits = moduleToAdd.structuredDna.gridUnits
Expand All @@ -191,7 +191,7 @@ export const addModuleToRow = (
return {
...row,
positionedModules: updatedPositionedModules,
length: updatedLength,
rowLength: updatedLength,
gridUnits: updatedGridUnits,
}
}
Expand Down Expand Up @@ -234,21 +234,21 @@ export const swapModuleInRow = (

// Recalculate z values for subsequent modules if needed
if (lengthDiff !== 0) {
for (let i = targetIndex + 1; i < positionedModulesCopy.length; i++) {
for (let i = targetIndex; i < positionedModulesCopy.length; i++) {
positionedModulesCopy[i].z += lengthDiff / 2
}
}

// Update the length and gridUnits
const updatedLength = row.length + lengthDiff
const updatedLength = row.rowLength + lengthDiff
const gridUnitsDiff =
newModule.structuredDna.gridUnits - oldModule.structuredDna.gridUnits
const updatedGridUnits = row.gridUnits + gridUnitsDiff

return {
...row,
positionedModules: positionedModulesCopy,
length: updatedLength,
rowLength: updatedLength,
gridUnits: updatedGridUnits,
}
}
Expand Down
8 changes: 4 additions & 4 deletions app/design/state/vanilla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const getVanillaColumnLength = (column: PositionedRow[]) =>
pipe(
column,
A.head,
O.map((row) => row.length),
O.map((row) => row.rowLength),
someOrError(`getVanillaColumnLength column of 0 height`)
)

Expand All @@ -85,7 +85,7 @@ export const useGetVanillaModule = (systemId: string) => {

const vanillaModule = pipe(
systemModules,
RA.filter((sysModule) =>
A.filter((sysModule) =>
all(
sectionType
? sysModule.structuredDna.sectionType === sectionType
Expand All @@ -103,13 +103,13 @@ export const useGetVanillaModule = (systemId: string) => {
sysModule.structuredDna.gridType === module.structuredDna.gridType
)
),
RA.sort(
A.sort(
pipe(
S.Ord,
Ord.contramap((m: Module) => m.dna)
)
),
RA.head,
A.head,
O.toNullable
)

Expand Down
5 changes: 4 additions & 1 deletion app/design/state/verticalCutPlanes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export const useVerticalCutPlanes = (
rotation,
} = house

const buildingLength = columnLayout.reduce((acc, v) => acc + v.length, 0)
const buildingLength = columnLayout.reduce(
(acc, v) => acc + v.columnLength,
0
)
const lengthMiddle = buildingLength / 2 + z
const widthMiddle = x

Expand Down
15 changes: 7 additions & 8 deletions app/design/ui-3d/fresh/FreshApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Fragment, useEffect, useRef } from "react"
import { useKey } from "react-use"
import { Group, Scene } from "three"
import { proxy, ref, useSnapshot } from "valtio"
import { A, O, pipeLogWith } from "../../../utils/functions"
import { A, O, pipeLog, pipeLogWith } from "../../../utils/functions"
import { useSubscribe } from "../../../utils/hooks"
import { floor, random } from "../../../utils/math"
import { useExportersWorker } from "../../../workers/exporters/hook"
Expand Down Expand Up @@ -99,7 +99,6 @@ const FreshApp = () => {
houseTransformsGroup.children,
A.filter(isWindowTypeAltLayoutGroup)
).forEach((lg) => {
console.log(`removing ${lg.uuid} FULLY`)
lg.removeFromParent()
})
)
Expand Down Expand Up @@ -183,22 +182,22 @@ const FreshApp = () => {
pipe(
maybeHouse,
O.map((house) => {
console.log("get first non-active layout")
const maybeNextLayout = pipe(
house.children,
A.filter(isHouseLayoutGroup),
pipeLogWith((xs) => xs.map((x) => x.userData.use)),
A.filter((x) => x.userData.use !== HouseLayoutGroupUse.Enum.ACTIVE),
(groups) => {
const i = floor(random() * groups.length)
return pipe(groups, A.lookup(i))
}
A.head
// (groups) => {
// const i = floor(random() * groups.length)
// return pipe(groups, A.lookup(i))
// }
)

pipe(
maybeNextLayout,
pipeLog,
O.map((nextLayout) => {
console.log(`set it ${nextLayout.uuid}`)
house.userData.setActiveLayoutGroup(nextLayout)
invalidate()
})
Expand Down
2 changes: 1 addition & 1 deletion app/design/ui-3d/fresh/scene/columnGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const createColumnGroup =
const columnGroupUserData: ColumnGroupUserData = {
type: UserDataTypeEnum.Enum.ColumnGroup,
columnIndex,
length: positionedRows[0].length,
length: positionedRows[0].rowLength,
startColumn,
endColumn,
}
Expand Down
1 change: 0 additions & 1 deletion app/design/ui-3d/fresh/scene/houseTransformsGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ import {
isXStretchHandleGroup,
isZStretchHandleGroup,
} from "./userData"
import { stripForDebug } from "../../../../workers/layouts/worker"

export const BIG_CLIP_NUMBER = 999

Expand Down
4 changes: 2 additions & 2 deletions app/workers/layouts/vanilla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const postVanillaColumn = async (arbitraryColumn: PositionedColumn) => {
z: vanillaModule.length / 2,
},
],
length: vanillaModule.length,
rowLength: vanillaModule.length,
y,
levelIndex,
levelType,
Expand Down Expand Up @@ -217,7 +217,7 @@ export const postVanillaColumn = async (arbitraryColumn: PositionedColumn) => {
sectionType,
vanillaColumn: {
positionedRows: gridGroups,
length,
columnLength: length,
},
})
})
Expand Down
Loading