Skip to content

Commit 2f1de59

Browse files
committed
Merge branch 'release/0.12.1.1218'
2 parents 00f50d7 + 755c5d7 commit 2f1de59

18 files changed

+399
-507
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Version 0.12.1.1218 - 2017-11-29
2+
3+
## Fixes
4+
- Fixed reload action taking non-ammunition items to fill magazines
5+
6+
7+
8+
19
# Version 0.12.0.1207 - 2017-11-24
210

311
## Additions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# On The Roadside
22

3-
[![Version](https://img.shields.io/badge/Version-0.12.0.1207-blue.svg)](https://github.com/rm-code/on-the-roadside/releases/latest)
3+
[![Version](https://img.shields.io/badge/Version-0.12.1.1218-blue.svg)](https://github.com/rm-code/on-the-roadside/releases/latest)
44
[![LOVE](https://img.shields.io/badge/L%C3%96VE-0.10.2-EA316E.svg)](http://love2d.org/)
55
[![Build Status](https://travis-ci.com/rm-code/On-The-Roadside.svg?token=q3rLXeyGTBN9VB2zsWMr&branch=develop)](https://travis-ci.com/rm-code/On-The-Roadside)
66

config.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ file = {
88
exclude = {
99
'lib',
1010
'res',
11-
'spc'
11+
'tests'
1212
}
1313
}
1414
dir = '../docs'

src/CombatState.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ function CombatState.new()
181181
return stateManager:getState()
182182
end
183183

184+
function self:getPlayerFaction()
185+
return factions:getPlayerFaction()
186+
end
187+
184188
function self:getCurrentCharacter()
185189
return factions:getFaction():getCurrentCharacter();
186190
end

src/SaveHandler.lua

Lines changed: 17 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1+
---
2+
-- @module SaveHandler
3+
--
4+
5+
-- ------------------------------------------------
6+
-- Required Modules
7+
-- ------------------------------------------------
8+
19
local Log = require( 'src.util.Log' );
10+
local Compressor = require( 'src.util.Compressor' )
211

312
-- ------------------------------------------------
413
-- Module
@@ -11,79 +20,20 @@ local SaveHandler = {};
1120
-- ------------------------------------------------
1221

1322
local SAVE_FOLDER = 'saves'
14-
local UNCOMPRESSED_SAVE = 'uncompressed.lua'
1523
local COMPRESSED_SAVE = 'compressed.data'
1624
local VERSION_FILE = 'version.data'
17-
local DEBUG = false
1825

1926
-- ------------------------------------------------
2027
-- Private Functions
2128
-- ------------------------------------------------
2229

2330
---
24-
-- Takes a table and recursively turns it into a human-readable and nicely
25-
-- formatted string stored as a sequence.
26-
-- @param value (mixed) The value to serialize.
27-
-- @param output (table) The table used for storing the lines of the final file.
28-
-- @param depth (number) An indicator for the depth of the recursion.
29-
--
30-
local function serialize( value, output, depth )
31-
-- Append whitespace for each depth layer.
32-
local ws = ' ';
33-
for _ = 1, depth do
34-
ws = ws .. ' ';
35-
end
36-
37-
if type( value ) == 'table' then
38-
for k, v in pairs(value) do
39-
if type( v ) == 'table' then
40-
table.insert( output, string.format( '%s[\'%s\'] = {', ws, tostring( k )));
41-
serialize( v, output, depth + 1 );
42-
table.insert( output, string.format( '%s},', ws ));
43-
elseif type( v ) == 'string' then
44-
table.insert( output, string.format( '%s[\'%s\'] = "%s",', ws, tostring( k ), tostring( v )));
45-
else
46-
table.insert( output, string.format( '%s[\'%s\'] = %s,', ws, tostring( k ), tostring( v )));
47-
end
48-
end
49-
else
50-
table.insert( output, string.format( '%s%s,', tostring( value )));
51-
end
52-
end
53-
54-
---
55-
-- Takes care of transforming strings to numbers if possible.
56-
-- @param value (mixed) The value to check.
57-
-- @return (mixed) The converted value.
31+
-- Creates a file containing only the version string.
32+
-- @string dir The directory to store the version file in.
33+
-- @table version A table containing the version field.
5834
--
59-
local function convertStrings( value )
60-
local keysToReplace = {};
61-
62-
for k, v in pairs( value ) do
63-
if tonumber( k ) then
64-
keysToReplace[#keysToReplace + 1] = k;
65-
end
66-
67-
if type( v ) == 'table' then
68-
convertStrings( v );
69-
elseif tonumber( v ) then
70-
value[k] = tonumber( v );
71-
end
72-
end
73-
74-
-- If the key can be transformed into a number delete the original
75-
-- key-value pair and store the value with the numerical key.
76-
for _, k in ipairs( keysToReplace ) do
77-
local v = value[k];
78-
value[k] = nil;
79-
value[tonumber(k)] = v;
80-
end
81-
82-
return value;
83-
end
84-
8535
local function createVersionFile( dir, version )
86-
love.filesystem.write( dir .. '/' .. VERSION_FILE, love.math.compress( version, 'lz4', 9 ))
36+
Compressor.save( version, dir .. '/' .. VERSION_FILE )
8737
end
8838

8939
-- ------------------------------------------------
@@ -102,38 +52,18 @@ function SaveHandler.save( t, name )
10252
local folder = SAVE_FOLDER .. '/' .. name
10353
love.filesystem.createDirectory( folder )
10454

105-
createVersionFile( folder, getVersion() )
106-
107-
-- Serialize the table.
108-
local output = {};
109-
table.insert( output, 'return {' );
110-
serialize( t, output, 0 )
111-
table.insert( output, '}' );
112-
113-
local str = table.concat( output, '\n' );
114-
local compress = love.math.compress( str, 'lz4', 9 );
115-
116-
-- Save uncompressed output for debug purposes only.
117-
if DEBUG then
118-
love.filesystem.write( folder .. '/' .. UNCOMPRESSED_SAVE, str )
119-
end
55+
createVersionFile( folder, { version = getVersion() })
12056

12157
-- Save compressed file.
122-
love.filesystem.write( folder .. '/' .. COMPRESSED_SAVE, compress )
58+
Compressor.save( t, folder .. '/' .. COMPRESSED_SAVE )
12359
end
12460

12561
function SaveHandler.load( path )
126-
local compressed, bytes = love.filesystem.read( path .. '/' .. COMPRESSED_SAVE )
127-
Log.print( string.format( 'Loaded savegame (Size: %d bytes)', bytes ), 'SaveHandler' );
128-
129-
local decompressed = love.math.decompress( compressed, 'lz4' );
130-
local rawsave = loadstring( decompressed )();
131-
return convertStrings( rawsave );
62+
return Compressor.load( path .. '/' .. COMPRESSED_SAVE )
13263
end
13364

13465
function SaveHandler.loadVersion( path )
135-
local compressed = love.filesystem.read( path .. '/' .. VERSION_FILE )
136-
return love.math.decompress( compressed, 'lz4' )
66+
return Compressor.load( path .. '/' .. VERSION_FILE ).version
13767
end
13868

13969
function SaveHandler.getSaveFolder()

src/characters/actions/Reload.lua

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ function Reload.new( character )
77
local self = Action.new( 5, character:getTile() ):addInstance( 'Reload' );
88

99
local function reload( weapon, inventory, item )
10-
weapon:getMagazine():addRound( item );
11-
inventory:removeItem( item );
10+
if item:instanceOf( 'Ammunition' ) and item:getCaliber() == weapon:getMagazine():getCaliber() then
11+
weapon:getMagazine():addRound( item )
12+
inventory:removeItem( item )
13+
end
1214
end
1315

1416
function self:perform()
@@ -26,15 +28,18 @@ function Reload.new( character )
2628

2729
local inventory = character:getInventory();
2830
for _, item in pairs( inventory:getItems() ) do
29-
if item:instanceOf( 'Ammunition' ) and item:getCaliber() == weapon:getMagazine():getCaliber() then
30-
reload( weapon, inventory, item );
31-
elseif item:instanceOf( 'ItemStack' ) then
31+
if item:instanceOf( 'ItemStack' ) then
3232
for _, sitem in pairs( item:getItems() ) do
33-
reload( weapon, inventory, sitem );
33+
reload( weapon, inventory, sitem )
3434
if weapon:getMagazine():isFull() then
35-
break;
35+
return true
3636
end
3737
end
38+
elseif item:instanceOf( 'Item' ) then
39+
reload( weapon, inventory, item )
40+
if weapon:getMagazine():isFull() then
41+
return true
42+
end
3843
end
3944
end
4045

src/characters/body/BodyFactory.lua

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,22 @@ end
119119
---
120120
-- Assembles a body from the different body parts and connections found in the
121121
-- body template.
122-
-- @param cid (string) The body id of the creature to create.
123-
-- @param layout (table) A table containing the nodes and edges of the body graph.
124-
-- @return (Body) A shiny new Body.
122+
-- @tparam string creatureID The body id of the creature to create.
123+
-- @tparam table template A table containing the definitions for this creature's body parts.
124+
-- @tparam table layout A table containing the nodes and edges of the body layout's graph.
125+
-- @treturn Body A shiny new Body.
125126
--
126-
local function assembleBody( cid, layout )
127-
local body = Body.new( templates[cid] );
127+
local function assembleBody( creatureID, template, layout )
128+
local body = Body.new( template )
128129
local equipment = Equipment.new();
129-
local inventory = Inventory.new( templates[cid].defaultCarryWeight, templates[cid].defaultCarryVolume );
130+
local inventory = Inventory.new( template.defaultCarryWeight, template.defaultCarryVolume )
130131

131132
equipment:observe( inventory );
132133

133134
-- The index is the number used inside of the graph whereas the id determines
134135
-- which type of object to create for this node.
135136
for index, id in ipairs( layout.nodes ) do
136-
createBodyPart( cid, body, equipment, index, id );
137+
createBodyPart( creatureID, body, equipment, index, id )
137138
end
138139

139140
-- Connect the bodyparts.
@@ -168,9 +169,12 @@ end
168169
-- @return (Body) The newly created Body.
169170
--
170171
function BodyFactory.create( id )
171-
local template = layouts[id];
172-
assert( template, string.format( 'Requested body template (%s) doesn\'t exist!', id ));
173-
return assembleBody( id, template );
172+
local layout, template = layouts[id], templates[id]
173+
174+
assert( layout, string.format( 'Requested body layout (%s) doesn\'t exist!', id ))
175+
assert( template, string.format( 'Requested body template (%s) doesn\'t exist!', id ))
176+
177+
return assembleBody( id, template, layout )
174178
end
175179

176180
function BodyFactory.load( savedbody )

0 commit comments

Comments
 (0)