Skip to content

Commit 83411fa

Browse files
committed
Fixed map randomization and semantic versioning
1 parent 9e51c11 commit 83411fa

6 files changed

Lines changed: 24 additions & 25 deletions

File tree

LevelImposter/Builders/IElemBuilder.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace LevelImposter.Builders;
1010
public interface IElemBuilder
1111
{
1212
/// <summary>
13-
/// Parses and builds a GameObject based on <c>LIElement</c> data.
13+
/// First step in the build process, called before <see cref="OnBuild"/> for each element in the map.
1414
/// </summary>
1515
/// <param name="elem">Element to be parsed and built</param>
1616
/// <param name="obj">GameObject to append data and components to</param>
@@ -19,7 +19,7 @@ public void OnPreBuild(LIElement elem, GameObject obj)
1919
}
2020

2121
/// <summary>
22-
/// Parses and builds a GameObject based on <c>LIElement</c> data.
22+
/// Primary step in the build process, called for each element in the map.
2323
/// </summary>
2424
/// <param name="elem">Element to be parsed and built</param>
2525
/// <param name="obj">GameObject to append data and components to</param>
@@ -28,7 +28,7 @@ public void OnBuild(LIElement elem, GameObject obj)
2828
}
2929

3030
/// <summary>
31-
/// Final clean-up after an element has been built.
31+
/// Third step in the build process, called after <see cref="OnBuild"/> for each element in the map.
3232
/// </summary>
3333
/// <param name="elem">Element to be parsed and built</param>
3434
/// <param name="obj">GameObject to append data and components to</param>
@@ -38,6 +38,7 @@ public void OnPostBuild(LIElement elem, GameObject obj)
3838

3939
/// <summary>
4040
/// Final clean-up after all elements in a map have been built.
41+
/// Only called once per map build.
4142
/// </summary>
4243
public void OnCleanup()
4344
{
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/workspaces/LevelImposter/LevelImposter/bin/Debug/net6.0/LevelImposter.dll

LevelImposter/Core/Utils/Stores/FileStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public byte[] Peek(int count)
2626
{
2727
using var stream = OpenStream();
2828
var managedArray = new byte[count];
29-
stream.Read(managedArray, 0, (int)Math.Min(count, stream.Length));
29+
stream.Read(managedArray, 0, count);
3030
return managedArray;
3131
}
3232

LevelImposter/LevelImposter.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<PropertyGroup>
33
<Title>LevelImposter</Title>
44
<Version>0.21.3-dev2</Version>
5+
<SourceRevisionId></SourceRevisionId>
56
<Description>Custom Among Us Mapping Studio</Description>
67
<Authors>DigiWorm</Authors>
78

LevelImposter/Shop/Util/MapRandomizer.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,29 +74,34 @@ public static void RandomizeMap(bool setMapType = true)
7474
var fileIDs = new List<string>(MapFileAPI.ListIDs());
7575
var mapIDs = fileIDs.FindAll(id => !blacklistMaps.Contains(id));
7676
if (mapIDs.Count <= 0)
77-
return null; // <-- No valid maps found
77+
return null; // <-- No valid maps left
7878

7979
// Get map weights
8080
var mapWeights = new float[mapIDs.Count];
81-
float mapWeightSum = 0;
81+
var sumOfAllMapWeights = 0.0f;
8282
for (var i = 0; i < mapIDs.Count; i++)
8383
{
8484
var mapWeight = ConfigAPI.GetMapWeight(mapIDs[i]);
85-
mapWeights[i] = mapWeightSum + mapWeight;
86-
mapWeightSum += mapWeight;
85+
mapWeights[i] = sumOfAllMapWeights + mapWeight;
86+
sumOfAllMapWeights += mapWeight;
8787
}
8888

89+
// All maps are of zero weight
90+
if (sumOfAllMapWeights <= 0)
91+
return null;
92+
8993
// Choose a random map
90-
// TODO: FIX ME, this logic is flawed and does not properly account for weights
91-
var randomValue = Random.Range(0, mapWeightSum);
94+
var randomValue = Random.Range(0, sumOfAllMapWeights);
95+
var remainingWeight = sumOfAllMapWeights;
9296
for (var i = 0; i < mapIDs.Count; i++)
9397
{
9498
// Check weight
95-
var mapID = mapIDs[i];
96-
if (mapWeights[i] < randomValue)
99+
remainingWeight -= mapWeights[i];
100+
if (remainingWeight > 0)
97101
continue;
98102

99103
// Check if map is in workshop
104+
var mapID = mapIDs[i];
100105
var isInWorkshop = Guid.TryParse(mapID, out _);
101106
if (isInWorkshop)
102107
return mapID;

build.cake

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
11
var target = Argument("target", "Build");
22

33
var workflow = BuildSystem.GitHubActions.Environment.Workflow;
4-
var buildId = workflow.RunNumber;
5-
var tag = workflow.RefType == GitHubActionsRefType.Tag ? workflow.RefName.Substring(1) : null;
64

7-
Task("Build")
8-
.Does(() =>
5+
Task("Build").Does(() =>
96
{
107
var settings = new DotNetBuildSettings
118
{
129
Configuration = "Release",
1310
MSBuildSettings = new DotNetMSBuildSettings()
11+
{
12+
VersionSuffix = "ci." + workflow.RunNumber
13+
}
1414
};
1515

16-
if (tag != null)
17-
{
18-
settings.MSBuildSettings.Version = tag;
19-
}
20-
else if (buildId != 0)
21-
{
22-
settings.MSBuildSettings.VersionSuffix = "ci." + buildId;
23-
}
24-
2516
DotNetBuild(".", settings);
2617
});
2718

0 commit comments

Comments
 (0)