PhobiaCide / ship-fitting

https://phobiacide.github.io/ship-fitting/
0 stars 0 forks source link

Place Module Slots #1

Open PhobiaCide opened 7 months ago

PhobiaCide commented 7 months ago

Align and space all the module slots perfectly around the fitting simulator.

Assuming 0 degrees is up:

codeautopilot[bot] commented 7 months ago

Potential solution

The task requires positioning module slots around a fitting simulator at specific degree ranges. To achieve this, we will use CSS to position each slot type (high, mid, low, rigs, and sub-systems) according to the specified degree ranges. The reasoning behind this approach is that CSS provides the necessary tools to position and rotate elements with precision using properties like position, top, left, and transform.

How to implement

  1. Define a common class for all slots to set their position relative to the fitting simulator's center.
  2. Calculate the positions for each slot type using trigonometry based on their degree ranges.
  3. Use CSS transforms to rotate each slot to the correct angle.
  4. Ensure even spacing within the degree ranges for each slot type.
  5. Make the layout responsive and test across different browsers and devices.

Here's an example of how to implement the CSS for high slots:

.slot-container {
  position: relative;
  width: 512px; /* Example width, should match the fitting simulator size */
  height: 512px; /* Example height, should match the fitting simulator size */
}

.slot {
  position: absolute;
  width: 64px; /* Slot image width */
  height: 64px; /* Slot image height */
  /* Center the slot image */
  transform: translate(-50%, -50%);
}

.high-slot {
  /* Calculate the correct top and left values for each slot */
  /* Example for one high slot at 0 degrees (up) */
  top: 0%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(0deg);
}

.mid-slot {
  /* Similar calculations for mid slots */
}

.low-slot {
  /* Similar calculations for low slots */
}

.rig-slot {
  /* Similar calculations for rig slots */
}

/* Repeat for each individual slot, adjusting the rotation and position */

For each slot, you will need to adjust the top and left properties based on the trigonometric calculations for their respective positions. The transform property should include both the translation to center the slot image and the rotation for the correct angle.

Ensure that the .slot class has the correct scaling and rotation to appear upright and consistent in size regardless of the slot's rotation. This may involve additional CSS rules to counteract the rotation applied for positioning.

The actual implementation will require specific calculations for the top and left properties based on the fitting simulator's dimensions and the desired distance of the slots from the center. These calculations will depend on the layout and design specifics of the fitting simulator.

Click here to create a Pull Request with the proposed solution

Files used for this task:

Changes on src/images/high.svg To address the issue described in the ticket, we need to ensure that the high slot SVG (`high.svg`) is properly centered and has the correct pivot point for rotation. The SVG provided in the source code appears to be a simple image wrapped in an SVG container, which means that the centering and rotation pivot point are likely handled by the CSS when the image is placed in the layout. Since the task for this file is to verify the SVG, we should check the following: 1. **Centering**: The SVG should be designed such that the visual center of the image corresponds to the center of the SVG canvas (32x32 in this case, given the 64x64 dimensions). This ensures that when the CSS applies rotation, it will rotate around the center of the image. 2. **Pivot Point**: The pivot point for rotation in SVG is by default the center of the SVG canvas. If the image is not centered in the SVG canvas, it will not rotate around its visual center. For this file, the practical steps to verify and adjust (if necessary) are: 1. Open the `high.svg` file in an SVG editor (like Adobe Illustrator, Inkscape, or an online SVG editor). 2. Check if the image is centered on the canvas. The center of the image should be at coordinates (32, 32) since the canvas is 64x64. 3. If the image is not centered, adjust it so that it is. This may involve moving the image within the SVG canvas. 4. Save the changes and replace the existing `high.svg` file with the updated one. If the image is already centered, no changes are required for this file. The actual positioning and rotation will be handled by the CSS, which is not within the scope of this file's task.
Changes on src/images/low.svg To address the issue described in the ticket, we need to ensure that the low slot SVG (`low.svg`) is properly centered and has the correct pivot point for rotation. The SVG provided in the source code seems to be a simple image wrapped in an SVG container. The pivot point for rotation is typically at the center of the image, which in this case should be at coordinates (32, 32) given the width and height of 64. However, since the task is to adjust the CSS rules to position the slots, the actual centering and rotation pivot adjustments will be handled in the CSS file (`style.css`). The SVG file itself does not need to be modified unless the image is not symmetrical or there is an issue with how it is being displayed. For this file (`low.svg`), there is no action required unless testing reveals that the image is not symmetrical or does not appear correctly when rotated. The actual positioning and rotation will be handled by the CSS, which is where the adjustments to meet the ticket requirements will be made.
Changes on src/images/mid.svg To address the issue described in the ticket, we need to ensure that the mid slot SVG (`mid.svg`) is properly centered and has the correct pivot point for rotation. The SVG provided seems to be a simple image embedded within an SVG container. The pivot point for rotation is typically at the center of the image, which in this case should be at coordinates (32, 32) given the width and height of 64. The SVG itself does not contain any explicit instructions for rotation or centering, as these are typically handled by CSS or JavaScript in the context of the web page where the SVG is used. Therefore, the task for this file is to ensure that the image is designed to be centered around its middle point, which appears to be the case given the symmetrical dimensions. If adjustments are needed, they would likely involve editing the image itself to ensure that the visual center of the icon aligns with the SVG's coordinate center (32, 32). However, without further context or a visual representation of the issue, it's difficult to provide a concrete solution for adjustments within the SVG file alone. Since the task specifies that the CSS rules need to be adjusted to position the slots, the actual positioning and rotation will be handled in the `style.css` file, not within the SVG file. The SVG file simply needs to be correctly designed so that when CSS applies transformations to it, it rotates around its center as expected. In summary, there is no action required for this file unless there is feedback that the image is not visually centered. The main work will be done in the CSS file to position and rotate the SVG appropriately on the web page.
Changes on src/images/rig.svg To confirm that the rig slot SVG is centered and has the appropriate pivot point for rotation, you would typically open the SVG file in a vector graphics editor like Adobe Illustrator or Inkscape. However, since we are dealing with the source code of the SVG file, we can analyze the SVG elements and attributes to ensure proper centering and rotation. The SVG provided has a `viewBox` attribute set to "0 0 64 64", which means the coordinate system of the SVG canvas is 64 units wide and 64 units high. The `image` element inside the SVG has both `width` and `height` attributes set to "64", which matches the `viewBox`, suggesting that the image should fill the entire SVG canvas. For the image to be centered, it should start at the top-left corner of the SVG canvas, which it does, since there are no `x` or `y` attributes on the `image` element to offset its position. This means the image is centered within the SVG canvas. The pivot point for rotation in SVG is by default the center of the `viewBox`, unless otherwise specified using the `transform-origin` property in CSS or the `transform` attribute in SVG. Since there is no `transform` attribute or CSS style applied to the `image` element that would change the pivot point, the pivot point should be at the center of the image, which is what we want. In conclusion, the rig slot SVG appears to be centered correctly, and the pivot point for rotation should be at the center of the image by default. No adjustments seem necessary based on the provided SVG code. However, if you need to adjust the pivot point or ensure compatibility across all browsers, you may need to add additional CSS rules or SVG attributes to explicitly set the `transform-origin`.
Changes on src/css/style.css To address the issue described in the ticket, we need to adjust the CSS rules for the positioning of the module slots around the fitting simulator. The goal is to align and space all the module slots perfectly within the specified degree ranges. Here's a practical proposal to solve the task for the `style.css` file: 1. **Define the center point**: Ensure that there is a defined center point for the fitting simulator. This will be the pivot point around which all slots will be positioned. 2. **Calculate positions**: For each slot type (high, mid, low, rigs, and sub-systems), calculate the exact positions using trigonometry based on the degree ranges provided. You will need to use the `top` and `left` properties to position each slot absolutely within its parent container. 3. **Use CSS transforms**: Utilize the `transform` property to rotate each slot to the correct angle. The `rotate()` function will be used here. 4. **Ensure even spacing**: Adjust the positions of the slots to ensure they are evenly spaced within their respective degree ranges. 5. **Responsive adjustments**: Make sure that the positions and sizes of the slots are responsive and look good on different screen sizes. This may involve using media queries and relative units like percentages or viewport units. 6. **Test thoroughly**: After making the adjustments, test the layout on different browsers and devices to ensure that the slots are positioned and spaced correctly. Here's an example of how you might adjust the CSS for the high slots: ```css .high-slots .high-slot { position: absolute; /* Calculate the correct top and left values for each slot */ } /* Example for one high slot */ .high-slots .high-slot-1 { /* Assuming the center of the fitting simulator is at (256px, 256px) */ top: calc(50% - 64px); /* Adjust this value based on trigonometric calculations */ left: calc(50% - 64px); /* Adjust this value based on trigonometric calculations */ transform: rotate(-36deg); /* Adjust the rotation angle as needed */ } ``` Repeat the above steps for mid slots, low slots, rig slots, and sub-system slots, making sure to place them within their respective degree ranges. Remember to remove any hard-coded values that are no longer relevant and replace them with calculated positions based on the center of the fitting simulator. The `top` and `left` values should be calculated such that the slots are placed at the correct angle and distance from the center. Finally, ensure that the `.slot-item` class has the correct scaling and rotation to appear upright and consistent in size regardless of the slot's rotation. This is a high-level overview, and the actual implementation will require careful calculation and testing to ensure the slots are positioned as desired.