-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmain.lua
More file actions
185 lines (155 loc) · 3.74 KB
/
main.lua
File metadata and controls
185 lines (155 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
local soluna = require "soluna"
local widget = require "core.widget"
widget.scripts(require "visual.ui")
local flow = require "core.flow"
local vdesktop = require "visual.desktop"
local initial = require "gameplay.initial"
local card = require "gameplay.card"
local map = require "gameplay.map"
local persist = require "gameplay.persist"
local language = require "core.language"
local localization = require "core.localization"
local config = require "core.rules".ui
local test = require "gameplay.test"
local loadsave = require "core.loadsave"
local track = require "gameplay.track"
local vbutton = require "visual.button"
local mouse = require "core.mouse"
local touch = require "core.touch"
local keyboard = require "core.keyboard"
local text = require "soluna.text"
local setting =require "core.setting"
local image = require "soluna.image"
local file = require "soluna.file"
local utf8 = utf8
local math = math
local io = io
local settings = soluna.settings()
global require, assert, print, ipairs, string, error
local args = ...
if soluna.version_api ~= settings.soluna then
error (string.format("Mismatch soluna api version (%s) != settings.soluna (%s)", soluna.version_api, settings.soluna))
end
text.init "asset/icons.dl"
language.init()
local app_setting = setting.load()
local LANG <const> = app_setting.language or language.get_default()
local callback = {}
language.switch(LANG)
soluna.set_window_title(localization.convert "app.title")
do
local c = file.load "asset/icon.png"
local data, w, h = image.load(c)
local mid_data, mid_w, mid_h = image.resize(data, w, h, 0.5)
local small_data, small_w, small_h = image.resize(data, w, h, 0.25)
soluna.set_icon {
{data = data, width = w, height = h},
{data = mid_data, width = mid_w, height = mid_h},
{data = small_data, width = small_w, height = small_h},
}
end
vdesktop.init {
batch = args.batch,
font_id = language.font_id(LANG),
sprites = soluna.load_sprites "asset/sprites.dl",
width = args.width,
height = args.height,
}
local game = {}
function game.init()
initial.new()
card.setup()
track.setup()
map.setup()
return flow.state.setup
end
function game.load()
local ok, phase = loadsave.load_game()
if ok then
return phase or "start"
else
return "init"
end
end
local states = {
"chooselang",
"startmenu",
"credits",
"exit",
"setup",
"start",
"action",
"payment",
"challenge",
"loss",
"power",
"advance",
"grow",
"settle",
"battle",
"expand",
"freepower",
"freeadvance",
"win",
"nextgame",
}
for _, action in ipairs(states) do
game[action] = require ("gameplay." .. action)
end
function game.idle()
return flow.state.idle
end
flow.load(game)
local function run_game()
if test.init() then
-- don't touch savefile when test
card.profile "TEST"
flow.enter(flow.state.init)
return
end
if app_setting.language == nil then
flow.enter(flow.state.chooselang)
else
flow.enter(flow.state.startmenu)
end
end
run_game()
callback.window_resize = vdesktop.flush
function callback.mouse_move(x, y)
mouse.mouse_move(x, y)
end
local mouse_btn = {
[0] = "left",
[1] = "right",
[2] = "mid",
}
function callback.mouse_button(btn, state)
btn = mouse_btn[btn]
state = state == 1
mouse.mouse_button(btn, state)
end
function callback.mouse_scroll(x, y)
mouse.scroll(x)
end
function callback.touch_begin(x, y)
touch.begin(x, y)
end
function callback.touch_end(x, y)
touch.ended(x, y)
end
function callback.touch_moved(x, y)
touch.moved(x, y)
end
function callback.frame(count)
local x, y = mouse.sync(count)
vdesktop.set_mouse(x, y)
flow.update()
touch.update(count)
-- todo : don't flush card here
vdesktop.card_count(card.count "draw", card.count "discard", card.seen())
map.update()
vdesktop.draw(count)
mouse.frame()
end
keyboard.setup(callback)
return callback