Feature Complete Shipping V1.0
This commit is contained in:
@@ -48,6 +48,39 @@ package.loaded["PaintMyKI5/PaintMyKI5VehiclePaintData"] = true
|
||||
|
||||
require "PaintMyKI5/PaintRequirements"
|
||||
require "PaintMyKI5/PaintInventory"
|
||||
require "PaintMyKI5/TextureName"
|
||||
|
||||
test("texture labels use the unique suffix of a shared filename prefix", function()
|
||||
local labels = PaintMyKI5.TextureName.buildLabels({
|
||||
{ texture = "Vehicles/Vehicles_93mustangGT_Shell_Green" },
|
||||
{ texture = "Vehicles/Vehicles_93mustangGT_Shell_Seafoam" },
|
||||
{ texture = "Vehicles/Vehicles_93mustangGT_Shell_SSP" },
|
||||
})
|
||||
assert(labels[1] == "Green")
|
||||
assert(labels[2] == "Seafoam")
|
||||
assert(labels[3] == "SSP")
|
||||
end)
|
||||
|
||||
test("texture labels keep filenames when there is no useful shared prefix", function()
|
||||
local labels = PaintMyKI5.TextureName.buildLabels({
|
||||
{ texture = "Vehicles/Ford_Green.png" },
|
||||
{ texture = "Vehicles/Chevrolet_Red.png" },
|
||||
})
|
||||
assert(labels[1] == "Ford_Green")
|
||||
assert(labels[2] == "Chevrolet_Red")
|
||||
|
||||
local single = PaintMyKI5.TextureName.buildLabels({
|
||||
{ texture = "Vehicles/Only_Skin" },
|
||||
})
|
||||
assert(single[1] == "Only_Skin")
|
||||
|
||||
local duplicates = PaintMyKI5.TextureName.buildLabels({
|
||||
{ texture = "Vehicles/Repeated_Green" },
|
||||
{ texture = "Vehicles/Repeated_Green" },
|
||||
})
|
||||
assert(duplicates[1] == "Repeated_Green")
|
||||
assert(duplicates[2] == "Repeated_Green")
|
||||
end)
|
||||
|
||||
local function fakeVehicle()
|
||||
return {
|
||||
@@ -78,6 +111,17 @@ test("invalid skin is rejected", function()
|
||||
assert(PaintMyKI5.PaintRequirements.getRequirements(fakeVehicle(), 1) == nil)
|
||||
end)
|
||||
|
||||
test("a paint selection is valid before the player reaches the vehicle area", function()
|
||||
local vehicle = fakeVehicle()
|
||||
vehicle.isInArea = function() return false end
|
||||
local character = { getVehicle = function() return nil end }
|
||||
|
||||
assert(PaintMyKI5.PaintRequirements.isValidSelection(character, vehicle, 2))
|
||||
assert(not PaintMyKI5.PaintRequirements.isValidTarget(
|
||||
character, vehicle, 2, "Engine"
|
||||
))
|
||||
end)
|
||||
|
||||
local syncCount = 0
|
||||
local removedCount = 0
|
||||
local addedCount = 0
|
||||
@@ -146,6 +190,35 @@ test("a missing color prevents every mutation", function()
|
||||
assertNear(green.delta, 1.0)
|
||||
end)
|
||||
|
||||
test("painting readiness requires reusable sandpaper and a paintbrush", function()
|
||||
local green = fakeItem("Base.PaintGreen", 1.0)
|
||||
local sandpaper = { marker = "sandpaper" }
|
||||
local craftedBrush = { marker = "crafted brush" }
|
||||
local byType = {
|
||||
["Base.PaintGreen"] = javaList({ green }),
|
||||
}
|
||||
local inventory = {
|
||||
getAllTypeRecurse = function(_, itemType)
|
||||
return byType[itemType] or javaList({})
|
||||
end,
|
||||
}
|
||||
local character = { getInventory = function() return inventory end }
|
||||
local requirements = { { item = "Base.PaintGreen", uses = 1 } }
|
||||
|
||||
local ready, missingPaint, missingTools =
|
||||
PaintMyKI5.PaintInventory.checkPaintingRequirements(character, requirements)
|
||||
assert(not ready and #missingPaint == 0 and #missingTools == 2)
|
||||
assert(missingTools[1].item == "PaintMyKI5.Sandpaper")
|
||||
assert(missingTools[2].item == "Base.Paintbrush")
|
||||
|
||||
byType["PaintMyKI5.Sandpaper"] = javaList({ sandpaper })
|
||||
byType["Base.PaintbrushCrafted"] = javaList({ craftedBrush })
|
||||
ready, missingPaint, missingTools =
|
||||
PaintMyKI5.PaintInventory.checkPaintingRequirements(character, requirements)
|
||||
assert(ready and #missingPaint == 0 and #missingTools == 0)
|
||||
assert(sandpaper.marker == "sandpaper" and craftedBrush.marker == "crafted brush")
|
||||
end)
|
||||
|
||||
test("replacement failure rolls back earlier paint", function()
|
||||
local green = fakeItem("Base.PaintGreen", 1.0)
|
||||
local white = fakeItem("Base.PaintWhite", 0.1, true)
|
||||
@@ -184,6 +257,7 @@ isClient = function() return false end
|
||||
isServer = function() return true end
|
||||
dofile(luaRoot .. "/shared/PaintMyKI5/TimedActions/ISPaintMyKI5Vehicle.lua")
|
||||
PaintMyKI5.PaintInventory.checkRequirements = function() return true end
|
||||
PaintMyKI5.PaintInventory.checkPaintingRequirements = function() return true end
|
||||
|
||||
local function serverCharacter()
|
||||
return {
|
||||
@@ -204,6 +278,23 @@ local function mutableVehicle()
|
||||
return vehicle
|
||||
end
|
||||
|
||||
test("server completion rejects missing tools before changing skin or paint", function()
|
||||
local vehicle = mutableVehicle()
|
||||
local consumed = 0
|
||||
PaintMyKI5.PaintInventory.checkPaintingRequirements = function()
|
||||
return false, {}, { { item = "PaintMyKI5.Sandpaper" } }
|
||||
end
|
||||
PaintMyKI5.PaintInventory.consumeRequirements = function()
|
||||
consumed = consumed + 1
|
||||
return true
|
||||
end
|
||||
local action = ISPaintMyKI5Vehicle:new(serverCharacter(), vehicle, 2, "Engine")
|
||||
action:serverStart()
|
||||
assert(not action:complete())
|
||||
assert(vehicle.skin == 0 and vehicle.transmitted == 0 and consumed == 0)
|
||||
PaintMyKI5.PaintInventory.checkPaintingRequirements = function() return true end
|
||||
end)
|
||||
|
||||
test("server completion consumes then transmits the selected skin", function()
|
||||
local vehicle = mutableVehicle()
|
||||
local character = serverCharacter()
|
||||
@@ -288,4 +379,74 @@ test("client completion never mutates inventory or the vehicle", function()
|
||||
isClient = function() return false end
|
||||
end)
|
||||
|
||||
test("sandpaper is rare wherever full paint cans spawn", function()
|
||||
ProceduralDistributions = {
|
||||
list = {
|
||||
PaintShelf = { items = { "PaintBlack", 10, "Paintbrush", 10 } },
|
||||
PaintJunk = {
|
||||
items = { "Hammer", 1 },
|
||||
junk = { items = { "Base.PaintGreen", 0.4 } },
|
||||
},
|
||||
EmptyBuckets = { items = { "PaintbucketEmpty", 10, "Paintbrush", 10 } },
|
||||
OtherModPaint = { items = { "OtherMod.PaintGreen", 10 } },
|
||||
AlreadyAdded = {
|
||||
items = { "PaintWhite", 1, "PaintMyKI5.Sandpaper", 0.1 },
|
||||
},
|
||||
},
|
||||
}
|
||||
ClutterTables = {
|
||||
ClosetItems = { "PaintPurple", 0.1, "Pillow", 1 },
|
||||
}
|
||||
|
||||
dofile(luaRoot .. "/server/Items/PaintMyKI5_SandpaperDistribution.lua")
|
||||
|
||||
local function countItem(items, itemType)
|
||||
local count = 0
|
||||
local weight = nil
|
||||
for index = 1, #items, 2 do
|
||||
if items[index] == itemType then
|
||||
count = count + 1
|
||||
weight = items[index + 1]
|
||||
end
|
||||
end
|
||||
return count, weight
|
||||
end
|
||||
|
||||
local shelfCount, shelfWeight = countItem(
|
||||
ProceduralDistributions.list.PaintShelf.items,
|
||||
"PaintMyKI5.Sandpaper"
|
||||
)
|
||||
assert(shelfCount == 1 and shelfWeight == 0.1)
|
||||
|
||||
local junkCount, junkWeight = countItem(
|
||||
ProceduralDistributions.list.PaintJunk.junk.items,
|
||||
"PaintMyKI5.Sandpaper"
|
||||
)
|
||||
assert(junkCount == 1 and junkWeight == 0.1)
|
||||
|
||||
local emptyCount = countItem(
|
||||
ProceduralDistributions.list.EmptyBuckets.items,
|
||||
"PaintMyKI5.Sandpaper"
|
||||
)
|
||||
assert(emptyCount == 0)
|
||||
|
||||
local otherModCount = countItem(
|
||||
ProceduralDistributions.list.OtherModPaint.items,
|
||||
"PaintMyKI5.Sandpaper"
|
||||
)
|
||||
assert(otherModCount == 0)
|
||||
|
||||
local existingCount = countItem(
|
||||
ProceduralDistributions.list.AlreadyAdded.items,
|
||||
"PaintMyKI5.Sandpaper"
|
||||
)
|
||||
assert(existingCount == 1)
|
||||
|
||||
local clutterCount, clutterWeight = countItem(
|
||||
ClutterTables.ClosetItems,
|
||||
"PaintMyKI5.Sandpaper"
|
||||
)
|
||||
assert(clutterCount == 1 and clutterWeight == 0.1)
|
||||
end)
|
||||
|
||||
print("Lua tests passed: " .. passed)
|
||||
|
||||
Reference in New Issue
Block a user