Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into kurt-refactor-client-side-…
Browse files Browse the repository at this point in the history
…scene
  • Loading branch information
Irev-Dev committed Sep 10, 2024
2 parents a7c2577 + 6776a35 commit a630538
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- run: yarn xstate:typegen
- run: yarn tsc
- name: Lint
run: yarn eslint --max-warnings 0 src e2e
run: yarn eslint --max-warnings 0 src e2e packages/codemirror-lsp-client


check-typos:
Expand Down
3 changes: 0 additions & 3 deletions docs/kcl/KNOWN-ISSUES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,3 @@ once fixed in engine will just start working here with no language changes.
chamfer cases work currently.

Sketching on the chamfered face does not currently work.

- **Shell**: Shell sometimes does not work when arcs or fillets are involved.
We are tracking the engine side bug on this.
66 changes: 66 additions & 0 deletions e2e/playwright/testing-settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,4 +552,70 @@ test.describe('Testing settings', () => {
await changeUnitOfMeasureInGizmo('m', 'Meters')
})
})

test('Changing theme in sketch mode', async ({ page }) => {
const u = await getUtils(page)
await page.addInitScript(() => {
localStorage.setItem(
'persistCode',
`const sketch001 = startSketchOn('XZ')
|> startProfileAt([0, 0], %)
|> line([5, 0], %)
|> line([0, 5], %)
|> line([-5, 0], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(5, sketch001)
`
)
})
await page.setViewportSize({ width: 1200, height: 500 })

// Selectors and constants
const editSketchButton = page.getByRole('button', { name: 'Edit Sketch' })
const lineToolButton = page.getByTestId('line')
const segmentOverlays = page.getByTestId('segment-overlay')
const sketchOriginLocation = { x: 600, y: 250 }
const darkThemeSegmentColor: [number, number, number] = [215, 215, 215]
const lightThemeSegmentColor: [number, number, number] = [90, 90, 90]

await test.step(`Get into sketch mode`, async () => {
await u.waitForAuthSkipAppStart()
await page.mouse.click(700, 200)
await expect(editSketchButton).toBeVisible()
await editSketchButton.click()

// We use the line tool as a proxy for sketch mode
await expect(lineToolButton).toBeVisible()
await expect(segmentOverlays).toHaveCount(4)
// but we allow more time to pass for animating to the sketch
await page.waitForTimeout(1000)
})

await test.step(`Check the sketch line color before`, async () => {
await expect
.poll(() =>
u.getGreatestPixDiff(sketchOriginLocation, darkThemeSegmentColor)
)
.toBeLessThan(15)
})

await test.step(`Change theme to light using command palette`, async () => {
await page.keyboard.press('ControlOrMeta+K')
await page.getByRole('option', { name: 'theme' }).click()
await page.getByRole('option', { name: 'light' }).click()
await expect(page.getByText('theme to "light"')).toBeVisible()

// Make sure we haven't left sketch mode
await expect(lineToolButton).toBeVisible()
})

await test.step(`Check the sketch line color after`, async () => {
await expect
.poll(() =>
u.getGreatestPixDiff(sketchOriginLocation, lightThemeSegmentColor)
)
.toBeLessThan(15)
})
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"build:wasm": "yarn wasm-prep && cd src/wasm-lib && wasm-pack build --release --target web --out-dir pkg && cargo test -p kcl-lib export_bindings && cd ../.. && yarn isomorphic-copy-wasm && yarn fmt",
"remove-importmeta": "sed -i 's/import.meta.url/window.location.origin/g' \"./src/wasm-lib/pkg/wasm_lib.js\"; sed -i '' 's/import.meta.url/window.location.origin/g' \"./src/wasm-lib/pkg/wasm_lib.js\" || echo \"sed for both mac and linux\"",
"wasm-prep": "rimraf src/wasm-lib/pkg && mkdirp src/wasm-lib/pkg && rimraf src/wasm-lib/kcl/bindings",
"lint": "eslint --fix src e2e",
"lint": "eslint --fix src e2e packages/codemirror-lsp-client",
"bump-jsons": "echo \"$(jq --arg v \"$VERSION\" '.version=$v' package.json --indent 2)\" > package.json",
"postinstall": "yarn xstate:typegen && ./node_modules/.bin/electron-rebuild",
"xstate:typegen": "yarn xstate typegen \"src/**/*.ts?(x)\"",
Expand Down
4 changes: 3 additions & 1 deletion packages/codemirror-lsp-client/src/plugin/lsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,9 @@ export class LanguageServerPlugin implements PluginValue {
processDiagnostics(params: PublishDiagnosticsParams) {
if (params.uri !== this.getDocUri()) return

const diagnostics = params.diagnostics
// Commented to avoid the lint. See TODO below.
// const diagnostics =
params.diagnostics
.map(({ range, message, severity }) => ({
from: posToOffset(this.view.state.doc, range.start)!,
to: posToOffset(this.view.state.doc, range.end)!,
Expand Down
4 changes: 2 additions & 2 deletions src/clientSideScene/CameraControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ export class CameraControls {
const oldFov = this.camera.fov

const viewHeightFactor = (fov: number) => {
/* *
/* *
/|
/ |
/ |
Expand Down Expand Up @@ -1189,7 +1189,7 @@ function convertThreeCamValuesToEngineCam({
const lookAt = buildLookAt(64 / zoom, target, position)
return {
center: new Vector3(lookAt.center.x, lookAt.center.y, lookAt.center.z),
up: new Vector3(0, 0, 1),
up: new Vector3(upVector.x, upVector.y, upVector.z),
vantage: new Vector3(lookAt.eye.x, lookAt.eye.y, lookAt.eye.z),
}
}
Expand Down
21 changes: 20 additions & 1 deletion src/clientSideScene/sceneEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ import {
getRectangleCallExpressions,
updateRectangleSketch,
} from 'lib/rectangleTool'
import { getThemeColorForThreeJs } from 'lib/theme'
import { getThemeColorForThreeJs, Themes } from 'lib/theme'
import { err, reportRejection, trap } from 'lib/trap'
import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer'
import { Point3d } from 'wasm-lib/kcl/bindings/Point3d'
Expand Down Expand Up @@ -1493,6 +1493,25 @@ export class SceneEntities {
to,
})
}
/**
* Update the base color of each of the THREEjs meshes
* that represent each of the sketch segments, to get the
* latest value from `sceneInfra._theme`
*/
updateSegmentBaseColor(newColor: Themes.Light | Themes.Dark) {
const newColorThreeJs = getThemeColorForThreeJs(newColor)
Object.values(this.activeSegments).forEach((group) => {
group.userData.baseColor = newColorThreeJs
group.traverse((child) => {
if (
child instanceof Mesh &&
child.material instanceof MeshBasicMaterial
) {
child.material.color.set(newColorThreeJs)
}
})
})
}
removeSketchGrid() {
if (this.axisGroup) this.scene.remove(this.axisGroup)
}
Expand Down
8 changes: 7 additions & 1 deletion src/components/SettingsAuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import decamelize from 'decamelize'
import { Actor, AnyStateMachine, ContextFrom, Prop, StateFrom } from 'xstate'
import { isDesktop } from 'lib/isDesktop'
import { authCommandBarConfig } from 'lib/commandBarConfigs/authCommandConfig'
import { kclManager, sceneInfra, engineCommandManager } from 'lib/singletons'
import {
kclManager,
sceneInfra,
engineCommandManager,
sceneEntitiesManager,
} from 'lib/singletons'
import { uuidv4 } from 'lib/utils'
import { IndexLoaderData } from 'lib/types'
import { settings } from 'lib/settings/initialSettings'
Expand Down Expand Up @@ -137,6 +142,7 @@ export const SettingsAuthProviderBase = ({
setClientTheme: ({ context }) => {
const opposingTheme = getOppositeTheme(context.app.theme.current)
sceneInfra.theme = opposingTheme
sceneEntitiesManager.updateSegmentBaseColor(opposingTheme)
},
setEngineEdges: ({ context }) => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
Expand Down
67 changes: 67 additions & 0 deletions src/lib/settings/settingsUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { DeepPartial } from 'lib/types'
import { Configuration } from 'wasm-lib/kcl/bindings/Configuration'
import {
configurationToSettingsPayload,
projectConfigurationToSettingsPayload,
setSettingsAtLevel,
} from './settingsUtils'
import { createSettings } from './initialSettings'

describe(`testing settings initialization`, () => {
it(`sets settings at the 'user' level`, () => {
let settings = createSettings()
const appConfiguration: DeepPartial<Configuration> = {
settings: {
app: {
appearance: {
theme: 'dark',
color: 190,
},
},
},
}

const appSettingsPayload = configurationToSettingsPayload(appConfiguration)

setSettingsAtLevel(settings, 'user', appSettingsPayload)

expect(settings.app.theme.current).toBe('dark')
expect(settings.app.themeColor.current).toBe('190')
})

it(`doesn't read theme from project settings`, () => {
let settings = createSettings()
const appConfiguration: DeepPartial<Configuration> = {
settings: {
app: {
appearance: {
theme: 'dark',
color: 190,
},
},
},
}
const projectConfiguration: DeepPartial<Configuration> = {
settings: {
app: {
appearance: {
theme: 'light',
color: 200,
},
},
},
}

const appSettingsPayload = configurationToSettingsPayload(appConfiguration)
const projectSettingsPayload =
projectConfigurationToSettingsPayload(projectConfiguration)

setSettingsAtLevel(settings, 'user', appSettingsPayload)
setSettingsAtLevel(settings, 'project', projectSettingsPayload)

// The 'project'-level for `theme` setting should be ignored completely
expect(settings.app.theme.current).toBe('dark')
// But the 'project'-level for `themeColor` setting should be applied
expect(settings.app.themeColor.current).toBe('200')
})
})
2 changes: 1 addition & 1 deletion src/lib/settings/settingsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function projectConfigurationToSettingsPayload(
): DeepPartial<SaveSettingsPayload> {
return {
app: {
theme: appThemeToTheme(configuration?.settings?.app?.appearance?.theme),
// do not read in `theme`, because it is blocked on the project level
themeColor: configuration?.settings?.app?.appearance?.color
? configuration?.settings?.app?.appearance?.color.toString()
: undefined,
Expand Down
5 changes: 1 addition & 4 deletions src/machines/modelingMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,7 @@ export const modelingMachine = setup({
'next is rectangle': ({ context: { sketchDetails, currentTool } }) =>
currentTool === 'rectangle' && canRectangleTool({ sketchDetails }),
'next is line': ({ context }) => context.currentTool === 'line',
'next is none': ({ context }) => {
console.log('is next none?', context)
return context.currentTool === 'none'
},
'next is none': ({ context }) => context.currentTool === 'none',
},
// end guards
actions: {
Expand Down

0 comments on commit a630538

Please sign in to comment.