AutoSkill C++ Raylib Province Class for Map Editor
Defines a C++ class 'Province' for managing map polygons (provinces) with file I/O, mouse interaction, and rendering using Raylib.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8/c-raylib-province-class-for-map-editor" ~/.claude/skills/ecnu-icalk-autoskill-c-raylib-province-class-for-map-editor && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8/c-raylib-province-class-for-map-editor/SKILL.mdsource content
C++ Raylib Province Class for Map Editor
Defines a C++ class 'Province' for managing map polygons (provinces) with file I/O, mouse interaction, and rendering using Raylib.
Prompt
Role & Objective
You are a C++ Raylib developer. Your task is to implement a
Province class for a map editor application that handles polygon creation, storage, rendering, and deletion.
Operational Rules & Constraints
-
Class Structure:
- Define a class named
.Province - Include a nested struct
with integer membersPoint
andx
.y - Maintain a member
for the province currently being drawn.std::vector<Point> points - Maintain a member
to store all loaded/saved provinces.std::vector<std::vector<Point>> provinces
- Define a class named
-
Function: drawProvince
- Arguments:
,Color fillColor
,float strokeThickness
(e.g., 0 for solid, 1 for dotted).int strokeType - Behavior:
- Load polygons from a file named
.provinces.txt - File Format: The first line is the province ID. The second line contains X coordinates separated by ';'. The third line contains Y coordinates separated by ';'.
- Iterate through loaded provinces and render them.
- Use a function like
(or standard Raylib drawing functions) to draw the polygon fill and stroke.DrawPolyEx - Implement polygon selection logic (e.g., point-in-polygon test) if required for interaction.
- Load polygons from a file named
- Arguments:
-
Function: drawPoints
- Behavior:
- Enter a loop that continues until the
is pressed.KEY_ENTER - Inside the loop, check for
.IsMouseButtonPressed(MOUSE_BUTTON_LEFT) - When clicked, add a new point to the
vector.points - Coordinate System: Points must be captured and stored in world coordinates (use
with the camera context), not screen coordinates.GetScreenToWorld2D - When
is pressed, move the currentKEY_ENTER
vector into thepoints
list and clearprovinces
.points
- Enter a loop that continues until the
- Behavior:
-
Function: deletePoints
- Behavior: Remove the last point from the
vector (e.g.,points
). This can be called repeatedly until all points are deleted.points.pop_back()
- Behavior: Remove the last point from the
-
Function: savePointsToFile
- Arguments:
.std::string filename - Trigger: Typically called via a keyboard event (e.g., Enter key).
- File Format: Write 3 lines for each province:
- X coordinates separated by ';'.
- Y coordinates separated by ';'.
- (Optional) Empty line or ID.
- Arguments:
-
Function: deleteProvince
- Arguments:
(world coordinates).Vector2 mousePoint - Behavior: Check if the
is inside the fill of a province. If so, remove that province from themousePoint
list, the display, and the file.provinces
- Arguments:
-
Rendering & Coordinates
- Ensure all drawing operations occur within
andBeginMode2D(camera)
.EndMode2D() - Ensure all point inputs are converted to world coordinates before storage or rendering.
- Use
or equivalent Raylib functions to handle polygon filling and stroking based on the provided arguments.DrawPolyEx
- Ensure all drawing operations occur within
Anti-Patterns
- Do not use screen coordinates for point storage or polygon rendering; strictly use world coordinates.
- Do not mix
types with RaylibProvince::Point
types without explicit conversion.Vector2 - Do not hardcode file paths (e.g.,
); use generic paths or arguments./home/danya/...
Triggers
- Write the Province class in C++ and raylib
- Create a Province class for map editor
- Implement polygon management in C++
- Raylib province drawing and file I/O