Skip to content

Commit

Permalink
Merge branch 'release/0.12.1.1218'
Browse files Browse the repository at this point in the history
  • Loading branch information
rm-code committed Nov 29, 2017
2 parents 00f50d7 + 755c5d7 commit 2f1de59
Show file tree
Hide file tree
Showing 18 changed files with 399 additions and 507 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Version 0.12.1.1218 - 2017-11-29

## Fixes
- Fixed reload action taking non-ammunition items to fill magazines




# Version 0.12.0.1207 - 2017-11-24

## Additions
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# On The Roadside

[![Version](https://img.shields.io/badge/Version-0.12.0.1207-blue.svg)](https://github.com/rm-code/on-the-roadside/releases/latest)
[![Version](https://img.shields.io/badge/Version-0.12.1.1218-blue.svg)](https://github.com/rm-code/on-the-roadside/releases/latest)
[![LOVE](https://img.shields.io/badge/L%C3%96VE-0.10.2-EA316E.svg)](http://love2d.org/)
[![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)

Expand Down
2 changes: 1 addition & 1 deletion config.ld
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ file = {
exclude = {
'lib',
'res',
'spc'
'tests'
}
}
dir = '../docs'
Expand Down
4 changes: 4 additions & 0 deletions src/CombatState.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ function CombatState.new()
return stateManager:getState()
end

function self:getPlayerFaction()
return factions:getPlayerFaction()
end

function self:getCurrentCharacter()
return factions:getFaction():getCurrentCharacter();
end
Expand Down
104 changes: 17 additions & 87 deletions src/SaveHandler.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
---
-- @module SaveHandler
--

-- ------------------------------------------------
-- Required Modules
-- ------------------------------------------------

local Log = require( 'src.util.Log' );
local Compressor = require( 'src.util.Compressor' )

-- ------------------------------------------------
-- Module
Expand All @@ -11,79 +20,20 @@ local SaveHandler = {};
-- ------------------------------------------------

local SAVE_FOLDER = 'saves'
local UNCOMPRESSED_SAVE = 'uncompressed.lua'
local COMPRESSED_SAVE = 'compressed.data'
local VERSION_FILE = 'version.data'
local DEBUG = false

-- ------------------------------------------------
-- Private Functions
-- ------------------------------------------------

---
-- Takes a table and recursively turns it into a human-readable and nicely
-- formatted string stored as a sequence.
-- @param value (mixed) The value to serialize.
-- @param output (table) The table used for storing the lines of the final file.
-- @param depth (number) An indicator for the depth of the recursion.
--
local function serialize( value, output, depth )
-- Append whitespace for each depth layer.
local ws = ' ';
for _ = 1, depth do
ws = ws .. ' ';
end

if type( value ) == 'table' then
for k, v in pairs(value) do
if type( v ) == 'table' then
table.insert( output, string.format( '%s[\'%s\'] = {', ws, tostring( k )));
serialize( v, output, depth + 1 );
table.insert( output, string.format( '%s},', ws ));
elseif type( v ) == 'string' then
table.insert( output, string.format( '%s[\'%s\'] = "%s",', ws, tostring( k ), tostring( v )));
else
table.insert( output, string.format( '%s[\'%s\'] = %s,', ws, tostring( k ), tostring( v )));
end
end
else
table.insert( output, string.format( '%s%s,', tostring( value )));
end
end

---
-- Takes care of transforming strings to numbers if possible.
-- @param value (mixed) The value to check.
-- @return (mixed) The converted value.
-- Creates a file containing only the version string.
-- @string dir The directory to store the version file in.
-- @table version A table containing the version field.
--
local function convertStrings( value )
local keysToReplace = {};

for k, v in pairs( value ) do
if tonumber( k ) then
keysToReplace[#keysToReplace + 1] = k;
end

if type( v ) == 'table' then
convertStrings( v );
elseif tonumber( v ) then
value[k] = tonumber( v );
end
end

-- If the key can be transformed into a number delete the original
-- key-value pair and store the value with the numerical key.
for _, k in ipairs( keysToReplace ) do
local v = value[k];
value[k] = nil;
value[tonumber(k)] = v;
end

return value;
end

local function createVersionFile( dir, version )
love.filesystem.write( dir .. '/' .. VERSION_FILE, love.math.compress( version, 'lz4', 9 ))
Compressor.save( version, dir .. '/' .. VERSION_FILE )
end

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

createVersionFile( folder, getVersion() )

-- Serialize the table.
local output = {};
table.insert( output, 'return {' );
serialize( t, output, 0 )
table.insert( output, '}' );

local str = table.concat( output, '\n' );
local compress = love.math.compress( str, 'lz4', 9 );

-- Save uncompressed output for debug purposes only.
if DEBUG then
love.filesystem.write( folder .. '/' .. UNCOMPRESSED_SAVE, str )
end
createVersionFile( folder, { version = getVersion() })

-- Save compressed file.
love.filesystem.write( folder .. '/' .. COMPRESSED_SAVE, compress )
Compressor.save( t, folder .. '/' .. COMPRESSED_SAVE )
end

function SaveHandler.load( path )
local compressed, bytes = love.filesystem.read( path .. '/' .. COMPRESSED_SAVE )
Log.print( string.format( 'Loaded savegame (Size: %d bytes)', bytes ), 'SaveHandler' );

local decompressed = love.math.decompress( compressed, 'lz4' );
local rawsave = loadstring( decompressed )();
return convertStrings( rawsave );
return Compressor.load( path .. '/' .. COMPRESSED_SAVE )
end

function SaveHandler.loadVersion( path )
local compressed = love.filesystem.read( path .. '/' .. VERSION_FILE )
return love.math.decompress( compressed, 'lz4' )
return Compressor.load( path .. '/' .. VERSION_FILE ).version
end

function SaveHandler.getSaveFolder()
Expand Down
19 changes: 12 additions & 7 deletions src/characters/actions/Reload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ function Reload.new( character )
local self = Action.new( 5, character:getTile() ):addInstance( 'Reload' );

local function reload( weapon, inventory, item )
weapon:getMagazine():addRound( item );
inventory:removeItem( item );
if item:instanceOf( 'Ammunition' ) and item:getCaliber() == weapon:getMagazine():getCaliber() then
weapon:getMagazine():addRound( item )
inventory:removeItem( item )
end
end

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

local inventory = character:getInventory();
for _, item in pairs( inventory:getItems() ) do
if item:instanceOf( 'Ammunition' ) and item:getCaliber() == weapon:getMagazine():getCaliber() then
reload( weapon, inventory, item );
elseif item:instanceOf( 'ItemStack' ) then
if item:instanceOf( 'ItemStack' ) then
for _, sitem in pairs( item:getItems() ) do
reload( weapon, inventory, sitem );
reload( weapon, inventory, sitem )
if weapon:getMagazine():isFull() then
break;
return true
end
end
elseif item:instanceOf( 'Item' ) then
reload( weapon, inventory, item )
if weapon:getMagazine():isFull() then
return true
end
end
end

Expand Down
24 changes: 14 additions & 10 deletions src/characters/body/BodyFactory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,22 @@ end
---
-- Assembles a body from the different body parts and connections found in the
-- body template.
-- @param cid (string) The body id of the creature to create.
-- @param layout (table) A table containing the nodes and edges of the body graph.
-- @return (Body) A shiny new Body.
-- @tparam string creatureID The body id of the creature to create.
-- @tparam table template A table containing the definitions for this creature's body parts.
-- @tparam table layout A table containing the nodes and edges of the body layout's graph.
-- @treturn Body A shiny new Body.
--
local function assembleBody( cid, layout )
local body = Body.new( templates[cid] );
local function assembleBody( creatureID, template, layout )
local body = Body.new( template )
local equipment = Equipment.new();
local inventory = Inventory.new( templates[cid].defaultCarryWeight, templates[cid].defaultCarryVolume );
local inventory = Inventory.new( template.defaultCarryWeight, template.defaultCarryVolume )

equipment:observe( inventory );

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

-- Connect the bodyparts.
Expand Down Expand Up @@ -168,9 +169,12 @@ end
-- @return (Body) The newly created Body.
--
function BodyFactory.create( id )
local template = layouts[id];
assert( template, string.format( 'Requested body template (%s) doesn\'t exist!', id ));
return assembleBody( id, template );
local layout, template = layouts[id], templates[id]

assert( layout, string.format( 'Requested body layout (%s) doesn\'t exist!', id ))
assert( template, string.format( 'Requested body template (%s) doesn\'t exist!', id ))

return assembleBody( id, template, layout )
end

function BodyFactory.load( savedbody )
Expand Down
Loading

0 comments on commit 2f1de59

Please sign in to comment.