Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tales of MajEyal
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
yutio888
Tales of MajEyal
Commits
55822dd1
Commit
55822dd1
authored
15 years ago
by
dg
Browse files
Options
Downloads
Patches
Plain Diff
docs
git-svn-id:
http://svn.net-core.org/repos/t-engine4@48
51575b47-30f0-44d4-a5cc-537603b46e54
parent
1a0f3c04
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
game/engine/Savefile.lua
+16
-0
16 additions, 0 deletions
game/engine/Savefile.lua
game/engine/init.lua
+2
-2
2 additions, 2 deletions
game/engine/init.lua
with
18 additions
and
2 deletions
game/engine/Savefile.lua
+
16
−
0
View file @
55822dd1
require
"engine.class"
--- Savefile code
-- T-Engine4 savefiles are direct serialization of in game objects<br/>
-- Basically the engine is told to save your Game instance and then it will
-- recursively save all that it contains: level, map, entities, your own objects, ...<br/>
-- The savefile structure is a zip file that contains one file per object to be saved. Unzip one, it is quite obvious<br/>
-- A simple object (that does not do anything too fancy in its constructor) will save/load without anything
-- to code, it's magic!<br/>
-- For more complex objects, look at the methods save() and loaded() in objects that have them
module
(
...
,
package
.
seeall
,
class
.
make
)
_M
.
current_save
=
false
--- Init a savefile
-- @param savefile the name of the savefile, usually the player's name. It will be sanitized so dont bother doing it
function
_M
:
init
(
savefile
)
self
.
save_dir
=
"/save/"
..
savefile
:
gsub
(
"
[^
a-zA-Z0-9_-.
]
"
,
"_"
)
..
"/"
self
.
load_dir
=
"/tmp/loadsave/"
...
...
@@ -15,6 +25,8 @@ function _M:init(savefile)
_M
.
current_save
=
self
end
--- Finishes up a savefile
-- Always call it once done
function
_M
:
close
()
self
.
tables
=
nil
self
.
process
=
nil
...
...
@@ -54,6 +66,7 @@ function _M:saveObject(obj, zip)
return
self
.
tables
[
game
]
end
--- Save the given game
function
_M
:
saveGame
(
game
)
fs
.
mkdir
(
self
.
save_dir
)
...
...
@@ -62,6 +75,7 @@ function _M:saveGame(game)
zip
:
close
()
end
--- Save a level
function
_M
:
saveLevel
(
level
)
fs
.
mkdir
(
self
.
save_dir
)
...
...
@@ -86,6 +100,7 @@ function _M:loadReal(load)
return
o
end
--- Loads a game
function
_M
:
loadGame
()
local
path
=
fs
.
getRealPath
(
self
.
save_dir
..
"game.teag"
)
if
not
path
or
path
==
""
then
return
nil
,
"no savefile"
end
...
...
@@ -104,6 +119,7 @@ function _M:loadGame()
return
loadedGame
end
--- Loads a level
function
_M
:
loadLevel
(
zone
,
level
)
local
path
=
fs
.
getRealPath
(
self
.
save_dir
..
(
"level-%s-%d.teal"
):
format
(
zone
,
level
))
if
not
path
or
path
==
""
then
return
false
end
...
...
This diff is collapsed.
Click to expand it.
game/engine/init.lua
+
2
−
2
View file @
55822dd1
...
...
@@ -34,8 +34,8 @@ if mod_def then
core
.
display
.
setWindowTitle
(
mod
.
name
)
local
Game
=
require
(
mod
.
starter
)
game
=
Game
.
new
()
--[[
--
game = Game.new()
--
[[
local
save
=
engine
.
Savefile
.
new
(
"player"
)
game
=
save
:
loadGame
()
save
:
close
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment