-
Notifications
You must be signed in to change notification settings - Fork 153
refactor: migrate modules.js to TypeScript as modules.ts #602
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* eslint-disable import/no-cycle */ | ||
import { simulationArea } from './simulationArea' | ||
|
||
// Define types for Input/Output layout | ||
interface LayoutProperties { | ||
x: number | ||
y: number | ||
} | ||
|
||
interface IOComponent { | ||
layoutProperties: LayoutProperties | ||
} | ||
|
||
interface Scope { | ||
Input: IOComponent[] | ||
Output: IOComponent[] | ||
layout: { | ||
height: number | ||
} | ||
} | ||
|
||
// Assume globalScope exists in your global context | ||
declare const globalScope: Scope | ||
|
||
export function getNextPosition(x = 0, scope: Scope = globalScope): number { | ||
let possibleY = 20 | ||
const done: Record<number, 1> = {} | ||
|
||
for (let i = 0; i < scope.Input.length - 1; i++) { | ||
if (scope.Input[i].layoutProperties.x === x) { | ||
done[scope.Input[i].layoutProperties.y] = 1 | ||
} | ||
} | ||
|
||
for (let i = 0; i < scope.Output.length; i++) { | ||
if (scope.Output[i].layoutProperties.x === x) { | ||
done[scope.Output[i].layoutProperties.y] = 1 | ||
} | ||
} | ||
|
||
while (done[possibleY] || done[possibleY + 10] || done[possibleY - 10]) { | ||
possibleY += 10 | ||
} | ||
|
||
const height = possibleY + 20 | ||
if (height > scope.layout.height) { | ||
const oldHeight = scope.layout.height | ||
scope.layout.height = height | ||
|
||
for (let i = 0; i < scope.Input.length; i++) { | ||
if (scope.Input[i].layoutProperties.y === oldHeight) { | ||
scope.Input[i].layoutProperties.y = scope.layout.height | ||
} | ||
} | ||
|
||
for (let i = 0; i < scope.Output.length; i++) { | ||
if (scope.Output[i].layoutProperties.y === oldHeight) { | ||
scope.Output[i].layoutProperties.y = scope.layout.height | ||
} | ||
} | ||
} | ||
Comment on lines
+45
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Height-adjustment updates miss elements above the old height Only elements exactly at 🤖 Prompt for AI Agents
|
||
|
||
return possibleY | ||
} | ||
|
||
/** | ||
* Global modules registry | ||
*/ | ||
const modules: Record<string, any> = {} | ||
export default modules | ||
|
||
// Define `this` context type | ||
interface ChangeInputSizeContext { | ||
inputSize: number | ||
objectType: string | ||
x: number | ||
y: number | ||
scope: any | ||
direction: number | ||
bitWidth: number | ||
delete: () => void | ||
} | ||
|
||
export function changeInputSize(this: ChangeInputSizeContext, size?: number): any { | ||
if (size === undefined || size < 2 || size > 10) return | ||
if (this.inputSize === size) return | ||
|
||
size = parseInt(String(size), 10) | ||
|
||
const obj = new modules[this.objectType]( | ||
this.x, | ||
this.y, | ||
this.scope, | ||
this.direction, | ||
size, | ||
this.bitWidth | ||
) | ||
Comment on lines
+90
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Runtime crash if module type not registered
🤖 Prompt for AI Agents
|
||
|
||
this.delete() | ||
simulationArea.lastSelected = obj | ||
return obj | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Off-by-one skips the last input element
for (let i = 0; i < scope.Input.length - 1; i++)
never visitsscope.Input[scope.Input.length - 1]
, so the y-coordinate of the last input placed at thisx
can collide with the new object.📝 Committable suggestion
🤖 Prompt for AI Agents