diff options
| author | techchud <protrude_paying969@simplelogin.com> | 2025-08-17 19:54:13 -0500 | 
|---|---|---|
| committer | techchud <protrude_paying969@simplelogin.com> | 2025-08-17 19:54:13 -0500 | 
| commit | f472907d31e24602c8f850b6c319a3c016f24ea3 (patch) | |
| tree | d748d504b08e25a8cb24a18c488d4d2528db7b9d /src | |
| download | sneed-master.tar.gz sneed-master.tar.bz2 sneed-master.zip | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/sneed.nim | 105 | 
1 files changed, 105 insertions, 0 deletions
| diff --git a/src/sneed.nim b/src/sneed.nim new file mode 100644 index 0000000..094f4da --- /dev/null +++ b/src/sneed.nim @@ -0,0 +1,105 @@ +import os +import sequtils +import parsetoml +import tables + +type +    Plant = object +        icon: char +        seedspacing: int +        rowspacing: int +        rownum: int + + +let sneedconfig = parsetoml.parseFile(paramStr(1)) +let plotMaxSizeX = sneedconfig["X"].getInt() +let plotMaxSizeY = sneedconfig["Y"].getInt() +var plot = newSeqWith( plotMaxSizeX, newSeq[char](plotMaxSizeY)) + + + +var plants: seq[Plant] + +var soilicon: char +var gapicon: char +var gapsize: int +var farmableEdge: bool + +for key, val in sneedconfig["plants"].getTable.pairs(): +     if key == "soilicon": +         soilicon = sneedconfig["plants"]["soilicon"].getStr()[0] +     elif key == "gapicon": +         gapicon = sneedconfig["plants"]["gapicon"].getStr()[0] +     elif key == "gapsize": +         gapsize = sneedconfig["plants"]["gapsize"].getInt() +     elif key == "farmableEdge": +         farmableEdge = sneedconfig["plants"]["farmableEdge"].getBool() +     else: +         let rawPlant = sneedconfig["plants"][key] +         plants.add ( Plant( +             icon: rawPlant["icon"].getStr[0],  +             seedspacing: rawPlant["seedspacing"].getInt(),  +             rowspacing: rawPlant["rowspacing"].getInt(),  +             rownum: rawPlant["rownum"].getInt(1) +         ) ) + +var rowstart = 0 +var rowend: int +var gapstart: int +var gapend: int + +var seedSpaceCounter = 0 + +# If the edge is farmable, then the edge plants should have their row size reduced. +if farmableEdge: +    plants[0].rowspacing = toInt(plants[0].rowspacing/2) +    plants[plants.len()-1].rowspacing = toInt(plants[plants.len()-1].rowspacing/2) + +# Find the demarcation point of the the row's end point. +for plant in plants: +    rowend = (rowstart + plant.rowspacing) +     +# If the rowend go over the maximum, terminate the loop +    if rowend >= (plotMaxSizeY-1): +        echo "Warning: " & $plant & " has gone over the allowed farm size! It has been dropped from the farm!" +        break + +# fill the entire row with the soil icon, and the gap area with the gap icon +# put seeds in the center of the rows with seedspacing number of units of free space between the edge +     +    for x in rowstart..rowend: +        for y in 0..(plotMaxSizeY-1): +            plot[y][x] = soilicon +            seedSpaceCounter = seedSpaceCounter + 1 +            if x == (toInt(plant.rowspacing/2)+rowstart) and (seedSpaceCounter mod (plant.seedspacing+1)) == 0: +                plot[y][x] = plant.icon + + +# Find the start and end of the gap given the gap size and add it unless this is the final plant. +    gapstart = rowend + 1 +    gapend = gapstart + gapsize + +# If the gaps go over the maximum, terminate the loop +    if gapend >= (plotMaxSizeY-1): +        break +     +    if plant != plants[plants.len()-1]: +        for x in gapstart..gapend: +            for y in 0..(plotMaxSizeY-1): +                plot[y][x] = gapicon +    else: +        for x in gapstart..gapend: +            for y in 0..(plotMaxSizeY-1): +                plot[y][x] = '!' +        let extraGap = (plotMaxSizeY - gapstart) +        if extraGap > 0: +            echo "Warning! You have " & $(extraGap) & " Y units of unused space!" + +# Note the start of the next row (end of the previous row + gap size), reset the seed space counter, and then move onto the next plant. +    rowstart = gapend + 1 +    seedSpaceCounter = 0 + +for y in plot: +    for x in y: +        stdout.write x +    stdout.write "\n" | 
