Class Diagram - treytomes/redstone_sim GitHub Wiki
Updated Redstone Wire and Crossover Design
I'll update the RedstoneWire component and add a new Crossover component to meet these requirements:
βββββββββββββββββββββββββββββββββββββ
β Β«interfaceΒ» β
β Component β // Base component interface
βββββββββββββββββββββββββββββββββββββ€
β + powerLevel: number β // Current power level (0-15)
β + orientation: Direction β // Component facing direction
β + connectedSides: Direction[] β // Sides that connect to other components
βββββββββββββββββββββββββββββββββββββ€
β + updateState(neighbors): void β // Update component state based on neighbors
β + getPowerOutput(side): number β // Get power level on specific side
β + canConnect(side): boolean β // Check if component can connect on side
β + onNeighborChange(side): void β // React to neighbor state change
βββββββββββββββββββββββββββββββββββββ
β²
β implements
β
βββββββββββββ΄ββββββββββββββΌββββββββββββββΌββββββββββββββ¬ββββββββββββββ
β β β β β β
βΌ βΌ βΌ βΌ βΌ βΌ
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
β RedstoneWire β β PowerSource β β RedstoneTorch β β Repeater β β Crossover β
βββββββββββββββββ€ βββββββββββββββββ€ βββββββββββββββββ€ βββββββββββββββββ€ βββββββββββββββββ€
β - connections β β - isActive β β - attachment β β - delay β β - axisALevel β // Power level for NS axis
β - enabledDirs β β - pulseTime β β - burnout β β - locked β β - axisBLevel β // Power level for EW axis
βββββββββββββββββ€ βββββββββββββββββ€ βββββββββββββββββ€ βββββββββββββββββ€ βββββββββββββββββ€
β + toggleDir() β β + toggle() β β + methods... β β + setDelay() β β + methods... β
β + methods... β β + methods... β βββββββββββββββββ β + methods... β βββββββββββββββββ
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
Updated RedstoneWire Class Details
βββββββββββββββββββββββββββββββββββββββββββββββ
β RedstoneWire β
βββββββββββββββββββββββββββββββββββββββββββββββ€
β - powerLevel: number β // Current power level (0-15)
β - enabledDirections: Map<Direction, boolean> β // Which directions are enabled
β - connections: Map<Direction, Component> β // Connected components by direction
βββββββββββββββββββββββββββββββββββββββββββββββ€
β + toggleDirection(dir: Direction): void β // Enable/disable connection in direction
β + isDirectionEnabled(dir: Direction): bool β // Check if direction is enabled
β + updateState(neighbors): void β // Update based on highest neighbor power
β + getPowerOutput(side): number β // Return power only if side is enabled
β + canConnect(side): boolean β // Check if side is enabled for connection
β + getVisualState(): WireState β // Get visual representation data
βββββββββββββββββββββββββββββββββββββββββββββββ
New Crossover Component Details
βββββββββββββββββββββββββββββββββββββββββββββββ
β Crossover β // Wire crossover component
βββββββββββββββββββββββββββββββββββββββββββββββ€
β - axisAPowerLevel: number β // Power level for North-South axis (0-15)
β - axisBPowerLevel: number β // Power level for East-West axis (0-15)
β - axisAConnections: Map<Direction, Component>β // NS axis connected components
β - axisBConnections: Map<Direction, Component>β // EW axis connected components
βββββββββββββββββββββββββββββββββββββββββββββββ€
β + updateState(neighbors): void β // Update both axes independently
β + getPowerOutput(side): number β // Return power from appropriate axis
β + canConnect(side): boolean β // Always true - connects on all sides
β + getAxisForDirection(dir: Direction): Axis β // Maps direction to corresponding axis
β + getVisualState(): CrossoverState β // Get visual representation data
βββββββββββββββββββββββββββββββββββββββββββββββ
Enumerations and Supporting Types
βββββββββββββββββββββββββββββββ
β Β«enumerationΒ» β
β Direction β // Cardinal directions
βββββββββββββββββββββββββββββββ€
β NORTH β
β EAST β
β SOUTH β
β WEST β
βββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββ
β Β«enumerationΒ» β
β Axis β // Axis identifier for crossover
βββββββββββββββββββββββββββββββ€
β NS β // North-South axis
β EW β // East-West axis
βββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββ
β WireState β // Visual representation data
βββββββββββββββββββββββββββββββ€
β - powerLevel: number β
β - connections: Direction[] β
βββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββ
β CrossoverState β // Visual representation data
βββββββββββββββββββββββββββββββ€
β - axisAPower: number β
β - axisBPower: number β
βββββββββββββββββββββββββββββββ
Implementation Notes:
-
RedstoneWire Modifications:
- Added
enabledDirectionsmap to track which directions are enabled for connections - Added
toggleDirection()method to enable/disable connections in specific directions - Modified
canConnect()to check if the direction is enabled - Modified
getPowerOutput()to only output power in enabled directions
- Added
-
New Crossover Component:
- Maintains two separate power levels for NS and EW axes
- Each axis operates independently - signals don't mix between axes
- North and South connections are on one axis, East and West on the other
- Updates each axis based on the highest power level from connected components on that axis
- Visual representation shows both power levels for rendering purposes
-
Connection Logic:
- RedstoneWire only connects to adjacent components in enabled directions
- Crossover connects to components in all four directions but maintains signal separation
- Both components need to implement proper neighbor notification to ensure signals propagate correctly
-
User Interface Considerations:
- UI needs controls to toggle individual wire connections
- Visual representation should clearly show which connections are enabled
- Crossover should visually distinguish between the two crossing signals
These changes allow for more precise control of redstone wiring patterns and enable complex circuit designs that require signal crossing without interference.