-
Notifications
You must be signed in to change notification settings - Fork 0
/
plain.lua
277 lines (249 loc) · 8.12 KB
/
plain.lua
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
SQRT = math.sqrt
PI = math.pi
SIN = math.sin
COS = math.cos
FLOOR = math.floor
ABS = math.abs
CEIL = math.ceil
RAND = math.random
RAD = math.rad
-- require'lfs'
JSON = require( "JSON" )
math.randomseed(os.time())
namegen = require("namegen")
debug = false
function logger(info,override)
-- Override will print regardless of global debug value
if(debug or override~=nil)then
print(info)
end
end
-- Requires ---------------------------
require("misclua.coronahelpers")
require("misclua.mathlib")
require("misclua.helpers")
require("misclua.military_unit_name")
require("misclua.coronahelpers")
class = require("misclua.30log-global")
require("classes.Empire")
require("classes.Planet")
require("classes.Star")
require("classes.Species")
require("classes.Ship")
require("classes.Galaxy")
require("classes.Galaxy2")
hull = require("classes.Convex_hull")
-- While we like OOP, there are
-- some things that should be loaded
-- and handled globally, like the table
-- for our different governments
government_file = loadjson("./misclua/government_types.json")
government_type = {}
government_description = {}
for k,v in pairs(government_file) do
table.insert(government_type,k)
table.insert(government_description,v[1])
end
--Spatial Definitions------------------------------------------
screenW = 500
screenH = 300
centerX = screenW/2
centerY = screenH/2
---------------------------------------------------------------------
local border = 20
local data= {
-- The width and height of the
-- galaxy in units. Pixels, light years,
-- hey it's up to you,
-- Number of empires
-- minimum distance from another empire
numberOfStars = 20,
width = screenW,
height = screenH,
numberOfEmpires = 3,
numberOfShips = 5,
numberOfSpecies = 3
}
-- local galaxy = Galaxy:new()
local galaxy = Galaxy:new(data)
local starModel = {}
local shipModel = {}
function CreateModelStars()
-- Run some tests on the galaxy object
-- starModel = galaxy:GetAllStarsBelongingToAEmpire(galaxy.empires[1])
starModel = galaxy.stars
-- Debug info if you wanna verify stuff!
-- for i=1,#starModel do
-- print("Star "..starModel[i].name.." belongs to the "..galaxy.empires[1].name)
-- end
end
function CreateModelShips()
-- Create ships and pass some data
-- print("How big is ships? "..#galaxy.ships)
for i=1,#galaxy.ships do
local shipData = {
name = "Ship "..i,
dockedAt = galaxy.stars[RAND(1,#galaxy.stars)],
empire = galaxy.empires[1],
speed = RAND(1,10),
heading = RAND(1,360)
}
local myShip = Ship:new(shipData)
myShip.x,myShip.y = myShip.dockedAt.x,myShip.dockedAt.y
table.insert(shipModel,myShip)
end
end
function MoveShips()
for i=1,#galaxy.ships do
galaxy.ships[i]:ChangeHeading(galaxy.ships[i].destination)
galaxy.ships[i]:MoveForward()
-- Sync the view with the newly
-- updated data model location
-- shipView[i].x,shipView[i].y = galaxy.ships[i].x,galaxy.ships[i].y
end
end
CreateModelStars()
CreateModelShips()
-- CreateSpeciesName()
function ScanForSerializables2(file)
local temp1 = SplitString(file,".lua")
local temp = SplitString(temp1[1],"\\")
local name = temp[#temp]
print("name "..name)
function file_check(file_name)
local file_found=io.open(file_name, "r")
local result = false
if file_found==nil then
result = false
else
result = true
end
return result
end
-- get all lines from a file, returns an empty
-- list/table if the file does not exist
function lines_from(file)
if not file_exists(file) then return {} end
lines = {}
for line in io.lines(file) do
lines[#lines + 1] = line
end
return lines
end
if(file_check(file))then
print("Exists "..tostring(file_check(file)))
print("File "..file)
print("MOyster")
-- Read variables/data/properties from file
local variables = {}
local methods = {}
-- tests the functions above
local file = '.\\classes\\Galaxy.lua'
local contents = lines_from(file)
-- print all line numbers and their contents
-- for k,v in pairs(contents) do
-- print('line[' .. k .. ']', v)
-- end
-- for line in (contents..'\n'):gmatch'(.-)\r?\n' do
for k,line in pairs(contents) do
-- print("POn")
if string.match(line, "Serialize this") then
local word1 = SplitString(line,"=")[1]
word1 = word1:gsub("%s+", "")
local word2 = SplitString(word1,"self.")[2]
-- print ("temp"..name.."."..word2.." = "..word1)
table.insert(variables,"{Ctrl {Enter}}{Delay 250}"..word2..":int{Delay 100}{Enter}")
-- print ("{Ctrl {Enter}}{Delay 250}"..word2..":int{Delay 100}{Enter}")
elseif string.match(line, "function "..name..":") then
-- print("Ok we found "..line)
local word1 = SplitString(line,":")[2]
-- print ("temp "..word1)
table.insert(methods,"{Ctrl {Shift {Enter}}}{Delay 250}"..word1..":int{Delay 100}{Enter}")
end
end
print("Variables\n------------------")
for i=1,#variables do
print(variables[i])
end
print("Methods\n------------------")
for i=1,#methods do
print(methods[i])
end
else
end
end
ScanForSerializables2(".\\classes\\Galaxy.lua")
function loadjson(filename)
local f = assert(io.open(filename, "rb"))
local content = f:read("*all")
f:close()
return JSON:decode(content)
end
local model = loadjson(".\\AG_modelmdj.mdj")
function print_r ( t )
local print_r_cache={}
local function sub_print_r(t,indent)
if (print_r_cache[tostring(t)]) then
print(indent.."*"..tostring(t))
else
print_r_cache[tostring(t)]=true
if (type(t)=="table") then
for pos,val in pairs(t) do
if (type(val)=="table") then
print(indent.."["..pos.."] => "..tostring(t).." {")
sub_print_r(val,indent..string.rep(" ",string.len(pos)+4))
print(indent..string.rep(" ",string.len(pos)+3).."}")
elseif (type(val)=="string") then
print(indent.."["..pos..'] => "'..val..'"')
else
print(indent.."["..pos.."] => "..tostring(val))
end
end
else
print(indent..tostring(t))
end
end
end
if (type(t)=="table") then
print(tostring(t).." {")
sub_print_r(t," ")
print("}")
else
sub_print_r(t," ")
end
print()
end
-- print_r(model)
print("Test "..model._type)
print("Name "..model.ownedElements[1].ownedElements[2].ownedElements[1].name)
-- Enumerate?
function EnumerateProperties(tempObject)
for i=1,#tempObject.attributes do
local name = tempObject.attributes[i].name
local _type = tempObject.attributes[i].type
print(name..":".._type)
end
print("---------------------------")
end
function EnumerateMethods(tempObject)
for i=1,#tempObject.operations do
print(tempObject.operations[i].name) --..":"..tempObject.operations[i].type)
end
print("---------------------------")
end
function EnumerateClasses()
for i=1,#model.ownedElements[1].ownedElements[2].ownedElements do
local tempObject = model.ownedElements[1].ownedElements[2].ownedElements[i]
print("\n\n---------------------------")
print("Class "..tempObject.name)
print("---------------------------")
EnumerateProperties(tempObject)
if(tempObject.operations~=nil)then
-- print("Size of operations "..#tempObject.operations)
EnumerateMethods(tempObject)
end
end
end
EnumerateClasses()
-- print("Prop "..model.ownedElements[1].ownedElements[2].ownedElements[1].attributes[2].name)
-- print("Type "..model.ownedElements[1].ownedElements[2].ownedElements[1].attributes[2].type)